Jump to content

if condition to change the value of a planar/solid boolean


Raph

Recommended Posts

Hello everyone,

I would like to change the state of a planar/solid boolean depending on a condition.

More precisely, I would like to be able to remove or not a square to an existing volume. The condition is true or false.

I thought I could do this with an "if" by acting on the size of the square.
if true = 3mm
if false = 0mm

but it creates an error

Does anyone have a solution for me?

Thanks in advance

greetings

Raphael

image.thumb.png.4413704e3acf05c2d8284e2fb4305570.png

test Forum.vwx

Link to comment

Hi Pat,

 

Thank you for your answer.

Unfortunately, this postpones the problem to the next step. The next node is a planar boolean. But an empty boolean operation also creates an error.

Is it possible to create a planar boolean node with a configurable "add, sub, ..." input.

 

Has anyone ever created a node like this?

Link to comment

Hello,

 

i think the solution of @Pat Stanford is working when the "False" value of the "If" node is "vs.Handle(0)" (take a "Any" node and write "vs.Handle(0)" into it).

 

I tested it with 2 rectangles, my Marionette looks like this:

340862378_Bildschirmfoto2022-10-20um17_12_26.thumb.png.d9b23e29a7fad853d052b4fad9185045.png

 

I tried to find an explanation for this behaviour, but i think i will leave it to the experts ☺️

 

 

Regards,

Letti

Link to comment

Hi Letti,

 

Thanks for your reply.

 

unfortunately it doesn't work properly

it seems that the created surfaces don't really get deleted


Has anyone ever created a boolean node with an extra entry that would allow to act on the action of the boolean?

Add, substrac or intersection

 

Thanks in advance

Link to comment

Hi everyone,

 

I'm thinking about something like this...

but I don't know enough python to do it by myself yet

 

 

@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
#APPEARANCE
    #Name
    this = Marionette.Node( "Planar Boolean" )
    this.SetDescription('This node performs a boolean operation between lists of objects. The operation will be performed for each possible combination of objects in the lists supplied.')
    
    #Input Ports
    in0 = Marionette.PortIn( vs.Handle(0), 'hBlank' )
    in0.SetDescription('A list of objects to be operated on (blanks)')
    in1 = Marionette.PortIn( vs.Handle(0), 'hTool')
    in1.SetDescription('A list of objects to operate on "in0" with (tools)')
    in2 = Marionette.PortIn(vsHandle(0), 'hValue')
    in2.SetDescription('A list of operation _ 0=Add _ 1=Substract _ 2=Intersect')
    
    #OIP Controls
    op = Marionette.OIPControl( 'operation', Marionette.WidgetType.Popup, 0, ['Add', 'Subtract', 'Intersect'])
    op.SetDescription('The operation to perform between objects\n'
                        '   Add: equivalent to the "Add Surface" command in VW\n'
                        '   Subtract: equivalent to the "Subtract Surface" command in VW\n'
                        '   Intersect: equivalent to the "Intersect Surface" command in VW')
    
    #Output Ports
    out = Marionette.PortOut('hObj')
    out.SetDescription('The resulting objects')
    
#BEHAVIOR
    this.SetLinksObjects()
    this.SetListAbsorb()

def RunNode(self):
    #inputs
    in0 = self.Params.in0.value
    in1 = self.Params.in1.value
    in2 = self.Params.in2.value
    
    #script
    output = []        
    if type(in0) != list:        
        in0 = [in0]
    
    for blank in in0:        
        if blank != vs.Handle(0):
            if type(self.Params.in1.value) != list:
                in1 = [in1]
            for tool in in1:
                newObj = vs.Handle(0)                
                if tool != vs.Handle(0):
                    #Add
                    if self.Params.op.value == 0:    
                        newObj = vs.AddSurface(blank, tool)    # blank and tool will be deleted after this operation
                        if newObj != vs.Handle(0) and newObj != None and newObj != tool:
                            blank = newObj
                    
                    #Subtract        
                    elif self.Params.op.value == 1:                    
                        newObj = vs.ClipSurfaceN(blank, tool) # blank and tool won't be deleted after this operation
                        if newObj != vs.Handle(0) and newObj != None and newObj != tool:
                            vs.Marionette_DisposeObj(blank)
                            vs.Marionette_DisposeObj(tool)
                            blank = newObj

                    #Intersect
                    elif self.Params.op.value == 2:
                        newObj = vs.IntersectSurface(blank, tool) # blank and tool won't be removed after this opeartion
                        if newObj != vs.Handle(0) and newObj != None and newObj != tool:
                            vs.Marionette_DisposeObj(blank)
                            vs.Marionette_DisposeObj(tool)
                            blank = newObj
                                            
            while blank != vs.Handle(0):
                if self.Params.op.value in [1, 2]:
                    if blank != tool:
                        output.append(blank)
                else:
                    output.append(blank)
                blank = vs.NextObj(blank)
            
    #outputs
    self.Params.out.value = output

 

Link to comment

Hello,

 

unfortunately i cant figure out if your Marionette is working correctly, because it is quite complicated, but i think a simple "Delete" node right behind the "Rectangle" node could do the trick.

 

But i also wrote the node you were looking for, or at least i think so:


@Marionette.NodeDefinition
class Params(metaclass = Marionette.OrderedClass):
#APPEARANCE
	#Name
	this = Marionette.Node( "Planar Boolean" ) 
	this.SetDescription('This node performs a boolean operation between lists of objects. The operation will be performed for each possible combination of objects in the lists supplied.')
	
	#Input Ports
	in0 = Marionette.PortIn( vs.Handle(0), 'hBlank' )
	in0.SetDescription('A list of objects to be operated on (blanks)')
	
	in1 = Marionette.PortIn( vs.Handle(0), 'hTool')
	in1.SetDescription('A list of objects to operate on "in0" with (tools)') 
	
	n_action_in = Marionette.PortIn( 0, 'nAction' ) 
	n_action_in.SetDescription( '0 = Add, 1 = Subtract, 2 = Intersect' )
	
	#OIP Controls

	
	#Output Ports
	out = Marionette.PortOut('hObj')
	out.SetDescription('The resulting objects')
	
#BEHAVIOR
	this.SetLinksObjects()
	this.SetListAbsorb()

def RunNode(self):
	#inputs
	in0 = self.Params.in0.value
	in1 = self.Params.in1.value
	n_action = self.Params.n_action_in.value[0]
	
	#script
	output = []		
	if type(in0) != list:		
		in0 = [in0]
	
	for blank in in0:		
		if blank != vs.Handle(0):
			if type(self.Params.in1.value) != list:
				in1 = [in1]
			for tool in in1:
				newObj = vs.Handle(0)
				if tool != vs.Handle(0):
					#Add
					if n_action == 0:	
						newObj = vs.AddSurface(blank, tool)	# blank and tool will be deleted after this operation
						if newObj != vs.Handle(0) and newObj != None and newObj != tool:
							blank = newObj
					
					#Subtract		
					elif n_action == 1:					
						newObj = vs.ClipSurfaceN(blank, tool) # blank and tool won't be deleted after this operation
						if newObj != vs.Handle(0) and newObj != None and newObj != tool:
							vs.Marionette_DisposeObj(blank)
							vs.Marionette_DisposeObj(tool)
							blank = newObj

					#Intersect
					elif n_action == 2:
						newObj = vs.IntersectSurface(blank, tool) # blank and tool won't be removed after this opeartion
						if newObj != vs.Handle(0) and newObj != None and newObj != tool:
							vs.Marionette_DisposeObj(blank)
							vs.Marionette_DisposeObj(tool)
							blank = newObj
											
			while blank != vs.Handle(0):
				if n_action in [1, 2]:
					if blank != tool:
						output.append(blank)
				else:
					output.append(blank)
				blank = vs.NextObj(blank)
			
	#outputs
	self.Params.out.value = output

 

If you need, i could also add a "Do nothing"- action to this node, where the "hBlank" is put out of the node unchanged and the "hTool" object gets deleted?

 

Regards,

Letti

Link to comment

Hi Letti,

 

Thanks a lot for your complements and for the planar boolean node!

Your code works well and I also adapted it for a solid boolean.


So I tried the following two variations:

1. to put a "delete" after the rectangle

2. to put the planar boolean node with parameters


in fact both solutions created the same problems.

I realized that my approach was wrong.

Instead of working with a boolean node for each element to be subtracted/added, I need a boolean node and send only the shapes that need to be subtracted.


Sorry Letti, I didn't understand where the error came from.

 

attached is a printscreen of the working solution (with a single boolean planar node)😉

 

Best regards

 

Raph

image.thumb.png.6114b4b627c98b807e324a29b91d59cb.png

 

 

Edited by Raph
  • Like 1
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...