Jump to content

# "If" node question

## Recommended Posts

I have an object, a rectangle, that has shared characteristics from other elements but I only want it to exist if certain parameters are met. I linked the rectangle to the other elements that it is sharing its characteristics with and then linked the rectangle to an "if" node at the "true" link.

My issue is that even if the "if" node test is false the rectangle still appears. I assume it is because the rectangle shares its characteristics with other elements and that circumvents the "if" node.

Is there a way to have the "if" node control the existence of this type of rectangle?

The bottom "Wrapper" is the item I referring to. As you can see it is linked to other elements of the script as well as the "if" node.

Edited by Rassa12345
##### Link to comment

Hi,

Also have a question on IF. I have a test if A>=B then true, Draw circle, else (False) draw square.

Can you show the connections please. If I run it I get both.

Sorry for such a Noob Question but hey got to start somewhere.

##### Link to comment
• Vectorworks, Inc Employee

The If node is a little tricky in this way - it does not negate the true or false input, it only filters the information. For this: "I have a test if A>=B then true, Draw circle, else (False) draw square." For it to work, it would have to draw the square or circle AFTER the if node. If you send a circle into the false input and a square into the true input, it still draws them because they are part of the definition prior to the If node.

The way you could do this is if you connected the delete node to the output of the if, that way it would delete whichever object you choose.

The best way to use the If node is if you have two values that you want to choose from, not two objects. that was you could send one of two radii to a circle depending on the test - the other value still exists in the definition, but it is just not used to create anything.

I hope that explains it!

##### Link to comment

Yes, that's as far as I got.

But then recognizing that a circle with r=0 or square with b or h = 0 is not drawn then then using a pair of if statements works:

##### Link to comment
The If node is a little tricky in this way - it does not negate the true or false input, it only filters the information. For this: "I have a test if A>=B then true, Draw circle, else (False) draw square." For it to work, it would have to draw the square or circle AFTER the if node. If you send a circle into the false input and a square into the true input, it still draws them because they are part of the definition prior to the If node.

The way you could do this is if you connected the delete node to the output of the if, that way it would delete whichever object you choose.

The best way to use the If node is if you have two values that you want to choose from, not two objects. that was you could send one of two radii to a circle depending on the test - the other value still exists in the definition, but it is just not used to create anything.

I hope that explains it!

That does explain it. Thanks for clarifying. I will try the delete option and see if that works. I look forward to seeing Marionette become more robust!
##### Link to comment

Sbarrett,

Thanks you have explained it simple that is easily understood.

What I have so far it a script that creates a Kitchen cabinet and to set the cabinet width to have a say range from min 600mm to max 1500mm.

Max width of doors to be 750mm, so if the cabinet unit width is <=600mm draw 1 door and if > 600mm then draw 2 doors.

bcd, Love the Bool at the beginning. This is all about knowing what each of the nodes do so you can use them efficiently.

For a non programmer this is like starting to learn a new language.

Also it took me a while to figure out that your end result was an object and not a wrapper node. Once I figured out that you had to convert the wrapper node to an object the change was instant with the check box.

Thanks again

Edited by Alan Woodwell

Thanks

Edited by bcd
##### Link to comment

Nice Strike,

Mine is probably more like.

Edited by Alan Woodwell
##### Link to comment

nicely tempered: modesty & courage

##### Link to comment
• 2 months later...

The delete option works great as long as you have an object on both the true and false inputs. If you have an object only on one of the input nodes you will get error messages. The marionette will work but you'll get a popup error message when it runs.

##### Link to comment

Hello Nik,

Sorry if I missed something. Why should someone put values of a different type into the if-Node?

I hope it helps when you connect the delete-Node direct with the object node like in the attached example.

##### Link to comment

Hello,

Most of this is making sense, but my question is a little different. I'm using a bool node and "IF" node to allow the user to add an additional object or not. How does on go about drawing an object or NOT. I guess I am looking for an IF THEN statement??

Jeff

##### Link to comment

My issue isn't so much changing an object as it is, adding an object if conditions warrant.

##### Link to comment

This is what the IF node does.

If one condition is true do X, if false do Y and your test is if the criteria you set for change is met.

So if you want to add an object, if condition is true you place it on that side of the node.

HTH

Edited by Alan Woodwell
##### Link to comment

ok thanks, Alan, but what do i place for false.

It wants to see something, or errors pop up.

I don't want to draw anything for false

Jeff

##### Link to comment

I would expect that the marionette network in the attached file "Drawsboth" would draw a circle and not a square, when the boolean is true, but it draws both.

In order to draw one and not the other I can do one of the following:

1. Create "If" nodes that evaluates to a "0" if my Bool is true and feed that into radius/height.

2. Invert the logic of the boolean and add a delete node to the output

##### Link to comment

Hi,

You just need to place a delete at the end to delete the other object.

Not sure if one of the nodes should be changed so this step is no longer needed.

I think the "If" Node should have the delete issue resolved within it and not outside. Maybe someone can look at this and rewrite it. (outside my league)

HTH

Edited by Alan Woodwell
##### Link to comment

Alan/Nik,

Very nice, but I don't think that is what Jeff is looking for. Both of your will alternate between drawing a circle and a square while he is looking to always draw a circle and when Bool is true ALSO drawing the square.

I could not figure out a way to do this using the standard nodes, so I hacked together the If and Delete nodes to create a Boolean Delete. I had to do this in Python. But it only took about 4 added lines of code to the Delete node.

The Boolean Delete removed the object passed to it when the control signal (test) is true.

##### Link to comment
• Vectorworks, Inc Employee

Here is another way of making the If node work in the way you want it to without making any alterations to the code. It involves a few extra steps but it only draws the shape you choose and it gives you the output of the single drawn shape.

I love using the data nodes - there is so much you can do if you use them together.

There is also a definition that draws both object when true and one when false - if you run it as true it gives an error, but only because nothing is going to the delete node.

##### Link to comment

hey Pat you are close

What i am looking for is:

If bool is true draw the square

if bool is fals dont draw anything

Jeff

##### Link to comment

hey Pat you are close

What i am looking for is:

If bool is true draw the square

if bool is fals dont draw anything

Jeff

##### Link to comment
• Vectorworks, Inc Employee

Another way to make the If Node work a little better is to tweak the code a little. All you have to do is double click on the node, and change the Marionette.PortIn() values for the true and false inputs from 0 to None. This should make you network work the way you want it to.

@Marionette.NodeDefinition

class Params(metaclass = Marionette.OrderedClass):

this = Marionette.Node( 'If' )

this.SetDescription( 'If test is true, pass the value from true otherwise pass the value from false' )

true = Marionette.PortIn( None )

true.SetDescription( "An item" )

false = Marionette.PortIn( None )

false.SetDescription( "An item" )

##### Link to comment

worked great Sarah

Thanks again!

Jeff

##### Link to comment
• 3 months later...
Another way to make the If Node work a little better is to tweak the code a little. All you have to do is double click on the node, and change the Marionette.PortIn() values for the true and false inputs from 0 to None. This should make you network work the way you want it to.

@Marionette.NodeDefinition

class Params(metaclass = Marionette.OrderedClass):

this = Marionette.Node( 'If' )

this.SetDescription( 'If test is true, pass the value from true otherwise pass the value from false' )

true = Marionette.PortIn( None )

true.SetDescription( "An item" )

false = Marionette.PortIn( None )

false.SetDescription( "An item" )

Unfortunately this solution will also cause an error message to show up (Script Debug Mode is activated in programm settings.)

I modified the delete node to prevent it from running with None or zero value:

```@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
this = Marionette.Node( 'Delete' )
this.SetDescription('Deletes an object.\nNote: Objects to be deleted are saved in a list and are deleted at the end of the network execution. So, there is no risk of referencing an object that no longer exists')
obj = Marionette.PortIn( vs.Handle( 0 ) )
obj.SetDescription('The object to delete')

def RunNode(self):
obj = self.Params.obj.value
if (obj): vs.Marionette_DisposeObj (obj)

```

Edited by Patrick Winkler
##### Link to comment
• 6 months later...

Just ran into the kind of the same Problem as Jeff:

I'm new to Marionette and I tried to recreate the stick figure from the python examples in the developers wiki with Marionette. (http://developer.vectorworks.net/index.php/Python_Sample_Point_Object_(complex))

For this example the hair should only be drawn if the User checks a checkbox, so a boolean. But with the if-statement I get an error from my Line Node if the box is unchecked. So I tried a filter with a delete object at the false-items box. But now I get an error from the Delete object Node if the box is checked, because now it gets no input.

Now I'm not really comfortable fiddling around with the if Node. So, while modifying the delete node to work without input (or None-input or 0-input) might be an option, I wanted to ask if there is another solution for this in the new version (working with VW2017).

On 15.1.2016 at 6:41 PM, sbarrett said:

Here is another way of making the If node work in the way you want it to without making any alterations to the code. It involves a few extra steps but it only draws the shape you choose and it gives you the output of the single drawn shape.

I love using the data nodes - there is so much you can do if you use them together.

There is also a definition that draws both object when true and one when false - if you run it as true it gives an error, but only because nothing is going to the delete node.

Also, as I can't see any attachment to this post, there might already be a solution, but I'd like to know it. :-)

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• KBASE
• #### MARIONETTE

×
• Create New...