Skip to main content
Known Participant
April 17, 2013
Answered

How reset the rotation of a PageItem (or access it's matrix at least) ?

  • April 17, 2013
  • 1 reply
  • 4226 views

I'd like to apply rotation to a few PageItem instances, but would like to reset the rotation first so it doesn't accumulate when I run the same script multiple times. I'm having a hard time trying to figure out how to restet the transformation matrix.

I've spotted this post which is close to what I need but it's a bit old now.

It looks like there isn't a matrix property anymore.

This:

alert(app.activeDocument.selection[0].matrix);

ouputs undefined

I've tried

app.activeDocument.selection[0].transform(app.getIdentityMatrix());

but it seems transformations are accumulated, multiplied, not reset.

If I want to reset the rotation of a PageItem, how would I go about doing that ?

Thanks,

George

This topic has been closed for replies.
Correct answer CarlosCanto

Hi Carlos,

That sounds like all that I need to do:

If I can add a tag, I can simply create one, add the rotation and on a different run of the script, remove it.

I've tried to instantiate a Tag like so: var t = new Tag()

but I get an error:

Tag does not have a constructor

I've tried to find out more about the Tag object but I got this:

function Tag() {

    [native code]

}

And in the Object Model Viewer I can only see these memebers:

name,parent,remove(),removeAll(),typename,value

If you can let me know how I can add a tag and add the ammount of rotation by script that would be awesome !

Thanks again,

George


check the Scripting Reference, it has a couple of samples, this is one of them

Using tags

// Finds the tags associated with the selected art item,

// show names and values in a separate document

if ( app.documents.length > 0 ) {

doc = app.activeDocument;

if ( doc.selection.length > 0 ) {

for ( i = 0; i < selection.length; i++ ) {

selectedArt = selection[0];

tagList = selectedArt.tags;

if (tagList.length == 0) {

var tempTag = tagList.add();

tempTag.name = "OneWord";

tempTag.value = "anything you want";

}

// Create a document and add a line of text per tag

reportDocument = app.documents.add();

top_offset = 400;

for ( i = 0; i < tagList.length; i++ ) {

tagText = tagList.value;

newItem = reportDocument.textFrames.add();

newItem.contents = "Tag: (" + tagList.name +

" , " + tagText + ")";

newItem.position = Array(100, top_offset);

newItem.textRange.size = 24;

top_offset = top_offset - 20;

}

}

}

}

1 reply

CarlosCanto
Community Expert
Community Expert
April 17, 2013

not all objects have a Matrix property, only TextFrames and PlacedItems if remember correctly.

why don't you use

app.activeDocument.selection[0].rotate(angle);

orgicusAuthor
Known Participant
April 17, 2013

Thanks Carlos, but if I do

app.activeDocument.selection[0].rotate(0);

the expected behaviour is the object's rotation's reset to 0

but that doesn't happen, rotation doesn't change since rotate

seems to perform relative not absolute rotations

So for example, if I call rotate(90) two times I get the selected objected rotated at 180 degrees

Any other ways to reset the rotation ? Or at least extract the current rotation ?

CarlosCanto
Community Expert
Community Expert
April 17, 2013

ok, chech this thread and see if it helps, my workaround on post # 5, but read it all, good info there.

http://forums.adobe.com/message/4478643#4478643