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

Script to auto attach to artboard.

Advisor ,
Aug 08, 2017 Aug 08, 2017

Hi i have a Layer "Corner Marks" that i would like to automatically fit to the outside bounds of the artboard (the 4 corners.). the Marks are auto inserted but seem to be offset from the artboard a little bit. Thanks everyone.

From (All 4 Corners)

Screen Shot 2017-08-08 at 11.13.14 AM.png

I would like to go to (All 4 COrners)

Screen Shot 2017-08-08 at 11.18.30 AM.png

TOPICS
Scripting
716
Translate
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

Community Expert , Aug 08, 2017 Aug 08, 2017

huzzah. now you're asking good questions!

In the perfect circumstances, the resize method might work, but being that conditions need to be ideal, i would recommend choosing a different direction.

But for the sake of learning new things, let's look at why you're getting the error that you're getting. the resize method works on art objects (pathItems,groupItems,compoundPathItems,rasterItems,etc), but 'selection' is an array. So if you're changing

app.activeDocument.groupitems[0].resize(#,#)

to

app.acti

...
Translate
Adobe
Community Expert ,
Aug 08, 2017 Aug 08, 2017

Do you have some code you need help with, or do you have a specific question? Or are you looking for someone to write the code?

Translate
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
Advisor ,
Aug 08, 2017 Aug 08, 2017

I'm kind of looking to see if this is already created somewhere.  I do not have code for this. I've dabbled with indesign scripts but what i'm seeing is that they are in some cases quite different in the scripting.

Translate
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 ,
Aug 08, 2017 Aug 08, 2017

Some of the functionality is different and some DOM elements are accessed in different ways, but logically everything works the same. If you write up the logic you're looking for, we can help you with the Illustrator specific API stuff.

It's probably unlikely that you're going to find this exact script already written, but who knows.

Translate
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
Advisor ,
Aug 08, 2017 Aug 08, 2017

This does what i want in reverse.  app.activeDocument.fitArtboardToSelectedArt(0);.  I tried to Switch Artboard & SelectedArt didnt work like i was hoping.  I'm gonna dig alittle deeper on the forums and see if i can find something closer to what i want.

***UPDATE***

I'm thinking that rather than Going by "Layer Name" i should go by Selection.  It would allow me a little more flexibility.

Translate
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
Advisor ,
Aug 08, 2017 Aug 08, 2017

Ok let me know if there is a better way to do this. Do you for see any problems with this?  The only thing i may have trouble with is "groupItems"  everytime i change this to selection it does not work.

  app.activeDocument.groupItems[0].resize(98.764,99.5932);

Translate
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 ,
Aug 08, 2017 Aug 08, 2017

huzzah. now you're asking good questions!

In the perfect circumstances, the resize method might work, but being that conditions need to be ideal, i would recommend choosing a different direction.

But for the sake of learning new things, let's look at why you're getting the error that you're getting. the resize method works on art objects (pathItems,groupItems,compoundPathItems,rasterItems,etc), but 'selection' is an array. So if you're changing

app.activeDocument.groupitems[0].resize(#,#)

to

app.activeDocument.selection.resize(#,#)

you're going to get an error because resize is not a method of the array object.

If you're changing

app.activeDocument.groupitems[0].resize(#,#)

to

app.activeDocument.selection[0](#,#)

and still getting the error, it's likely that there is no selection.

I'm merely taking a stab in the dark here since i don't know what error you got, what the file looks like or the state of the file when you ran the script.

Now let's consider a better, more portable way to do this.

Take each corner mark (as an array), determine it's position (which one is closest to the top left of the artboard, which one is closest to the top right, etc), then change the position of the mark to match the edges of the artboard. Here's some pseudo-code:

buffer = 20

for each corner mark

     if this corner mark's position is within 'buffer' of the top left corner of the artboard

          move this corner mark to match the edges of the artboard

     else if ... top right

     else if ... bottom left

     else if ... bottom right

Translate
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
Advisor ,
Aug 09, 2017 Aug 09, 2017

Excellent thank you so much for your help. Works Like a charm.

Translate
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 ,
Aug 09, 2017 Aug 09, 2017
LATEST

awesome. glad to help. come on back any time with questions, we're glad to help around here. 😃

Translate
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