Grzegorz Krzemien Posted October 24, 2023 Share Posted October 24, 2023 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. test_if_hk.vwx Quote Link to comment
Letti R Posted October 24, 2023 Share Posted October 24, 2023 (edited) 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: Regards, Letti Edited October 24, 2023 by Letti R Quote Link to comment
Grzegorz Krzemien Posted October 25, 2023 Author Share Posted October 25, 2023 Thanks @Letti R for your answer. Unfortunately, this is a simplified example of much bigger network, so the idea of changing the Extrude node is not the best option, either relocating the If node. Quote Link to comment
Recommended Posts
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.