question

JPYR avatar image
0 Likes"
JPYR asked Ryan Clark commented

Declaring functions and objects in FlexScript

Hello, I am testing the capabilities of the environment for WMS integrations, and as such we would need to write a lot of custom code. In fact, the grand majority of our work on the simulator would be about writing custom code and making a sort of shared code library we can easily leverage from model to model.

Naturally, the code would include a lot of re-usable parts that would be great to have as functions or methods, but I haven't found anything to declare such things per se in FlexScript - a cursory search suggested some workarounds with function_s and events, or having a custom object with FlexScript stuffed into labels, but is there a better practice for reusable code at this time?

Likewise, I'd like to be able to declare objects (or rather, classes/structs) to hold multiple attributes or even functions/methods, but I have not found a way to do something like this. For example's sake, let's say I want to implement a Car object, and the object would then have attributes like color, make, model, etc, and I'd pass instances of this object around in code. Is there a workaround to achieve this kind of a structure?

FlexSim 22.1.0
flexscriptprogramming
· 1
5 |100000

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

Ryan Clark avatar image Ryan Clark commented ·

Hi @JPYR, was Joerg Vogel's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Jason Lightfoot edited

SDK that is your answer. currently you are analyzing a software frontend to build models and do experiments on a point of view of a user. You are developer, not a user. Then you have to look for this kind of information in a manual. It is the reference manual at the end. From a perspective of a user you can build user libraries to reuse functions, objects, process flows. But you are looking for interfaces from a perspective of a programmer then your interfaces are DLL or adding modules to FlexSim.

BUT before you start Developer work, it is a good practice to discover abilities of FlexSim from a perspective of an advanced user. You have to build models on your own. Please contact a distributor to take part at a course to learn FlexSim. I know a person, who is a programmer and started FlexSim as a well educated programming expert. He tried to find structures of higher programming languages in FlexSim and he misused given structures just to force tasks into his known world. Later he discovered, this wasn’t necessary, FlexSim has got all features he needed. All he had to do was, build more models to learn.

https://docs.flexsim.com/en/22.1/Reference/DeveloperAdvancedUser/ModuleSDK/KeyConcepts/KeyConcepts.html
https://docs.flexsim.com/en/22.1/Reference/DeveloperAdvancedUser/ConnectingToExternalCode/ConnectingToExternalCode.html

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

JPYR avatar image JPYR commented ·

I am asking these question because I couldn't find the information I need in the manual, or from this forum. I have been building models for around 15 years in other software, and we're currently evaluting moving over to Flexsim. I am aware that external DLLs could do anything, because I have written them for the other software as well, but it's also quite overkill for reusable code and I am therefore interested in options and workarounds inside the simulation environment itself.

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel JPYR commented ·

If you want to achieve this, you do this with user libraries

https://docs.flexsim.com/en/22.1/Reference/DeveloperAdvancedUser/CustomLibraries/CustomLibraries.html

You can customize those user libraries that they get a behavior when you load them or you drag objects from them into a model. User libraries can consists of nearly everything you use in 3D model view. I am not sure if you can add user customized dashboard widgets in a user library.
You can set options to add automatically user libraries on FlexSim start in your customized workspace.

If you want to add a subset of objects as a whole object group into a new model, you put those objects first on a visual plane and build a user library object from this plane. The plane is acting as a container.

You can add user defined functions in the toolbox to call them from triggers when needed.

https://docs.flexsim.com/en/22.1/Reference/Tools/UserCommands/UserCommands.html

you can add nodes in the tree, which can contain source code. you call the node from another function to execute the source code of this node.

@Phil BoBo , @Matthew Gillespie would you write more about abilities of FlexSim for this kind of task. Thanks!

0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Joerg Vogel commented ·

Furthermore, you can save the library as one or more xml files use the the ffm file map definition and use that in a repository to centrally manage shared/parallel developed objects and code.

Contained in Jorg's links you'll find comparison of the advantages and disadvantages of UserLibraries, Direct Development and Modules - direct link here.

One thing the comparison doesn't mention is the situation where an organisation might need an audit trail whereby all models and their results are stored with the relevant development step of a custom development so that any run can be loaded and repeated with minimal effort. With modules that will involve swapping out module versions and keeping an external list of which model uses which versions. In the past I've had success moving a user library into the model space before saving the model and restoring it when the model is loaded - something to consider if you have this need.

1 Like 1 ·