question

Sebastien avatar image
0 Likes"
Sebastien asked Sebastien edited

Get a line of a custom code from a script

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

FlexSim 20.2.3
custom codemodel documentation
test-doc.fsm (27.2 KiB)
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

Regan Blackett avatar image
0 Likes"
Regan Blackett answered Sebastien edited

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.

· 2
5 |100000

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

Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

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[n]+"<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 0 ·
Sebastien avatar image Sebastien commented ·

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 0 ·