question

Lucas Klein avatar image
1 Like"
Lucas Klein asked Matthew Gillespie commented

Is "model().find" a heavy (computational) code?

How much could the use of the code "model().find" impact in the model performance?

My question is if this code works the same way that a "For" code does, or if it works somehow else lighter. Case it does not, there is another code that could be used instead, looking for improve the code performance?

FlexSim 18.1.1
codingloopperformancefor
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matt Long avatar image
4 Likes"
Matt Long answered Matthew Gillespie commented

The find method does involve multiple steps in order to locate the desired node. It does checking for special characters like @, ~, .., +, /, >, ?, LAST etc. It then starts with the top container and loops through the subnodes to find the object with the specified name. If there are additional levels to the find, ie model().find("VisualTool1/Processor1"), then it will continue looping through the next container until it locates the next object.

If you're worried about speed and you're using the find command with static names ie model().find("Processor1"), you have a few different options to increase the speed (listed in order of speed):

  1. Global Variables: Create a global variable for your object. You can then reference that object with the global variable name anywhere in code or a picklist.
  2. Port Connections: Connect objects up using port connections then reference objects by rank. current.centerObjects[1]
  3. Labels: Labels on objects, items or tokens can store references to other objects. To access the object use dot syntax, current.MyObject or token.MyObject
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Albert L avatar image Albert L commented ·

Hi Matt,

Do you have the comprehensive list of special characters not allowed in object names? I want to write a parser that checks for these characters and remove/replaces them.

There should be a function like this that already exists, but I'm not able to find it. Thanks for the help!

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Albert L commented ·

Can you ask this as a separate question? Our best practices page encourages asking new separate questions instead of asking tangential questions in the comments of a different question.

1 Like 1 ·
Albert L avatar image Albert L Albert L commented ·

I found validatename (obj node, num isviewtext [, obj object])

but I'm looking for a method that can be passed in a string and outputs the corrected string without necessarily changing the node properties or popping up a message.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.