question

Chris Smith avatar image
2 Likes"
Chris Smith asked Ben Wilson edited

How can AStar Barriers be created in FlexScript?

I am trying to create a model that uses the AStar module from an excel file. I have some basic characteristics that would define the barriers in the model (location and size). Could someone help me understand the preferred method for creating AStar barriers in FlexScript? The way I am currently thinking about doing it is saving off a created Barrier as a node and then creating a copy of that and editing the x, y coordinates of the points. I just wanted to make sure there aren't any more preferred methods or commands to accomplish this.

Choose One
astarbarrier
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

·
Matt Long avatar image
6 Likes"
Matt Long answered Ben Wilson edited

The A* Navigator has functions on it that create barriers, dividers etc. For example, if you wanted to create a solid barrier that started at 0, 0 and ended at 10, 10 you would call:

function_s(node("AStarNavigator", model()), "addBarrier", 0, 0, 10, 10, EDITMODE_SOLID_BARRIER);

The dividers and preferred paths are a little more complicated, but here's an example of adding a divider with 3 legs:

treenode aStar = node("AStarNavigator", model());
treenode barrier = function_s(aStar, "addBarrier", 0, 0, 10, 10, EDITMODE_DIVIDER); //1st leg
function_s(aStar, "setBarrierMode", barrier, 3); //Editing barrier
function_s(aStar, "onClick", activedocumentnode(), LEFT_RELEASE, 10, 20); //2nd leg
function_s(aStar, "onClick", activedocumentnode(), LEFT_RELEASE, 20, 20); //3rd leg
function_s(aStar, "setBarrierMode", barrier, 0); //Done editing

The other edit modes are EDITMODE_ONE_WAY_DIVIDER and EDITMODE_PREFERRED_PATH.

Once you reset the model, all of the created barriers will be added to the network.

If you need to add objects as barriers or to the network, just use:

contextdragconnection(node("Operator1", model()), node("AStarNavigator", model()), "A");

Hope that helps.

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

jing.c avatar image jing.c commented ·

Hi, @Matt Long

I tried use it in Script to add a divider, but I found the last line in "adding a divider with 3 legs" will cause an "exception"

function_s(aStar, "setBarrierMode", 0); //Done editing

The system console will show:

exception: Exception caught in TreeNode::callMemberFunction() c++/dll execution. Throwing... MAIN:/project/library/astar/AStarNavigator>behaviour/eventfunctions/setBarrierMode c: /AStarNavigator thisClass: MAIN:/project/library/astar/AStarNavigator
exception: Exception caught in flexscript execution of <no path> line 6 instruction 33. Discontinuing execution.
exception: Exception caught in TreeNode::callMemberFunction() flexscript execution /0 c: /testlink_instance i: /testlink_associated theclass: /testlink_class

It looks like no difference and works well without that line of code, so I wonder what does it do.

0 Likes 0 ·
Matt Long avatar image Matt Long jing.c commented ·

Sorry, typo. It should be like the first call to setBarrierMode:

function_s(aStar, "setBarrierMode", barrier, 0);

The mode just tells the barrier what to do when the mouse is clicked. Passing in a 0 just ensures that we're done editing and no additional legs will be added.

EDIT: updated top answer with correct syntax.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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