Get a line of a custom code from a script

Get a line of a custom code from a script

sebastien_b49
Advocate Advocate
12 Views
3 Replies
Message 1 of 4

Get a line of a custom code from a script

sebastien_b49
Advocate
Advocate

[ FlexSim 20.2.3 ]

Hi !

I'd like to write an automatic documentation system in my model. I added a Dashboard with Model documentation and within a dynamic flexscript I tried to recover one line from a custom code where the documentation is written.

I could recover the entire code but I did not succeed in separating it per line. It does not seem to take it as an array or a text, as the property length is not working. Neither is slice.

Is it possible to get one or several line from the codeNode property of a Custom Code ?

Test_Doc.fsm

0 Likes
Accepted solutions (1)
13 Views
3 Replies
Replies (3)
Message 2 of 4

regan_blackett
Autodesk
Autodesk
Accepted solution

You will need to recast the code node's value as a string first then you perform whatever string based operations you need to do:

string codeNodeString = model().find("/Tools/ProcessFlow/ProcessFlow/Test>variables/codeNode").value.as(string);

This will get the code node as a string. Then something like this would let you get a portion of the code node as a substring:

string subString = codeNodeString.slice(codeNodeString.indexOf("Doc"));

I'm assuming the comment in your code node is what you were wanting shown on the dashboard.

0 Likes
Message 3 of 4

jason_lightfootVL7B4
Autodesk
Autodesk

To answer your questions about multiple lines - here's an example using the split function to get an array

treenode codeNode = model().find("/Tools/ProcessFlow/ProcessFlow/Test>variables/codeNode");
string s=codeNode.value;
Array allLines=s.split(strascii(13));
for (int n=1;n<=allLines.length;n++)
      pt(allLines+"<br>");

You could also try replacing strascii(13) with <br> and then just print the string.

treenode codeNode = model().find("/Tools/ProcessFlow/ProcessFlow/Test>variables/codeNode");
string s=codeNode.value;
s=s.replace(strascii(13),"<br>",1);
print(s);
0 Likes
Message 4 of 4

sebastien_b49
Advocate
Advocate

Thank you @Regan Blackett and @Jason Lightfoot !

I was missing the .as(string) in my code. I assumed the text returned with .value was enough.


0 Likes