ATTENTIONThis 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 |
#1
|
|||
|
|||
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); Code:
createinstance(node("/VisualTool",library()),model()); treenode mynode; mynode = last(model()); setname(mynode, "MyName2"); setnodestr(node("/MyName2>visual/shape", model()), "fs3d\General\Cylinder.3ds"); 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); 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
|
||||
|
||||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
||||
|
||||
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:
|
The Following User Says Thank You to Phil BoBo For This Useful Post: | ||
brett forbes (03-06-2013) |
#7
|
|||
|
|||
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
|
|||
|
|||
Quote:
|
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
brett forbes (03-07-2013) |
#9
|
|||
|
|||
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 |