# Letti R

Member

57

48 Great

• Location
Germany

## Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

1. ## Confused on how Pop Front / Pop Back / Rotate / etc. can be used to repeat actions

Hello @ASag I think Marionette and a little bit of programming go very well together, however for most things you dont need to write nodes / code on your own. In my answers i usually try to show multiple ways on achieving a set goal (because there often is not just one "correct" way on how to do stuff), so that you can choose the solution that suits you best. Me neither. Actually it was Marionette that got me into learning how to program. Regards, Letti
2. ## Confused on how Pop Front / Pop Back / Rotate / etc. can be used to repeat actions

Hello, your example reminds me of a problem @DomC posted some years ago. You can solve it by using the node "add sequence". But i would never recommend solving this kind of problems like this. It is a much better solution to just write your own node with a little bit of Python. For comparison, creating the Marionette (even though i had a rough idea of the solution) took me some hours. Writing the solution in Python code took me less than 10 minutes (it is just 3 lines of code). Here is what you want to do to create the Marionette: Sort the data. In this case the data is already sorted, so i skipped this part. If you need to sort your data you can write the id and the area of the object into tuples via the "Point 2D" node and then just sort the resulting list. Use the "add sequence" node on the list with the values. "add sequence" works like this: If you for example enter a list like [1,2,3,4] it will return this list [1,3,6,10] where each value is the sum of all values that came before. This means that the sums you want to calculate are somewhere in this list, you just have to pick the right ones and than subtract the sum of all the sums that came before. To get the indices of the correct sum you can make a list with the occurances of the ids, subract 1 from the first item of the list (because indices are counted from 0) and then use "add sequence" on this list, you get the indices of the sums that you want to pick from the list that we calculated in 2. Now you have a list where the first value is the first sum, the second value is the first sum plus the second sum, the third value is the first sum plus the second sum plus the third sum and so on Now you have to create a list with the correct values that you have to subtract from the sums we just picked. To do that we rotate the list from 5. by -1 and set the first item of the list to 0. Like this you subtract nothing from the first sum we picked (because it already was correct), than you subtract the value of the first sum from the second sum, than the value of the first two sums from the third sum and so on. And here is a screenshot of this Marionette: And here is how i would do the same thing (but better) with some Python code when writing a custom Marionette node: @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'sum by id' ) this.SetDescription( 'sum by id' ) #Input Ports list_values_input = Marionette.PortIn( [] ) list_values_input.SetDescription('The values input list') list_ids_input = Marionette.PortIn( [] ) list_ids_input.SetDescription('The ids input list') #OIP Controls #Output Ports list_sums_values_output = Marionette.PortOut() list_sums_values_output.SetDescription('The sums list') list_sums_ids_output = Marionette.PortOut() list_sums_ids_output.SetDescription('The ids list') #BEHAVIOR this.SetListAbsorb() def RunNode(self): #inputs list_values = self.Params.list_values_input.value list_ids = self.Params.list_ids_input.value #script sums_dict = {} for id, value in zip(list_ids, list_values): sums_dict[id] = sums_dict.get(id, 0) + value #outputs self.Params.list_sums_values_output.value = list(sums_dict.values()) self.Params.list_sums_ids_output.value = list(sums_dict.keys()) (i know this is more than 3 lines of code, but the code that does something with the data is only between "#script" and "#outputs". Everything else ist just the node appearance and so on) Regards, Letti
3. ## Set All Attributes by Class (Including Texture)

Hello, @Pat Stanford i think so. Ofcourse Texture only Shows for 3d Objekts Regards, Letti
4. ## Set All Attributes by Class (Including Texture)

Hello, if your active class has set all the attributes as "set automatically by class" when you run the Marionette, than all created objects will be created in this class with all the Attributes of the class. Could this be a a solution for you? Regards, Letti

Hello, i dont know if this is a known issue or if im doing something wrong, but if i arrange some polygons that do not overlap, in a specific way and try to add them via the menu command or [ctrl] + [k], than some of them dissappear. If i try the same thing in vw23 nothing happnes (thats what i would expect). Regards, Letti
6. ## If node passes value despite False test

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
7. ## Change tool behaviour with mode bar.

Hello, so i finished my Plug-in. Now i want to put it in the Forums to share it (for free). Is there something i have to consider to not run into legal problems because i used the VW SDK, or can i just put it out there for others to use? Regards, Letti
8. ## GetFName not returning name properly?

Hello, line 3 in your script does not call (run) the function, but assigns the (whole) function to the variable "filename". it should work if you change line 3 to: filename = vs.GetFName() Like that you actually call (run) the function and therefore assign the return value of the function to the variable "filename". Regards, Letti
9. ## Simple Marionette to Plot British Standard Tree Shadows

Hello, what i forgot to write the last time is, that the last node / code i posted also works if the 3D part of the existing tree PIO is disabled. From my understanding (and im hoping someone will correct me if im wrong) Marionette Networks are not version specific if you only use the nodes that are provided from Vectorworks. Costum Python scripts (and therefore custom Marionette nodes) for Vectorworks should also not be strictly version specific, but i once had to change some parts in a custom script because it stopped working on the newer version. My guess ist you should be able to use this custom script / the custom nodes atleast for some versions. Regards, Letti
10. ## Simple Marionette to Plot British Standard Tree Shadows

Hello, @Marissa Farrell The problem with the 3D info is, that you can deactivate the 3D part of this PIO and than the 3D info will return a hight of 0. Which ofcourse is correct, but not what we need. @Michal Zarzecki I wrote my solution (as pointed out in my previous post) into a node. Please do some tests, if this node gives the correct results. I also added a "deviation angle" that you can set, if north is not "straight up". @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'draw_shadow_of_PIO_"Existing Tree"' ) this.SetDescription( 'draw_shadow_of_PIO_"Existing Tree"' ) #Input Ports obj_in = Marionette.PortIn( vs.Handle( 0 ), 'hObj' ) obj_in.SetDescription( "The input object" ) angle_in = Marionette.PortIn(0, 'nAng') angle_in.SetDescription( "The deviation angle, if north is not in y direction" ) #OIP Controls #Output Ports h_out = Marionette.PortOut('obj') h_out.SetDescription( "obj" ) #BEHAVIOR def RunNode(self): # INPUTS obj = self.Params.obj_in.value angle = self.Params.angle_in.value # FUNCTIONS def get_parametric_record_dict(handle): record_handle = vs.GetParametricRecord(handle) record_name = vs.GetName(record_handle) record_dict = {} field_number = 1 while vs.GetFldName(record_handle, field_number) != "": record_dict[vs.GetFldName(record_handle, field_number)] = vs.GetRField(handle, record_name, vs.GetFldName(record_handle, field_number)) field_number += 1 return(record_dict) def selection_to_handle(): handles = [] def callback_selection_to_handle(handle): handles.append(handle) vs.ForEachObject(callback_selection_to_handle, "(NOTINDLVP & NOTINREFDLVP & (VSEL=TRUE))") return(handles) # SCRIPT # only run script if the object is a PIO with the parametric record "Existing Tree" attached if vs.GetTypeN(obj) == 86: if vs.GetName(vs.GetParametricRecord(obj)) == "Existing Tree": # save unit info of document temp_style, temp_prec, temp_dimPrec, temp_format, temp_angPrec, temp_showMark, temp_dispFrac = vs.GetPrimaryUnitInfo() # set unit of document to mm and high precision and dont show unit mark vs.PrimaryUnits(7, 10, 10, 2, 7, False, False) # get PIO info center = vs.GetSymLoc(obj) height = float(get_parametric_record_dict(obj)["Height"]) # draw arc and lines and compose them vs.DSelectAll() drawn_ojects = [] vs.ArcByCenter(center[0], center[1], height, 135, -135) drawn_ojects.append(vs.LNewObj()) dir_vector_arc_start = vs.Ang2Vec(135, 1) vs.MoveTo(center) vs.LineTo((center[0] + dir_vector_arc_start[0] * height, center[1] + dir_vector_arc_start[1] * height)) drawn_ojects.append(vs.LNewObj()) vs.MoveTo(center) vs.LineTo((center[0] + height, center[1])) drawn_ojects.append(vs.LNewObj()) vs.DoMenuTextByName('Compose', 0) poly_line = selection_to_handle() if len(poly_line) != 1: for item in poly_line: vs.DelObject(item) output_object = None else: output_object = poly_line[0] # rotate polyline, to account for the fact that north is not always in direction (0, 1) vs.HRotate(output_object, center, angle) # set unit of document to what was seved before vs.PrimaryUnits(temp_style, temp_prec, temp_dimPrec, temp_format, temp_angPrec, temp_showMark, temp_dispFrac) # OUTPUTS self.Params.h_out.value = output_object Regards, Letti
11. ## Simple Marionette to Plot British Standard Tree Shadows

Hello, can you provide us with an example file with some of the trees aswell as the Marionette? Regards, Letti
12. ## Simple Marionette to Plot British Standard Tree Shadows

Hello @Michal Zarzecki, unfortunately i dont know how to get the values directly from the ET Plugin objects. However here is what i tried (with Python and Marionette combined), but i do NOT think that this is the correct way to do it: depending on how the PIO is built, you can maybe get the information from a datarecord that might be attached to the PIO. You can do this with the "Get Record Field" node. Therefore you will have to look up the name of the record and the name of the field. The problem here is, that the value you get from the record depends on the document units settings. Here are the problems: If you are reading the height value of a 49m tall tree with this method, while your document units are set to kilometers with a displayed precision of 1 (0.1), you will get 0km as the height of the tree, because the value its rounded down. The value is given as a string. If the document does not display the unit mark, this string can be easily turned into a float number with the "float()" function of Python, but not if the document does display the unit mark. I think i am missing something here, because i would assume vectorworks has a function to convert such strings into floats, but i have not found that function yet. So if i had to "solve" this now i wold do it like this (but i really hope someone else will show us the proper way of doing this): Get the current unit info of the document with the function "vs.GetPrimaryUnitInfo()" and "store" it Set the unit settings of the document to what is needed (mm, with high precision and dont show unit marks) with the function "vs.PrimaryUnits()" Read the data from the record and convert it to a float with the function "float()" Draw the arc and the lines and compose them Set the unit settings to what they were before I hope that someone else can provide you with a better idea and better information, because i am clearly way out of my depth here. Regards, Letti
13. ## Simple Marionette to Plot British Standard Tree Shadows

Hello, assuming your Tree is a 3D symbol and not a PIO, these steps might help: Regarding #1.: I think you can get the 3D height of your 3D symbol by subtracting the output "nBotz" from the output "nTopz" of the "Get 3D Info" Node. Unfortunately this Node seemes to be brocken (hopefully only on my computer). If not, here is the code for a custom node that only outputs the 3D height. To create the node, replace the code of any existing node, with the code below. @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'get 3D height' ) this.SetDescription( 'get 3D height' ) #Input Ports x = Marionette.PortIn( None, '3D Object' ) x.SetDescription( "3D Object" ) #OIP Controls #Output Ports y = Marionette.PortOut('n') y.SetDescription( "n" ) #BEHAVIOR def RunNode(self): #inputs x = self.Params.x.value #script _, __, n = vs.Get3DInfo(x) #outputs self.Params.y.value = n (please only use this, if the "Get 3D Info" node does not work). Regarding #3.: Given you have drawn the correct arc, you can than turn this into a closed polyline by drawing a line from the center point of the arc to the start point of the arc and another line from the center to the end point of the arc. To create a polyline from that just put the arc and the two lines into the "compose" node. And this is how this Marionette could look like: Regards, Letti
14. ## Issue with repeating substrings in "Strip" Node

Hello, you may want to use. string.removeprefix("") string.removesuffix("") These functions seem to do what you are searching for. A Marionette node with the functions above could look like this: @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( "remove suffix prefix" ) this.SetDescription('Removes the suffix or the prefix from the full string.') #Input Ports s = Marionette.PortIn( '', 's' ) s.SetDescription('The full string.') s2 = Marionette.PortIn( '', 'sSub') s2.SetDescription('The substring.') #OIP Controls pos = ['left', 'right', 'both'] position = Marionette.OIPControl( 'Position', Marionette.WidgetType.RadioButton, 0, pos) position.SetDescription('an OIP control representing the position options for where the string gets stripped.') #Output Ports outList = Marionette.PortOut('sNew') outList.SetDescription('The stripped string.') #BEHAVIOR def RunNode(self): #inputs s = self.Params.s.value s2 = self.Params.s2.value pos = self.Params.pos position = self.Params.position.value #script if pos[position] == 'left': sNew = s.removeprefix(s2) elif pos[position] == 'right': sNew = s.removesuffix(s2) elif pos[position] == 'both': sNew = s.removeprefix(s2).removesuffix(s2) #outputs self.Params.outList.value = sNew You can create the node by replacing the code of any Marionette node with the code above. Regards, Letti
15. ## Wrapping marionette script breaks outputs

Hello, to get the "vs.ResetBBox(h)" function within a Marionette node you can write the node with a bit of Python code by replacing the code in any node with the code below. @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'vs.ResetBBox(h)' ) this.SetDescription( 'vs.ResetBBox(h)' ) #Input Ports x = Marionette.PortIn( vs.Handle(0), 'h' ) x.SetDescription( "input" ) #OIP Controls #Output Ports y = Marionette.PortOut('h') y.SetDescription( "output" ) #BEHAVIOR #this.SetListAbsorb() def RunNode(self): #inputs x = self.Params.x.value #script vs.ResetBBox(x) #outputs self.Params.y.value = x Another way would be to create your own "node" by using the "function" node within a wrapper. Therefore you have to write the Python function "vs.ResetBBox(x)" into the OIP of the "function" node and wrap a small Marionette that looks like this: You can now use this wrapper like @DomC uses the "ResetBBox" node in his Marionette. Regards, Letti
×

• KBASE
• #### MARIONETTE

×
• Create New...