Skip to main content
j.khakase
Inspiring
August 11, 2022
Answered

Looking Script to rotate objects

  • August 11, 2022
  • 3 replies
  • 2175 views

Hello Friends,

 

I am looking an illustrator script, which will rotate the selected objects. by its current rotate angle * 0

 

is this possible ?

This topic has been closed for replies.
Correct answer Kurt Gold

Also see:

 

https://community.adobe.com/t5/illustrator-discussions/rotation/m-p/12443669

 

Apart from that, there is a very good script called Circular, provided by Alexander Ladygin. It has an option to reset rotations.

 

https://github.com/alexander-ladygin/illustrator-scripts

 

3 replies

Kurt Gold
Community Expert
Kurt GoldCommunity ExpertCorrect answer
Community Expert
August 12, 2022

Also see:

 

https://community.adobe.com/t5/illustrator-discussions/rotation/m-p/12443669

 

Apart from that, there is a very good script called Circular, provided by Alexander Ladygin. It has an option to reset rotations.

 

https://github.com/alexander-ladygin/illustrator-scripts

 

j.khakase
j.khakaseAuthor
Inspiring
August 18, 2022

I am really very thankful to all, who replies on my query. and my problem is solved now 🙂

CarlosCanto
Community Expert
Community Expert
August 11, 2022

but rotating by 0 or rotating by angle*0 would not apply any rotation, right?

Disposition_Dev
Legend
August 11, 2022

that is my understanding. doesn't matter what the current rotation is.. if you multiply it by zero, no rotation will occur. 

Disposition_Dev
Legend
August 11, 2022

var selection = app.activeDocument.selection;

for(var s=0;s<selection.length;s++)

{

    selection[0].rotate(0);

}

j.khakase
j.khakaseAuthor
Inspiring
August 12, 2022

Thank you for your reply. I test the code but it doesn't work in my case. I am attaching the screenshot the problem I am facing and the solution is expecting.

Please Refer the attached screenshot.

Sergey Osokin
Inspiring
August 12, 2022

I have a script in the archive, unfortunately I do not know its author 🙂

 

doc = app.activeDocument;
sel = doc.selection;

first = 1;
ang = 0;
for (i = 0; i < sel.length; i++) {
  if (sel[i].typename == "GroupItem" || sel[i].typename == "PathItem" || sel[i].typename == "CompoundPathItem") {
    currGroup = sel[i];

    getFP = FindFirstPath(currGroup);
    currpath = getFP[1];

    if (getFP[0] == 1) {
      p1 = currpath.pathPoints[0].anchor;
      p2 = currpath.pathPoints[1].anchor;

      deltax = p1[0] - p2[0];
      deltay = p1[1] - p2[1];

      currang = Math.atan(deltay / deltax);
      if (deltax < 0)
        currang += Math.PI;

      if (first) {
        first = 0;

        ang = currang;
      } else {
        currGroup.rotate((ang - currang) * 180 / Math.PI);
      }
    }
  }
}

function FindFirstPath(workGroup) {
  if (workGroup.typename == "PathItem")
    return [1, workGroup];

  if (workGroup.typename == "CompoundPathItem")
    return [1, workGroup.pathItems[0]];

  nSubPathes = workGroup.pathItems.length;
  if (nSubPathes > 0)
    return [1, workGroup.pathItems[0]];

  nSubPathes = workGroup.compoundPathItems.length;
  if (nSubPathes > 0)
    return [1, workGroup.compoundPathItems[0].pathItems[0]];

  nSubGroups = workGroup.groupItems.length;
  if (nSubGroups == 0)
    return [0, 0];
  var currRet = [0, 0];
  for (iGroup = 0; iGroup < nSubGroups; iGroup++) {
    currRet = FindFirstPath(workGroup.groupItems[iGroup]);
    if (currRet[0] == 1)
      break;
  }
  return currRet;
}