question

Tom S4 avatar image
0 Likes"
Tom S4 asked Tom S4 commented

Create token and copy labels prior to activity start

I am developing a custom ProcessFlow activity (using the module SDK) which essentially incorporates a bunch of existing activities into one block - currently it's only inheriting from the Delay class. Among other things, something I would like to do is create a token from within this object. I want to also handle the case where the user needs the labels copied to the new token immediately after it is created. These are simplified versions of some attempts:

Next activity starts before label can be assigned:

Token* newToken = Token::create(origToken->instance()->ownerNode(), nextActivity, true);
createcopy(origToken->labels, newToken->labels, 1, 1, 0, 1);


Next activity never starts, and releasing the token skips the activity. I don't want users to have to worry about this caveat (e.g., having to create a dummy block):

Token* newToken = Token::create(origToken->instance()->ownerNode(), nextActivity, false);
createcopy(origToken->labels, newToken->labels, 1, 1, 0, 1);
releasetoken(newToken->holder, 0);


Also tried this but it errors out:

Token* newToken = Token::create(origToken->instance()->ownerNode(), nextActivity, false);
createcopy(origToken->labels, newToken->labels, 1, 1, 0, 1);
((Activity*)nextActivity)->start(newToken->instance(), *newToken);

I also looked into using CreateTokens::createTokens, (I don't know exactly how that works but I can do some trial and error), but that function is private and I couldn't seem to figure out how friend classes work. Ideally I would be able to just implement my own simpler version of what this method essentially does.

Thoughts? Thanks in advance.

FlexSim 23.0.1
processflowmodule sdkcreate tokens
· 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 ·

I guess I should also mention that I read the documentation for Token::create and it describes the same functionality as my first two examples above. (https://docs.flexsim.com/en/23.0/Reference/CodingInFlexSim/FlexScriptAPIReference/ProcessFlow/Token.html#Method-create)

Just wondering if there is a way around it using the SDK that may or may not be possible from within standard FlexScript.

0 Likes 0 ·

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Tom S4 commented

Call the start() method of the nextActivity instead of releasing the token.

TreeNode* nextActivity = evaluateNode(getvarnode(holder, "destination"), instance->ownerNode(), holder, token.holder);
Token* newToken = Token::create(instance->ownerNode(), nextActivity, false);
newToken->copyLabels(&token, false);
nextActivity->objectAs(Activity)->start(instance, *newToken);

If you want to use CreateTokens::createTokens then your activity needs to be a subclass of CreateTokens instead of Delay.

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

Tom S4 avatar image Tom S4 commented ·
Thanks, this worked. It looks like my issue in the 3rd example I provided was that I was casting the TreeNode* to Activity*, which throws an exception. Using objectAs(Activity) worked instead - unsure why this was the case but it solved my issue.
0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Tom S4 commented ·

In FlexScript, it is possible to "cast" a treenode to other types. But this is a convenience provided by FlexScript. In C++, a treenode holds data, and that data is what you need to cast to an Activity.

See the C++ TreeNode type reference:

https://docs.flexsim.com/en/23.0/Reference/DeveloperAdvancedUser/ModuleSDK/Reference/Types/TreeNode/TreeNode.html

0 Likes 0 ·
Tom S4 avatar image Tom S4 Jordan Johnson ♦♦ commented ·

Ah, thanks for the insight - that makes sense.

0 Likes 0 ·