algorithmic modeling for Rhino
The file I'm working with is really messy, so I don't think it will help to post it here. Instead I'll do my best to describe my issue (hopefully it wont be too terrible).
Ok, so I have been slowly assimilating components from a large definition into a single custom scripted component (eventually to be made into a GHA).
As of now I have 6 identical components in a chain (one after the other) which have several inputs and outputs. Some inputs are from the same user-defined sources and some are outputs from the previous component in the chain. My goal was to combine them all into a single scripted component - which I've done - but the amount of time it takes to process the solution is huge (compared to having them all chained in a row).
When chained, each component only take 50 or 60 ms to compute (300-360 ms total). When all crammed into one component, it can take several seconds (this also depends on the amount of inputs, though).
My theory is that I've just done something less efficient / more stupid than the best scripting practices would call for (since it's a relatively new realm for me) - So this is what I ask: Is there a better way to script what I have scripted? I don't want to complicate things by posting my few hundred lines of code, so I'll simplify:
To combine these previously disparate scripted components, I:
Create a class with various properties: (I am using a class because I have several data types -planes, points, numbers- that I want to output as the result of a function)
Class exampleClass
public aProp
public bProp
public cProp
etc...
create a function with 6 inputs (which is basically exactly the same as a single scripted component):
exampleFunction(a,b,c,d,e,f)
inside the function solve for 6 variables based on inputs
aVar = some math
bVar = some more math
cVar = even more math
etc...
At the end of the function create an instance of exampleClass (and set properties equal to variables solved for in the function)
classInstance = exampleClass
classInstance.aProp = aVar
classInstance.bProp = bVar
classInstance.bProp = bVar
etc...
Finally set the return value of the function equal to the instance of the class
exampleFunction = classInstance
So that's the setup. Now I want to run the function 6 times so I do something like:
dim funtion01 = exampleFunction(a0,b0,c0,d0,e0,f0)
dim funtion02 = exampleFunction(a1,b1,c1,d1,e1,f1)
dim funtion03 = exampleFunction(a2,b2,c2,d2,e2,f2)
dim funtion04 = exampleFunction(a3,b3,c3,d3,e3,f3)
dim funtion05 = exampleFunction(a4,b4,c4,d4,e4,f4)
dim funtion06 = exampleFunction(a5,b5,c5,d5,e5,f5)
So that's it. Now I can access any of the results from any of the 6 functions.
This works exactly the way I'd like it to, but it takes many times longer to calculate than when this whole script is broken up into separate components (360 ms total vs. 3.4 seconds in one script).
Any ideas why this may be? Should I do something different to achieve the same desired result?
Thanks in advance, I hope that wasn't overly confusing.
-Brian Harms
Tags:
Since the return of the function is an instance of a class (let's say, customClass) that has different properties:
i.e.
classInstance.angle (which would be Doubles)
classInstance.curPlns (which would be Planes)
classInstance.Pts (which would be points)
etc.
How should I define the return type?
Public Function SomeName(ByVal arg0 As SomeType) As customClass?
By the way I really appreciate the help.
Brian
Yes, your function should specifically return the typename of your class, which I think is jointClass in this case right? So:
Function Name(...) As jointClass
--
David Rutten
david@mcneel.com
Poprad, Slovakia
It should probably be:
Public ReadOnly curPins As New List(Of Plane)
that way you can always be certain it is not null. However the ReadOnly keyword is optional and might not be a good idea depending on how you plan to provide those planes.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Ok great - I will try all of this as soon as I get home.
Again, many thanks.
-Brian
After making those changes I successfully got the function + class component down to within a few milliseconds of the non-function non-class component.
Thanks a lot for your help (and time!)
-Brian Harms
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by