Jump to content
Developer Wiki and Function Reference Links ×

If node passes value despite False test


Recommended Posts

Hi,

I have a question about the If node. In my example, somehow If node passes through an object despite the fact the Boolean condition is False. This network should work "if condition is True then create an extrusion and move it to the right, if condition is False do nothing".

As a result if value is True, indeed it creates an extrusion and moves an object (Green in the picture). If value is False, "IF" node returns "0", but later extrusion sees base rectangle and passes it through, but not performing extrusion and then moves rectangle (RED in the picture).

 

Anyone has an idea why IF node works like this?

File is VW2023.

If node query.jpg

test_if_hk.vwx

Link to comment

Hello,

 

i think this is due to a flaw inside the "Extrude" node and not the "If" node.

In short, the "Extrude" node uses a function that returns the last created object. Normaly this would give you the handle to the newly created extrusion. However, if you have no input value in "hObj" the node wont create an extrusion. But the function that returns the last created object will still return the last created object. In that case this is a group that gets created by the "Create Rectangle" node automaticaly. And that is why you have some strange, unexpected output to the "Extrude" node.

 

Here are some ideas to fix this:

  • Fix the code of the "Extrude" node in a way that the "problematic" part of the node is not run, if there is no input value in "hObj". For the code of such a node please see the code i provided below.

@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
#APPEARANCE
	#Name
	this = Marionette.Node( "Extrude" ) 
	this.SetDescription('Extrudes a 2D profile from a bottom Z value to a top Z value') 

	#Input Ports
	profile = Marionette.PortIn( vs.Handle(0), 'hObj' )
	profile.SetDescription('The 2D object to extrude')
	top = Marionette.PortIn( 5, 'nTop' )
	top.SetDescription('The Z value of the top of the resulting extrusion')
	bottom = Marionette.PortIn( 0, 'nBot' )	
	bottom.SetDescription('The Z value of the bottom of the resulting extrusion')

	#OIP Controls

	#Output Ports
	xtrds = Marionette.PortOut('hObj')
	xtrds.SetDescription('The resulting extrusion')

#BEHAVIOR
	this.SetLinksObjects()

def RunNode(self):
	#inputs
	prof = self.Params.profile.value
	top = self.Params.top.value
	bottom = self.Params.bottom.value

	#script
	extr = vs.Handle(0)
	if prof != vs.Handle(0):
		vs.BeginXtrd(bottom, top)
		vs.CreateDuplicateObject(prof, vs.Handle(0))
		vs.EndXtrd() 
		extr = vs.LNewObj() 
		(ok, start, rotX, rotY, rotZ) = vs.GetEntityMatrix(prof)			
		vs.Marionette_DisposeObj(prof)	
		vs.SetEntityMatrix(extr, start, rotX, rotY, rotZ)

	#outputs
	self.Params.xtrds.value = extr

 

  • Place the "If" node somewhere after the extrusion, so that you always create the extrusion and move it arround and so on. Than you delete it and make a duplicate of the extrusion only if the condition is true. This takes advantage of the fact that the "Delete" node kind of only deletes objects at the very end of the Marionette network, no matter where they are put in the Marionette network. And here is how this Marionette could look like:

grafik.thumb.png.80bf4acf3d16b7130ce8044532907e60.png

 

 

Regards,

Letti

Edited by Letti R
Link to comment

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.

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

×
×
  • Create New...