Applying warp to object using extended script

Community Beginner ,
Jan 12, 2021

Copy link to clipboard

Copied

Hello,

 

I found a great post and answer by Silly-V using Live Effects under this post: https://forums.adobe.com/message/9356527#9356527 . It certainly helped me since I can now warp my object. However, I still have a minor issue after using this tool. Namely, after warping, the shape of the object changes but the selection stays the same. I have a specified canvas size and therefore the selection may stay inside the canvas while the shape actually does not. Since my script also exports the PDF it therefore cuts off parts of the shape.

I have seen that using "envelope distort" updates the selection so that the entire shape is included after warping. However, I cannot find any way to apply the envelope distort warp other than this: 

 

 

app.executeMenuCommand("Make Warp");

 

Nonetheless, I need the whole process to be automatic so that does not help. This command only opens the envelope distort warp dialogue, but you first have to manually select the shape and then you have to manually set the warp percentage.
 
Another potential solution would be to update the selection so that it includes the full shape. I don't know how to do this either. If you have any ideas or solutions that would be very much appreciated! Thank you.

Hi Karl,

 

Not sure if I understand you right, but see if this makes sense:

 

var item = app.activeDocument.selection[0];
item.applyEffect('<LiveEffect name="Adobe Deform"><Dict data="R DeformValue 0.5 R DeformHoriz 0.0 R DeformVert 0.0 I DeformStyle 3 B Rotate 0 "/></LiveEffect>');
$.writeln('item.height = '+item.height);
app.redraw();
app.executeMenuCommand('expandStyle');
item = app.activeDocument.selection[0];
$.writeln('item.height = '+item.height);

 

 

Screen Shot 2021-01-12 at 9.24.31 pm.png

 

Box 1 is starting point. Box 2 has a Warp "ArcUpper" on it and exceeds the artboard, but it's height is still 80 so there's no way to know the problem. Box 3 is expanded, so you can resize it to fit artboard. (Note that you could duplicate the item first and expand the duplicate, measure the new dimensions, then remove the expanded item.)

 

Is that what you needed? - Mark

TOPICS
Scripting

Views

28

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

Applying warp to object using extended script

Community Beginner ,
Jan 12, 2021

Copy link to clipboard

Copied

Hello,

 

I found a great post and answer by Silly-V using Live Effects under this post: https://forums.adobe.com/message/9356527#9356527 . It certainly helped me since I can now warp my object. However, I still have a minor issue after using this tool. Namely, after warping, the shape of the object changes but the selection stays the same. I have a specified canvas size and therefore the selection may stay inside the canvas while the shape actually does not. Since my script also exports the PDF it therefore cuts off parts of the shape.

I have seen that using "envelope distort" updates the selection so that the entire shape is included after warping. However, I cannot find any way to apply the envelope distort warp other than this: 

 

 

app.executeMenuCommand("Make Warp");

 

Nonetheless, I need the whole process to be automatic so that does not help. This command only opens the envelope distort warp dialogue, but you first have to manually select the shape and then you have to manually set the warp percentage.
 
Another potential solution would be to update the selection so that it includes the full shape. I don't know how to do this either. If you have any ideas or solutions that would be very much appreciated! Thank you.

Hi Karl,

 

Not sure if I understand you right, but see if this makes sense:

 

var item = app.activeDocument.selection[0];
item.applyEffect('<LiveEffect name="Adobe Deform"><Dict data="R DeformValue 0.5 R DeformHoriz 0.0 R DeformVert 0.0 I DeformStyle 3 B Rotate 0 "/></LiveEffect>');
$.writeln('item.height = '+item.height);
app.redraw();
app.executeMenuCommand('expandStyle');
item = app.activeDocument.selection[0];
$.writeln('item.height = '+item.height);

 

 

Screen Shot 2021-01-12 at 9.24.31 pm.png

 

Box 1 is starting point. Box 2 has a Warp "ArcUpper" on it and exceeds the artboard, but it's height is still 80 so there's no way to know the problem. Box 3 is expanded, so you can resize it to fit artboard. (Note that you could duplicate the item first and expand the duplicate, measure the new dimensions, then remove the expanded item.)

 

Is that what you needed? - Mark

TOPICS
Scripting

Views

29

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
Jan 12, 2021 0
Engaged ,
Jan 12, 2021

Copy link to clipboard

Copied

Hi Karl,

 

Not sure if I understand you right, but see if this makes sense:

 

var item = app.activeDocument.selection[0];
item.applyEffect('<LiveEffect name="Adobe Deform"><Dict data="R DeformValue 0.5 R DeformHoriz 0.0 R DeformVert 0.0 I DeformStyle 3 B Rotate 0 "/></LiveEffect>');
$.writeln('item.height = '+item.height);
app.redraw();
app.executeMenuCommand('expandStyle');
item = app.activeDocument.selection[0];
$.writeln('item.height = '+item.height);

 

 

Screen Shot 2021-01-12 at 9.24.31 pm.png

 

Box 1 is starting point. Box 2 has a Warp "ArcUpper" on it and exceeds the artboard, but it's height is still 80 so there's no way to know the problem. Box 3 is expanded, so you can resize it to fit artboard. (Note that you could duplicate the item first and expand the duplicate, measure the new dimensions, then remove the expanded item.)

 

Is that what you needed? - Mark

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...
Jan 12, 2021 1
Community Beginner ,
Jan 12, 2021

Copy link to clipboard

Copied

Mark,

 

Wow that did definitely work. Thank you so much for the quick and insightful reply. This is exactly what I needed, to capture that bit of hidden height and resize it. I already had the code to resize, so I just had to copy in the expansion work you did and it immediatly executed perfectly.

If you do not mind, I would like to ask you a theoretical question as well. I just started scripting in Illustrator so I am still new to some concepts. When you work with the activeDocument.selection[0], I thought that I first had to select the object for the changes to apply, but in my case the object is imported directly from my computer so I never get the chance to select it. It still worked for me which is great but I would love to understand why.

Related to this, I had some issues with working on a PDF object after opening it via a script:

 

var fileRef = new File("C:/originalpeople/Winetumbler/canvas_test1.pdf");

if (fileRef != null) {
  var docRef = open(fileRef, DocumentColorSpace.RGB, );
}

 

The PDF is imported just fine here, but I don't understand quite how to access its content. I tried looking at the document's groupItems (there were 9), pathItems (98), rasterItems (0), etc. But it did not quite work. Here is the content of the PDF:

PDF_illustrator.png

 

I want to store this same selection as you see in the image in a variable. I believe I have some fundamental concepts missing and I am sorry if I am phrasing these questions poorly. The solution I used in the end, in case that anyone else has a similar issue, was to embed the PDF as a groupItem as such:

 

var embedDoc = new File(myPath + "canvas_test1.pdf");
if (app.documents.length > 0 && embedDoc.exists) {
  var doc = app.activeDocument;
  var placed = doc.groupItems.createFromFile(embedDoc);
}

 

While this solution works perfectly fine for me, I just want to be able to better understand what is going on so I can tackle similar issues in the future. I basically want to understand how to go about selecting different objects in a script when you do not create them inside the script, and exactly what .selection[o] is referencing (I thought it was the first of whichever object you selected).

 

I hope I have explained myself properly and I am super greatful for the help already provided.

 

Thank you Mark!

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...
Jan 12, 2021 0
Resources