Exists
exists(expression) returns TRUE if the given expression is true within the context of the macro and the defined document, layer or element does exist.
# some examples:
IF (exists (activeDoc) = false) THEN
MESSAGE "No document opened!"
IF (exists (activeDoc.firstSelectedElement) = false) THEN
MESSAGE "No element selected!"
IF (exists (activeDoc.layers[3]) = false) THEN
MESSAGE "Less than three layers exist!"
IF (exists (activeDoc.layers["Background"].firstChild) = false) THEN
MESSAGE "Background layer is empty!"
IF (exists (activeDoc.firstSlectedElement.info) = false) THEN
MESSAGE "The first selected element has no object info!"
IF (exists (app.pens["Thick"]) = false) THEN
MESSAGE "Pen ""Thick"" does not exist!"
MACRO AddCustomPen
DEFINE penName AS String
penName = Get String "Name of your new Pen?"
IF (exists (activeDoc.Pens[penName]) = false) THEN
Add Pen penName
ELSE
MESSAGE "Pen " + penName + " already exists!"
END IF
END MACRO