question

Tom S4 avatar image
0 Likes"
Tom S4 asked Jordan Johnson answered

Create processflow activity via flexscript

Backstory: I am writing a module to help speed up development time of ProcessFlow-heavy models. One of the more time-consuming but repeatable activities of our standard workflow is resource creation (create PF resource, name PF resource, set location of PF resource, create 3D object, name 3D object, set location of 3D object, link PF resource to 3D object, link PF quantity to table quantity, repeat for potentially hundreds of resources). My idea is to automate most of this.

I've figured out all aspects of this, except automatically creating PF resources.

I have tried the following:

treenode template = getactivity("ProcessFlow", "Resource"); // existing activity reference
createinstance(template, Model.find("Tools/ProcessFlow/ProcessFlow"));
treenode template = Model.find("Tools/ProcessFlow/ProcessFlow/Resource"); // existing activity reference from model tree
createinstance(template, Model.find("Tools/ProcessFlow/ProcessFlow"));
treenode template = views().find("modules/ProcessFlow/DragDropLibrary/Shared Assets/Resource"); // template activity reference from view tree
createinstance(template, Model.find("Tools/ProcessFlow/ProcessFlow"));
treenode template = maintree().find("project/library/processflow/activities/ResourceBlock"); // template activity reference from main tree
createinstance(template, Model.find("Tools/ProcessFlow/ProcessFlow"));

All result in exceptions that make the saved model un-usable.


I've looked through previous questions on here. I found one from 2017 which says this is not possible (at least at the time) due to a design choice:

https://answers.flexsim.com/questions/42248/creating-processflow-with-flexscript-code.html

Is this still accurate? If so, are there any alternatives? Surely there is code in the backend that is triggered when, say, dragging/dropping from the library, or copying and pasting an existing activity. Is this accessible?

FlexSim 23.0.1
processflowflexscriptresources
· 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.

Tom S4 avatar image Tom S4 commented ·

Update:

Still not working, but found something else. In one of the examples, I used ResourceBlock:

maintree().find("project/library/processflow/activities/ResourceBlock")

However, I discovered there is actually another activity listed as Resource:

maintree().find("project/library/processflow/activities/Resource")


This seems to create a new Resource in my ProcessFlow instance, but I am still getting view errors when hovering over the ProcessFlow window:

exception: Exception caught in TreeNode::callMemberFunction() main function. Throwing... 
exception: FlexScript exception: Exception caught in TreeNode::callMemberFunction() c++/dll execution. Throwing...  at VIEW:/active/MainPanel/BackPanel/SplitterXPane/SplitterYPane/SplitterXPane/TabPane~2/TabControl/ProcessFlow>eventfunctions/OnDraw c: VIEW:/active/MainPanel/BackPanel/SplitterXPane/SplitterYPane/SplitterXPane/TabPane~2/TabControl/ProcessFlow


0 Likes 0 ·
Jordan Johnson avatar image
2 Likes"
Jordan Johnson answered

Short answer: FlexSim doesn't support building Process Flow logic through code.

For this case, it feels like a List is a better solution than hundreds of Resource blocks. Here's why:

  • A List can do everything a Resource can do and more. In many cases, Resources actually use a List under the hood anyways.
  • A List block in Process Flow can reference a Global List. Global Lists are easy to access and manipulate through code. Each process flow only needs one List block, so not much repetition there. All your push/pull activities can reference that single block.
  • You can use code to create 3D objects and push them to a Global List.
  • You can partition a list. Even if you're handling hundreds of resource types, you can use partition values (such as type) to split a single list into as many categories as you need. Just push or pull to the proper partition values, and the List will make sure those partitions exist.
  • You can query a list. With many resources, you need to filter or sort the possible resources, beyond the initial partition filter. You can write queries with WHERE and ORDER BY statements to get the best resource in each case.

With all those features, you can use a Global List to manage as many resources as you need. In the HC version of FlexSim, we use four global lists to manage resources: Staff, Locations, Transports, and Equipment. The user then (essentially) pushes and pulls from those lists. The people module provides special activities that are essentially push/pull from list activities in disguise.

So at the end of the day, I'd say standardize on certain Global Table formats/names. Then write code that:

  • looks for those tables with those names
  • creates the resources (the 3D objects) using locations and quantities specified by the tables
  • makes special lists if they don't already exist
  • pushes those resources to the correct partitions on the correct list

Then, you just have to acquire and release the correct resource using Pull From List and Push To List activities.

I know that's a lot of steps with a bunch of details that matter a lot. However, if you are managing hundreds of resources, that's a complicated task no matter how you try to approach it. This approach is designed to reduce repetition, but it can't remove the fundamental complexity of the problem you are trying to solve.

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
1 Like"
Jason Lightfoot answered Tom S4 commented

If you have a complex network of connected activities (hundred or thousands) with precedence/successor data then it makes sense that you might want to import and auto-generate delay/task activities. While that's not strictly supported it is possible for some activity types. From my experience that does not include the Resource type.

But if your goal is to avoid repetitive tasks in creating your process flows then that suggests that your design may not be taking advantage the ability to define the activities and resources generically and from within Object Process Flows (tutorial here). You may also want to take advantage of the ability to create 3D cells of functionality with internal references that correctly update with copy/paste actions - or to have them managed through templates.

The example in the comment of this post shows using pointer labels (and array labels) in an object process flow where the decision point is the member/attached instance of the flow, and how easy that is to scale once defined generically.

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

Tom S4 avatar image Tom S4 commented ·

Unfortunately I can't find a way to use these ideas in my work. Our models have very different processes/objectives/approaches for each of our clients, and there doesn't seem to be a ton of standardization opportunities between these projects. One approach we frequently employ is using PF as the primary model and linking resources to dummy objects to capture utilization, which is why I was looking to automate the creation of said resources.

I've used Object Process Flows before, but there doesn't seem to be a good application for my purposes to automatically link the resources to each object instance, as I would need a feasible way to reference each resource in a General Process Flow (referencing the resource in each object instance seems like it would be more effort on the back-end) . Additionally, I would like to avoid major deviations from our typical approaches as to not have to train my team on other FS features they don't typically use (custom library, object PF's, etc.)

The approach I ended up taking was manually creating the resources in a container. It isn't too difficult to drop in ~10 or so, and copy those until we have the appropriate number. My code then references the resources in the container, creates objects, names everything, links them together, positions them, etc. (see below for result). Hopefully there will be added functionality in the future to automatically create the resources.

0 Likes 0 ·