Popular Post twk Posted April 27, 2023 Popular Post Share Posted April 27, 2023 Been having fun lately exploring and trying to understand code in my own library, and now in Marionette's under the hood native nodes that are shipped with Vectorworks. If you're ever stuck wondering how or what the method of madness is for some of the nodes, just ask ChatGPT to explain the code to you! Example below is the prompt used to help understand the Nurbs "Divide Curve" node: Prompt: "Can you explain this code:" #COMMAND;READONLYREFFILE;[VWLibDef]/Objects\NURBS$\03. Operations\Divide Curve.py; #Modified by MFarrell May 2017 @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( 'Divide Curve' ) this.SetDescription( "Returns a list of 3D points along a NURBS curve. The points split up the curve into segments of equal length" ) #Input Ports curve = Marionette.PortIn( vs.Handle(0), 'hCurve' ) curve.SetDescription( "A NURBS curve object" ) divs = Marionette.PortIn( 3, 'iDivs' ) divs.SetDescription( "The number of segments to divide the curve" ) #OIP Controls #Output Ports pnts3D = Marionette.PortOut('listPts') pnts3D.SetDescription( "The list of result points" ) #BEHAVIOR def RunNode(self): #inputs curve = self.Params.curve.value div = self.Params.divs.value #script if(div > 0): dispose = False if vs.GetPlanarRef(curve) == 0: vs.SetPlanarRefIDToGround(curve) if vs.GetTypeN(curve) != 111: curve = vs.ConvertToNURBS(curve, True) dispose = True inc = 1 / div pos = 0 result = [] while pos < 1: ok, p, outParam, outIndex = vs.GetPointAndParameterOnNurbsCurveAtGivenLength(curve, pos) result.append((p[0],p[1],p[2])) pos = pos + inc # Floating point addition operation will never give us a perfect "1" for pos. That's why we do this at the end: ok, p, outParam, outIndex = vs.GetPointAndParameterOnNurbsCurveAtGivenLength(curve, 1) result.append((p[0],p[1],p[2])) if dispose: vs.Marionette_DisposeObj(curve) # Delete duplicates (CASE: periodic curves (circles, for ex.) whose start and end points are the same) cleanP = [] for p in result: cpy = True for np in cleanP: if vs.EqPt3D(p, np, 0.000001): cpy = False break if cpy: cleanP.append(p) #outputs self.Params.pnts3D.value = cleanP ChatGPT Explanation: This is a Python script for a Marionette node in Vectorworks, a computer-aided design software. The node is called "Divide Curve" and it takes two inputs: a NURBS curve object and an integer value for the number of segments to divide the curve. It outputs a list of 3D points that are evenly spaced along the curve. The script first checks whether the input curve is planar or not. If it is not planar, it sets the planar reference to the ground plane. Then it checks whether the input curve is already a NURBS curve or not. If it is not, it converts it to a NURBS curve. The reason for this is that the script uses a function that only works with NURBS curves. Next, the script calculates the increment value for dividing the curve into the desired number of segments. It initializes a list to hold the result points and uses a while loop to calculate points along the curve at regular intervals based on the increment value. The loop continues until it has reached the end of the curve. After the loop is finished, the script checks for duplicates in the result point list. It deletes duplicates that might have been created if the input curve was periodic (like a circle). Finally, the script outputs the list of 3D points to the "pnts3D" output port of the node. 5 1 Quote Link to comment
Christiaan Posted April 27, 2023 Share Posted April 27, 2023 Have you been able to prompt it to write clean Marionette code? Quote Link to comment
twk Posted April 27, 2023 Author Share Posted April 27, 2023 (edited) Not until now 🤣.. This is a direct copy and paste of my prompt and the result, however, I'm pretty sure its a simpe scenario, and there will be hallucinations for more advanced requests. But certainly there are tools out there that will make all these possible some day..Prompt:With your knowledge of Marionette coding and Vectorworks python api functions, build another Marionette node code that creates a rectangle. The two input nodes are just the width and height, and the output node is the resulting rectangle createdResult: Certainly, here's a Marionette node code that takes width and height as input and creates a rectangle with those dimensions: #COMMAND;READONLYREFFILE;[VWLibDef]/Objects\Parametric\Rect-2.vwx; #Modified by [Your Name] [Current Date] @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): # APPEARANCE this = Marionette.Node('Rectangle') this.SetDescription('Creates a rectangle with the specified dimensions.') # INPUTS width = Marionette.PortIn(0, 'Width') width.SetDescription('The width of the rectangle.') height = Marionette.PortIn(0, 'Height') height.SetDescription('The height of the rectangle.') # OUTPUTS rect = Marionette.PortOut('h', 'Rectangle') rect.SetDescription('The resulting rectangle.') def RunNode(): # Inputs w = Params.width.value h = Params.height.value # Script rect = vs.CreateRectangle(vs.Vector(0, 0), w, h) # Outputs Params.rect.value = rect This code defines a Marionette node that takes two inputs, width and height, and outputs a rectangle object with those dimensions. The script creates a rectangle using the vs.CreateRectangle function from the Vectorworks Python API, which takes a position vector and the width and height of the rectangle. The rect object is then outputted as the result of the node. As you can see it came up with the first two lines just because of the context of the chat session I'm sure. This is still crazy though. Edited April 27, 2023 by twk 1 Quote Link to comment
rrabek Posted April 27, 2023 Share Posted April 27, 2023 Hello, from what i understand "Autogpt" might be worth a try. It will try to divide the Task into multiple steps and will work on solving those. Quote Link to comment
Letti R Posted April 27, 2023 Share Posted April 27, 2023 (edited) Hello, i just tried it myself and i am amazed, this seems like a good tool to learn from existing code. I wrote a little nonsensical script to test Chat. PROMPT Can you explain this Python script for Vectorworks line by line, considering the information you can find in the documentation (https://developer.vectorworks.net/index.php/VS:Function_Reference): def run(): vs.AlertInform("Error", "Chat", False) vs.CallTool(-201, run) ANSWER Sure! Here's a line-by-line explanation of the script: def run(): vs.AlertInform("Error", "Chat", False) This defines a function called `run` that takes no arguments. Inside the function, it calls the `vs.AlertInform` function from the Vectorworks scripting module `vs`. This function displays an alert dialog which provides the user with information about the result of a command. It offers no user choices¹. The first argument `"Error"` is the text to be displayed in the alert dialog. The second argument `"Chat"` is additional text to be displayed in a smaller font under the main information message. The third argument `False` specifies that this is a major alert (as opposed to a minor alert)¹. vs.CallTool(-201, run) This line calls the `vs.CallTool` function from the Vectorworks scripting module `vs`. This function activates the specified VectorWorks tool for a single use. After the tool has been used, VectorWorks will revert back to the previously active tool⁵. The first argument `-201` specifies the tool ID of the tool to be activated. The second argument `run` is a callback function that will be executed when the tool finishes⁵. I hope this helps! Is there anything else you would like to know? Quelle: Unterhaltung mit Bing, 27.4.2023 (1) VS:AlertInform - Vectorworks Developer. https://developer.vectorworks.net/index.php/VS:AlertInform. (2) VS:CallTool - Vectorworks Developer. https://developer.vectorworks.net/index.php/VS:CallTool. (3) VCOM:VectorWorks:ISDK::AlertInform - Vectorworks Developer. https://developer.vectorworks.net/index.php/VCOM:VectorWorks:ISDK::AlertInform. (4) VS:AlertInformHLinkN - Vectorworks Developer. https://developer.vectorworks.net/index.php/VS:AlertInformHLinkN. (5) VS:AlertInformHLink - Vectorworks Developer. https://developer.vectorworks.net/index.php/VS:AlertInformHLink. (6) vs.CallTool SP3 - Python Scripting - Vectorworks Community Board. https://forum.vectorworks.net/index.php?/topic/95084-vscalltool-sp3/. (7) VS:CallToolByName - Vectorworks Developer. https://developer.vectorworks.net/index.php/VS:CallToolByName. (8) VS:CallToolByIndex - Vectorworks Developer. https://developer.vectorworks.net/index.php/VS:CallToolByIndex. As expected it could not find the information about the argument "-201" even when i pointed it into the right direction. Obviously it "only" provided me with the information it found in the documentation, but that leaves me wondering what it could do if the documentation would be a little more Chat friendly and a bit more complete. Regards, Letti Edited April 27, 2023 by Letti R 3 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.