Renerabbitt Posted February 8, 2022 Share Posted February 8, 2022 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 Link to comment Share on other sites More sharing options...
Chopsaw Posted February 8, 2022 Share Posted February 8, 2022 I think it was Joe that originally posted this method. referenced ? obj = referenced : obj = owner obj.layer Does that do what you are after set to "None" and "Evaluate" ? Link to comment Share on other sites More sharing options...
Joe_Carrick Posted February 8, 2022 Share Posted February 8, 2022 On 2/8/2022 at 6:58 PM, 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 Expand 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 More sharing options...
Renerabbitt Posted February 8, 2022 Author Share Posted February 8, 2022 On 2/8/2022 at 7:07 PM, solver said: Maybe a bit more info about what you are doing would help. Expand 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. On 2/8/2022 at 7:07 PM, Joe_Carrick said: If there's no connection it will return the layer of the text or note as a text string. Expand 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 More sharing options...
Joe_Carrick Posted February 8, 2022 Share Posted February 8, 2022 On 2/8/2022 at 7:12 PM, Renerabbitt said: This method works...but why? why does the referenced layer supersede the owner? Is this an order of operations that is constant? Expand 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 More sharing options...
Alaskan_Son Posted February 9, 2022 Share Posted February 9, 2022 On 2/8/2022 at 7:28 PM, Joe_Carrick said: That 1st line could have been written: if referenced ? obj=referenced else obj=owner end Expand "if referenced ?" shouldn't have the question mark. Link to comment Share on other sites More sharing options...
Joe_Carrick Posted February 9, 2022 Share Posted February 9, 2022 On 2/9/2022 at 3:44 AM, Alaskan_Son said: "if referenced ?" shouldn't have the question mark. Expand Sorry, I'm so used to writing the conditional on a single line. Link to comment Share on other sites More sharing options...
Alaskan_Son Posted February 10, 2022 Share Posted February 10, 2022 On 2/8/2022 at 7:12 PM, Renerabbitt said: This method works...but why? why does the referenced layer supersede the owner? Is this an order of operations that is constant? Expand Your conditional statements are what causes one thing to supersede another. In 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 More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now