A simple one line script to show the Artboard Cross Hairs:
All have failed!
app.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!
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.
app.activeDocument.artboards.showCrossHairs = true;
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;
In the following documents:
Illustrator Scripting Guide Release 0.0.1
Adobe Illustrator CC Scripting Guide
Adobe Illustrator Scripting Guide! ( https://ai-scripting.docsforadobe.dev/index.html)
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.
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
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.
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
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.
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 or artboards or artboards, 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].