How to script showCrossHairs

Community Beginner ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

A simple one line script to show the Artboard Cross Hairs:

All have failed!

app.artboard.showCrossHairs;
app.artboard.showCrossHairs = true;
app.activeDocument.artboard.showCrossHairs;
app.activeDocument.artboard.showCrossHairs(true);
app.activeDocument.artboard.showCrossHairs = true;
app.activeDocument.artboard.showCrossHairs = “true”;

Please please give me an example of something that works!

Thank you so much!

TOPICS
Scripting

Views

173

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
community guidelines
Adobe Community Professional ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

I don't really know what crosshairs you're talking about.. how would you normally do this with the UI?

 

There's a print setting for trim marks or alignment crosshairs.. but that's not something that gets applied to the document or the artboard. it's just written into the print file. 

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
community guidelines
Community Beginner ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

Cross Hairs and Show Center Mark are items I find useful.  On the Artboards Window, double click on icon that looks like a page.  This opens the Artboard Options Window.  Attched some images are attached.  Thank you so much for looking into this.  I hope this helps!

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
community guidelines
Advocate ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

app.activeDocument.artboards[0].showCrossHairs = true;

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
community guidelines
Adobe Community Professional ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

Just to fill out what @femkeblanco correctly wrote: showCrossHairs is a property of Artboard. Artboards are usually accessed via the artboards property of Document. Document.artboards has a method getByName(nameToSearchFor) so you can do this:

app.activeDocument.artboards.getByName('My Best Artboard');

or simply use an Array-like index, as @femkeblanco showed. So you can iterate over them and set all the artboards showCrossHairs.

var doc = app.activeDocument;
for (var i = 0; i < doc.artboards.length; i++)
    doc.artboards[i].showCrossHairs = true;

 - 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
community guidelines
Community Beginner ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

Thank you!

 

In the following documents:

Illustrator Scripting Guide Release 0.0.1
Adobe Illustrator CC Scripting Guide
Adobe Illustrator CC Scripting Reference: JavaScript
Adobe Illustrator Scripting Guide! ( https://ai-scripting.docsforadobe.dev/index.html)
Illustratorcc2017JavaScriptScriptingRefen.1362469837

All show that the showCrossHairs as a subset of Artboard.  There is absoutely no clue that showCrossHairs is part of Artboards.  Please forgive me, but how the hell is one suppose to learn/develop scripts when all documention is wrong.  I spent over a week trying to find how ro do this.  You have no idea how frusturation this is! 

 

Adobe needs to fix this!

 

Thank you again for providing the top secret decoder ring.

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
community guidelines
Adobe Community Professional ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

It is confusing at first, but I don't think the documentation is wrong. To understand it better, you might need to improve your understanding of Javascript Objects especially how to get, store, handle and access them. A basic Javascript course would help here, but be careful because ExtendScript (the flavour of javascript we use here) is very old, similar to Javascript version 3. I'm not super expert myself, but I'll have a quick go of explaining, or at least giving you something to think about.

 

"showCrossHairs" is a property of Artboard, which is a constructor or constructor-like object (would be a Class in modern javascript).

 

Capitalization matters. Artboards is another Object (it is an array-like collection) that provides access to a document's artboards. But you don't access Artboards (the constructor-like object), you access Document.artboards which will provide access to a document's instance of Artboards. Here artboards is a property of Document that refers to an instance of Artboards. But you don't access Document, you access App.documents which will provide access to an app's instance of Documents which is a property of App. But you don't access App, you access app which is a global variable provided by the scripting API that refers to an instance of the application you are targetting (eg. Illustrator).

So in the line

app.documents[0].artboards[1].showCrossHairs

 is first getting the global variable app (an instance of App), then the property documents of that instance (which is itself an instance of Documents) and asking for the first index which gives you the first document of app, which is an instance of Document, then you ask for the property artboards of that instance of Document, which gives you an instance of Artboards and you ask for the second element of the Artboards instance which gives you an instance of Artboard to which you (finally!) ask for the property showCrossHairs which is a Boolean (true or false) object.

 

Notice that nowhere in my line of code above I referred to App or Documents or Document or Artboards or Artboard directly? That's because I used the global var "app" and the rest is accessing properties or array-like elements of the objects that are returned when asking for those properties.

 

So Artboard ≠ artboard, and when the documentation says showCrosshairs is a property of Artboard it is correct. To say showCrossHairs is a property of artboard is incorrect unless you have a variable called artboard that refers to an instance of Artboard. Any instance of Artboard will have the property showCrossHairs unless it has been overwritten.

- 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
community guidelines
Community Beginner ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

Wow Mark,  I got a headache just reading your reply.  Yes, I need a basic course.  But I am a really old dude trying to help others out.  My way of thinking is ancient - I used to program PDP, Nova, CDC systems in assembly - very linear.  Thought I had a little understanding of Object Oriented Programming.  Instead have show that I am an idiot and that a little knowledge can be worse than complete ignorance.  Your response must have taken a long time to write - thank you!  I understand some of what you wrote but need to digest those aspects I don't understand.  Please allow me to get back to you with other questions.

 

Thanks again, Over and out

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
community guidelines
Adobe Community Professional ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

Yeah I agree—it's a lot, and laid out as a dump like that isn't a great experience for someone learning. I just wanted you to understand that there is sense to it, despite the complexity. You certainly aren't an idiot! This is weird stuff until you have some experience with OOP and javascript and Illustrator—each of which bring their own quirks to the party! Good luck and feel free to ask questions of course. 🙂

- 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
community guidelines
Adobe Community Professional ,
Mar 30, 2022 Mar 30, 2022

Copy link to clipboard

Copied

the programming guide does not make sense...until it does. We've all been in the same boat. If you want to continue learning don't let the documentation or your age or your previous knowledge of other programming languages get in your way.

 

 

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
community guidelines
Advocate ,
Mar 31, 2022 Mar 31, 2022

Copy link to clipboard

Copied

LATEST

In short, practically all single objects are referenced in terms of the collection they are elements of. So you don't say "artboard", you say artboards[i] (artboards[0] or artboards[1] or artboards[2], et cetera). This makes sense, of course, since if you have >1 artboard, how would Illustrator know which artboard you mean when you say "artboard". Similarly, you don't say "document", "layer" and "pathItem", for example, you say documents[i], layers[i] and pathItems[i].

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
community guidelines