Setting a macro condition to see if a reference exists?


Renerabbitt
 Share

Recommended Posts

10 minutes ago, Renerabbitt said:

I have a condition where I want a variable to report a referenced layer name, but if no reference exists, report its own layer name.
Any help is greatly appreciated

What do you mean by referenced?  Do you mean the note or text is connected to an object with an arrow?  if so, try this:

  • referenced ? obj=referenced : obj=owner
  • obj.layer.to_s

If there's no connection it will return the layer of the text or note as a text string.

Link to comment
Share on other sites

1 minute ago, solver said:

Maybe a bit more info about what you are doing would help.

An old habit, I have to make a post and then go back and re-edit it(the way my brain works) but you guys beat me to it.
I have a text box with a macro. I want that macro to report the value for a layer of a reference object via a leader. If no leader exists, then I would like it to report the layer of the text box that it is contained in.
 

 

4 minutes ago, Joe_Carrick said:

If there's no connection it will return the layer of the text or note as a text string.

This method works...but why?
why does the referenced layer supersede the owner? Is this an order of operations that is constant?

Link to comment
Share on other sites

19 minutes ago, Renerabbitt said:

This method works...but why?
why does the referenced layer supersede the owner? Is this an order of operations that is constant?

It isn't the referenced layer, it's the referenced object.  The first line established what object to examine.  If there's a connection (ie: referenced ? is true) then the connected (referenced) object is examined and its layer is displayed.  Otherwise, the owner (text or note) is examined and its layer is displayed.

 

Very simply, that first line determines what object is going to be reported. obj is the object because the first line set it either as the referenced object or the owner object.

 

 

That 1st line could have been written:

  • if referenced ?
  •   obj=referenced
  • else
  •   obj=owner
  • end
Link to comment
Share on other sites

On 2/8/2022 at 10:12 AM, Renerabbitt said:

This method works...but why?
why does the referenced layer supersede the owner? Is this an order of operations that is constant?

 

Your conditional statements are what causes one thing to supersede anotherIn this example, you're using what's called a ternary operator which consists of 3 parts separated by a question mark and a colon (condition ? value if truthy : value if falsey), and you're testing to see if referenced has any truthy value.  If it does, your obj variable is defined as referenced throughout the rest of your code.  That's it.  You've created a fork in the road and have decided to head down the referenced path. 

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share