Highlighted

Illustrator Extendscript: Position Clipping Masks

New Here ,
May 18, 2020

Copy link to clipboard

Copied

I want to know how to position clipping mask groups with Extendscript - properly. Simply setting the position is not good enough.

 

selection[0].position = [0, 0]

 

 

This code will work improperly with a clipping mask group if the inner contents of the clipping mask group are larger than the clipping mask object itself because the position point of reference of a clipping mask group is the outer most top-left corner of the bounding box of the clip-mask object or whatever contents is being clip-masked, which ever is largest. Another way of stating it is that if the inside contents of the clipping mask group are larger in either axis than the clipping mask object itself, then the outer most bounds of the clipping mask group are not considered to be the clipping mask object. This means that the position reference is not on the top left corner of the clipping mask, but somewhere outside of it. As you might have figured out, this makes it incredibly difficult to apply position changes to clipping mask groups and get reliable width/height/etc. data when the bounds of your group are almost never your actual clip mask outline - the whole point of the existence of clipping masks. I believe these problems also exist for regular masks.

 

I have already tried a work around where I create a duplicate of the clipping mask outline itself (basically a proxy object), calculate the position I want on this proxy object with a particular algorithm, then apply the difference in position from the original clipping mask and the proxy back on to the original clipping mask. It actually works quite well. But this becomes a very difficult solution to extend when you have a group of clipping masks and other regular pageItems in a multi layer nested hierarchy. This coupled with the fact that you can't edit the contents of the selection object (add or remove objects that are selected, etc.) makes my problem seemingly almost impossible to solve.

 

Btw, while the above positioning code works it's interesting that this won't:

 

selection[0].position[0] = 0

 

 

How do I set the position of a clipping mask group if the read position data isn't reliable? A better implementation of my proxy logic?

 

I'm not the best programmer in the world so the severe limitations of Extendscript being limited to ECMA3 and the API being less than desirable leave me asking for help here. I'm using VS Code and the Adobe extendscript debugger extension.  Thanks.

Salut!

tem = selection[0];alert(item)
item.position = [0,0];
rect = item.pathItems[0];
pos = rect.position;
item.position = [-pos[0],-pos[1]]

Pour faire simple...

 

TOPICS
Scripting

Views

502

Likes

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

Illustrator Extendscript: Position Clipping Masks

New Here ,
May 18, 2020

Copy link to clipboard

Copied

I want to know how to position clipping mask groups with Extendscript - properly. Simply setting the position is not good enough.

 

selection[0].position = [0, 0]

 

 

This code will work improperly with a clipping mask group if the inner contents of the clipping mask group are larger than the clipping mask object itself because the position point of reference of a clipping mask group is the outer most top-left corner of the bounding box of the clip-mask object or whatever contents is being clip-masked, which ever is largest. Another way of stating it is that if the inside contents of the clipping mask group are larger in either axis than the clipping mask object itself, then the outer most bounds of the clipping mask group are not considered to be the clipping mask object. This means that the position reference is not on the top left corner of the clipping mask, but somewhere outside of it. As you might have figured out, this makes it incredibly difficult to apply position changes to clipping mask groups and get reliable width/height/etc. data when the bounds of your group are almost never your actual clip mask outline - the whole point of the existence of clipping masks. I believe these problems also exist for regular masks.

 

I have already tried a work around where I create a duplicate of the clipping mask outline itself (basically a proxy object), calculate the position I want on this proxy object with a particular algorithm, then apply the difference in position from the original clipping mask and the proxy back on to the original clipping mask. It actually works quite well. But this becomes a very difficult solution to extend when you have a group of clipping masks and other regular pageItems in a multi layer nested hierarchy. This coupled with the fact that you can't edit the contents of the selection object (add or remove objects that are selected, etc.) makes my problem seemingly almost impossible to solve.

 

Btw, while the above positioning code works it's interesting that this won't:

 

selection[0].position[0] = 0

 

 

How do I set the position of a clipping mask group if the read position data isn't reliable? A better implementation of my proxy logic?

 

I'm not the best programmer in the world so the severe limitations of Extendscript being limited to ECMA3 and the API being less than desirable leave me asking for help here. I'm using VS Code and the Adobe extendscript debugger extension.  Thanks.

Salut!

tem = selection[0];alert(item)
item.position = [0,0];
rect = item.pathItems[0];
pos = rect.position;
item.position = [-pos[0],-pos[1]]

Pour faire simple...

 

TOPICS
Scripting

Views

503

Likes

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
May 18, 2020 0
Enthusiast ,
May 18, 2020

Copy link to clipboard

Copied

Salut!

tem = selection[0];alert(item)
item.position = [0,0];
rect = item.pathItems[0];
pos = rect.position;
item.position = [-pos[0],-pos[1]]

Pour faire simple...

 

Likes

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
Reply
Loading...
May 18, 2020 1
3d3d3d3d LATEST
New Here ,
May 26, 2020

Copy link to clipboard

Copied

Thank you. I get what this logic is doing and it helps a lot. Quite simple indeed. Although for my specific case I would have to implement it in a more complicated way that's hard to exlain.

Likes

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
Reply
Loading...
May 26, 2020 0
Resources