• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
7

Strange behaviour when trying to rotate around (0,0) point ??

Community Expert ,
Sep 21, 2023 Sep 21, 2023

Copy link to clipboard

Copied

(0,0) is set in TOP LEFT corner of the page...

 

https://youtu.be/9XABq_EgBOo

 

It's not shown on the Video - but it's like rotation point is in the middle of the Left edge of the first page ?? But it's still dancing ??

 

What is even worse - objects on the 2nd spread - behave like (0,0) point is still on the 1st Page / Spread ??

 

This is part to set TransformReferencePoint:

myInDi.ActiveDocument.LayoutWindows.Item(1).TransformReferencePoint = Array(0, 0)

And this is to rotate:

myInDi.ActiveDocument.Selection.Item(a).RotationAngle = myInDi.ActiveDocument.Selection.Item(a).RotationAngle + myLAngle

 

It's in a loop so when only one item is selected - a=1.

 

Doesn't matter what RulerOrigin I set, doesn't matter if I manually move (0,0) point in the InDesign - when I'm trying to rotate object via scripting - it's like (0,0) point is in the middle of the left edge of the first page???

 

If I try to rotate by Object's reference point - it's perfectly fine.

 

What am I doing wrong? Or it's fine in JavaScript?

 

Uploaded by ID-Tasker on 2023-09-21.
TOPICS
Bug , Scripting

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Sep 22, 2023 Sep 22, 2023

Hi Robert,

 

Not using transform and matrices explicitly does not mean that coordinate spaces are not involved behind the scenes. In fact, they always are, since InDesign works that way. The critical part of your code is the transformReferencePoint assignment, which explicitly refers to the origin of the pasteboard coordinate space. And this determines the center point of the rotation. Maybe a picture will make it clear:

 

2023-09-22-13-23-23.gif

 

Code:

var doc = app.properties.activeDocument;
doc.layoutWindows[0].transfor
...

Votes

Translate

Translate
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

Sorry. Was logged in with the wrong Adobe ID. My reply is the same:

 

@Robert Tkaczyk said: "…I did - and it behaved like the (0,0) was still on the 1st page..."

 

I expected that.

You can think of this as the zero point of the document.

Nothing really new. And no bug.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

But (0,0) point is for each page / spread?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

Hi @Robert at ID-Tasker ,

read into Marc's Coordinate Spaces & Transformations in InDesign CS4 – CC | Oct. 2021 (3.2) :

https://indiscripts.com/blog/public/data/coordinate-spaces-and-transformations-5/CoordinateSpacesTra...

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

@Laubender

 

Yes, this PDF has been mentioned here few times already. 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

My link points to a particular page…

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

On my phone it opens on the 1st page? 

 

Checked page 26 - but the problem is - I'm not using Transform and Matrices - I'm just changing RotationAngle directly after setting ReferencePoint to (0,0).

 

So the bug is there, when doing it the "old" or rather simple way.

 

I'll have to add few extra Rules to my tool to let user to set up Matrices and the rest and try again later today. 

 

Once again - big thanks to @Marc Autret for the PDF.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

Hi Robert,

 

Not using transform and matrices explicitly does not mean that coordinate spaces are not involved behind the scenes. In fact, they always are, since InDesign works that way. The critical part of your code is the transformReferencePoint assignment, which explicitly refers to the origin of the pasteboard coordinate space. And this determines the center point of the rotation. Maybe a picture will make it clear:

 

2023-09-22-13-23-23.gif

 

Code:

var doc = app.properties.activeDocument;
doc.layoutWindows[0].transformReferencePoint = [0,0];

var sel = app.selection[0];
for( i=-1 ; ++i < 40 ; sel.rotationAngle += 2, $.sleep(200) );

 

Best,

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

Thanks Marc for posting this!

Had no time to get more into details here.

 

One thing that is worth noting:

If one calculates the distance from the origin of the pasteboard ( in my words: "the origin of the document" ) to an object on a different spread, also the gap between the spreads is adding to the distance!

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

Hi @Laubender, I really wondered about this. So the vertical gap between spreads? Interesting. Well, I guess there would be no space between pasteboards though, so I guess the gap between spreads is implicit.

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

Yep! And things get even more complicated when spreads are transformed:

 

MarcAutret_0-1695388212134.png

 

The pasteboard space is the one that embraces all these phenomena, incl. gap between spreads, rotated views, etc. This is an absolute coordinate system. Powerful but tricky 😉

 

Best,

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2023 Sep 22, 2023

Copy link to clipboard

Copied

That's EXACTLY what I've experienced... 

 

But why (0,0) is shifted to the middle of the left edge of the 1st page - even if you move it around manually in the UI?

 

Looks like I need to read your PDF again - thanks @Marc Autret.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2023 Sep 23, 2023

Copy link to clipboard

Copied

OK, this is what I wanted to achieve - and it is working - thanks to @Marc Autret and @m1b's example code.

 

 

But it only works on the 1st page - I still need help with resolving (0,0) point on next Pages / Spreads...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

Hi Robert,

 

If your goal (?) is to perform a rotation on any set of page items (e.g. the selection) as InDesign would do in the GUI, you only have to follow two rules:

 

1) work in the pasteboard space for determining individual bounds (that's what ID does),

2) compute the center point as the midpoint of minmax bounds (not the barycenter).

 

idTransformBoxcenter.gif

Here is a detailed implementation—in ExtendScript—that should work anywhere and whatever the original transform state of the items:

 

 

var myItems = app.selection; // Any array of page items
var myAngleDeg = 20;         // Your rotation angle (in degree)


// Absolute transform space (used by InDesign when you transform the selection).
const SPACE = +CoordinateSpaces.pasteboardCoordinates;

var xy = (function(/*PageItem[]*/a,/*CS*/sp,  bx,TL,BR,t,l,b,r,i,xy,v)
//----------------------------------
// Center point of `myItems` in SPACE coordinates (considering in-SPACE boxes.)
// This is how InDesign works when you manually perform a transformation on
// the selection: the default transform origin is not the 'barycenter' of the
// different box centers, it is the center of the overall bounding box, hence
// the min-max algo.
// => [num,num]
{
	bx = +BoundingBoxLimits.outerStrokeBounds;
	TL = [[0,0],bx,sp];
	BR = [[1,1],bx,sp];
	for( t=l=1/0, b=r=-1/0, i=a.length ; i-- ; )
	{
		xy = a[i].resolve(TL,sp)[0];
		(v=xy[0]) < l && (l=v);
		(v=xy[1]) < t && (t=v);

		xy = a[i].resolve(BR,sp)[0];
		(v=xy[0]) > r && (r=v);
		(v=xy[1]) > b && (b=v);
	}
	return [(l+r)/2, (t+b)/2];
})( myItems, SPACE );

var rot = (function(/*angleRad*/a,  c,s)
//----------------------------------
// Get the rotation matrix.
// => [num,num,num,num,0,0]
{
	c = Math.cos(a);
	s = Math.sin(a);
	return [c,-s,s,c,0,0];
})( myAngleDeg*Math.PI/180 );

// Perform the desired rotation around x,y (SPACE coords).
// ---
var orig = [xy,SPACE];
for( var i=myItems.length ; i-- ; myItems[i].transform(SPACE,orig,rot) );

 

 

Note that myItems can be set to any array of PageItem objects, not necessarily the active selection, and not even necessarily sharing the same spread!

 

Best,

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

Thanks @Marc Autret, I'll try to digest it later - but your video - is EXACTLY what I'm looking for.

 

Of course - the end goal is much bigger - do this on multiple pages / spreads at once ... and even multiple Documents - when someone is working on multiple designs of the leaflet...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

I think I've figured it out ... This piece of code works - sort of:

 

Set myLTransMatrix = myInDi.TransformationMatrices.add(, , , myLAngle)
      For a = 1 To myInDi.ActiveDocument.Selection.Count
         qqq = myInDi.ActiveDocument.Selection.Item(a).Resolve(Array(Array(0, 0), 0), idCoordinateSpaces.idPasteboardCoordinates, True)
         Call myInDi.ActiveDocument.Selection.Item(a).Transform(idCoordinateSpaces.idPasteboardCoordinates, Array(qqq(0)(0), qqq(0)(1)), myLTransMatrix)
      Next a

 

It works - but no matter what I set as <PAGE_INDEX> / <PAGE_LOCATION> - it rotates ONLY around (0,0) point located on the FIRST page of the Spread.

 

I've tried playing with idCoordinateSpaces.idPasteboardCoordinates - but no luck...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2023 Sep 25, 2023

Copy link to clipboard

Copied

OK - just figured it out - and it's working as intended.

Once again, thank you guys for your help - especially @Marc Autret.

For each object - I need to get its ParentPage:

 

Set myLTransMatrix = myInDi.TransformationMatrices.add(, , , myLAngle)
For a = 1 To myInDi.ActiveDocument.Selection.Count
  myLParentPage = myInDi.ActiveDocument.Selection.Item(a).ParentPage.Index
  qqq = myInDi.ActiveDocument.Selection.Item(a).Resolve(Array(Array(0, 0), myLParentPage - 1), idCoordinateSpaces.idPasteboardCoordinates, True)
  Call myInDi.ActiveDocument.Selection.Item(a).Transform(idCoordinateSpaces.idPasteboardCoordinates, Array(qqq(0)(0), qqq(0)(1)), myLTransMatrix)
Next a

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2023 Sep 26, 2023

Copy link to clipboard

Copied

LATEST

And here is a quick preview of the end result - full screen preview would be best:

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines