Grasshopper

algorithmic modeling for Rhino

if I have a vb.net script in which i say

dim newgmtry as new OnSurface

and

doc.AddSurfaceObject(newgmtry, att)

(where att=the name of the geometry)

Can I change the script using string inputs to say:

dim newgmtry as new OnCurve

and

doc.AddCurveObject(newgmtry, att)

using a string input to the VB.net component?

can OnSurface, OnCurve and AddSurfaceObject and AddCurveObject be string variables?

I have added a screenshot to illustrate what I would like to do.

Thanks in advance

Views: 234

Attachments:

Replies to This Discussion

attached is a slightly better picture.
Essentially the question is whether or not the scripting component can read string inputs as portions of the script. Can the contents of a string variable be transformed into a part of the script itself?

ScreenHunter_02 Nov. 05 17.23.jpg
Hi Benjamin,

There is no way I could think of where you can do that, but if I understood your question right, you want your code to dynamically cast input and add the right object with some attribute.

If this is true, then the following code can get you started. You obviously can add your attributes to the object as well:

Private Sub RunScript(ByVal x As OnGeometry)

If( x.ObjectType() = RMA.OpenNURBS.IOn.object_type.curve_object ) Then
' Debug string
Print("Object is a curve")

' Cast object to brep type
Dim crv As OnCurve = OnCurve.Cast(x)
'Dim new_crv As OnCurve = input_crv.DuplicateCurve()

' Since a copy of the object is passed to the VB component, you can add it
' without creating a duplicate instance
doc.AddCurveObject(crv)

Else If ( x.ObjectType() = RMA.OpenNURBS.IOn.object_type.brep_object) Then
' Debug string
Print("Object is a brep")

' Cast object to brep type
Dim brep As OnBrep = OnBrep.Cast(x)

' Since a copy of the object is passed to the VB component, you can add it
' without creating a duplicate instance
doc.AddBrepObject(brep)

End If

End Sub
Thank you very much Rajaa! That is basically what I was looking for, and it is plenty to get me started. It is excellent.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service