ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 03-05-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Red face Changing Object Shape - Simple Question

Hi,

I have a user command that creates a couple of objects in defined (x, y) positions, and once created I want to change their shape to cylinders (2nd image in the media list). I can't get it to work, and must be doing something stupid.

I am using the script window to test out the code before putting it in the user command.

At first i tried using the "setobjectshapeindex" command using the code below, but although it created a bulge in the visual tool, it wasn't set to a cylinder.
Code:
createinstance(node("/VisualTool",library()),model());
treenode mynode;
mynode = last(model());
setname(mynode, "MyName");
setobjectshapeindex(mynode,2);
Then i tried using a "setnodestr" command using the code below, but it didn't work either, although the shapes name appeared correct in the treeview.
Code:
createinstance(node("/VisualTool",library()),model());
treenode mynode;
mynode = last(model());
setname(mynode, "MyName2");
setnodestr(node("/MyName2>visual/shape", model()), "fs3d\General\Cylinder.3ds");
Then I tried combining both approaches, but that didn't work either.
Code:
createinstance(node("/VisualTool",library()),model());
treenode mynode;
mynode = last(model());
setname(mynode, "MyName2");
setnodestr(node("/MyName2>visual/shape", model()), "fs3d\General\Cylinder.3ds");
setobjectshapeindex(mynode, 2);
In this third piece of code, the variables shape and shapeindex appear exactly the same as a VisualTool with the image changed manually, but still it wasn't a cylinder.

I must be doing something wrong, and I apologise that it may be a stupid question, but how can I change the shape on the fly?

Please advise

Thanks
Brett
  #2  
Old 03-05-2013
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

The Visual Tool's "Visual Display" is set to plane. You aren't changing that. Your object is drawing a plane and the cylinder.

Also, '\' is an escape character within strings so your setnodestr() command isn't doing what it should be.

Here is some code that will be beneficial:

Code:
createinstance(node("/VisualTool",library()),model());
treenode mynode;
mynode = last(model());
setname(mynode, "MyName2");
setvarnum(mynode, "shapetypes", 5); // set "Visual Display" to "Imported Shape"
set(luminous(mynode),0); // turn off luminous
setsize(mynode,1,1,1);
setnodestr(node(">visual/shape", mynode), "fs3d\\General\\Cylinder.3ds");
setobjectshapeindex(mynode, 2);
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post:
Jörg Vogel (03-05-2013)
  #3  
Old 03-06-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Thumbs up Thanks but can you expand a little?

Thanks Phil, for the insight,

I like the code, as it makes a lot of sense. Whoops, I was doing several things stupidly

I assume this shapetypes variable is due to the VisualTool having special visual behaviour controlled in the Visual Display property box, which I'd completely missed.

I have a couple of small clarifications on some implications of your code, if you would elucidate:
- How does the luminosity impact the visual tool?
- I notice that you set the size first before getting the image. Is there are reason behind this order, or could you have had the set-size statement after getting the image?
- You use the setobjectshapeindex function last, is that because it triggers the shape change if you also have the other two variables set correctly?

Great answer though, it makes a lot of sense. I really like the Flexsim code, the underlying metaphor is coherently expressed and inherently flexibile, I just wish I could come to grips with it quicker

Thanks
  #4  
Old 03-06-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Red face Whoops, one further clarification on visualTools

Hi Phil,

If the VisualTool size is set to a small cylinder, can you still copy fixed resources inside (i.e. larger things) in code using CreateCopy(), if so, how are the x,y location values determined?

Do you then have to set the ContainerContents variable to 0 to hide the contents?

And once they're inside and hidden, can you still use ContextDragConnection between these inner objects and outside objects?

Or should you copy the objects inside the Visual Tool first,then set up the connections, hide the contents, and finally change the shape (i.e. is the order of instructions important when assumbling function clusters hidden inside Visual Tools)?

Finally, if your patience holds out, if I use DestroyObject on a VisualTool function cluster in the Reset Function, do the objects contained within also get destroyed, or do I need to destroy the contained objects first and then the VisualTool?

Thanks a lot for your insight on coding

Brett
  #5  
Old 03-06-2013
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

You can use switch_hidecontents(<object> [,0/1/-1]) to inspect and set the object property. Hiding the contents of the visual tool has no bearing on whether you can create or connect to objects inside it.

The size of the tool has no impact or constraint on what can be added. The locations should be set by you when you create them if that's important.

If you destroy an object in code, all the contained objects are destroyed.

If you connect an object the connections are maintained wherever you move it. Copying an object does not maintain connections that are outisde of the hierachy, but if you copy a visual tool that has connected objects inside, the connection between those objects are maintained.
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post:
Phil BoBo (03-06-2013)
  #6  
Old 03-06-2013
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Quote:
Originally Posted by brett forbes View Post
- How does the luminosity impact the visual tool?
Luminosity affects whether the object uses opengl lighting. A 'luminous' object gives off light so it is colored uniformly. A non-luminous object uses the opengl lights to draw a shadow gradient on the shape.

Quote:
Originally Posted by brett forbes View Post
- I notice that you set the size first before getting the image. Is there are reason behind this order, or could you have had the set-size statement after getting the image?
- You use the setobjectshapeindex function last, is that because it triggers the shape change if you also have the other two variables set correctly?
There isn't any particular reason for the order I put the commands. I don't think the order is going to affect anything.
The Following User Says Thank You to Phil BoBo For This Useful Post:
brett forbes (03-06-2013)
  #7  
Old 03-06-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Thumbs up Finally, whats the best way to set the section table of a pipe/conveyor?

Hi Phil and Jason,

Thanks for the clarification.

Its been really useful as I am writing a user command to draw a gas well at a given (x, y) location, with two hidden fluidgenerators (Methane, Water), a local water reservoir, complete with separate piping for water and methane that automatically connects up with a central plant and central reservoir.

I am doing this as a protptyping excercise to understand how to create this behaviour in an application. Once successful, I plan to post the code on the message board as a reply to one of my own forum questions, for use by the community, in respect for the excellent help provided. Its been a very interesting learning excercise.

One last question, concerning code-based layout of the section table in a pipe, or conveyor. I've had a good search, and can't seem to find a command to perform this.

What is the best way to go about modifying the section table of a pipe or conveyor in Flexscript?

Once this last piece of layout info is in place I can finish off the last bit of behaviour being modelled, and post an automated pipe layout user command.

Thanks for your invaluable help.

Cheers

Brett
  #8  
Old 03-07-2013
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

Quote:
What is the best way to go about modifying the section table of a pipe or conveyor in Flexscript?
You can just use table commands on the pipesections variable -accessed by getvarnode(<pipeobject>,"pipesections").
The Following User Says Thank You to Jason Lightfoot For This Useful Post:
brett forbes (03-07-2013)
  #9  
Old 03-25-2013
brett forbes brett forbes is offline
Flexsim User
 
Join Date: Oct 2011
Posts: 34
Downloads: 0
Uploads: 0
Thanks: 27
Thanked 3 Times in 2 Posts
Rep Power: 107
brett forbes is on a distinguished road
Thumbs up Problem Solved, see Tips and Tricks

Hi,

Thanks for the help above, it has enabled me to solve my own problem and I have posted a full description of how to achieve automated, realistic pipe layout in the Tips and Tricks section.

Thanks very much to Phil and Jason for the answers.

I hope this link below is persistant, if not you will have to use the menu to get there.

/threads/thread2457.html#post11436

Thanks

Brett

Tags
object shape


Thread Thread Starter Forum Replies Last Post
changing shape of a link Shahin Gelareh Q&A 8 06-06-2012 05:51 AM
Probably a simple question Jelmer Js Q&A 2 04-01-2011 06:29 AM
some question about 5.02 changing LINWEIXU Q&A 0 06-03-2010 02:07 AM
changing shape factor when changing 3d shape KelvinHo Q&A 3 09-03-2009 08:24 AM
Changing the color of a .3ds shape made with autocad Alexandre Ouellet Q&A 5 04-30-2008 08:48 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.