Grasshopper

algorithmic modeling for Rhino

Dear all,
I have a small problem with calling Rhino commands into GH through VBScript components (the commands are Rhino.GetUserText and Rhino.SetUserText).
The main goal of my application would be an automatic filling process of additional information to 3D geometry (for interoperability purposes).
Searching information I found this discussion:


...where Vicente Soler suggests a simple method which calls a command from Rhino into GH. I discovered, talking with Vicente that now the language to use is RhinoCommons but I didn't still reached a solution, being a dummie for scripting.

Does anybody can help me with this problem?

Here's the code that I'm trying to implement (it is written in RhinoScript actually):

Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByVal z As Object, ByVal idObject As Object, ByRef A As Object) 
    Dim sIfcType, strObject
    Dim strIfcColumn, strIfcBeam

    sIfcType = Rhino.GetUserText(idObject, "TypeObjetIFC")

    If ((sIfcType = "IfcBeam") Or (sIfcType = "IfcColumn")) Then

      'MsgBox "median = " & y & ", min = " & x& ", max =" & z

      Rhino.SetUserText(idObject, "Longueur", z)
      Rhino.SetUserText(idObject, "Largeur", x)
      Rhino.SetUserText(idObject, "Hauteur", y)
      
    End If
  End Sub 


I just would like to add extra-information to a selected list of 3D geometries by managing the UserText data.

Thanking you in advance for your attention I'll wait for an your answer about this theme.
Sincerely,

Matteo

Views: 834

Replies to This Discussion

In Rhinocommon, it goes something like this:

Private Sub RunScript(ByVal x As Guid, ByVal y As Object, ByRef A As Object)

Dim obj As New docobjects.ObjRef(x)
Dim att As docobjects.ObjectAttributes = obj.Object.attributes
Dim str As String = att.GetUserString("key")
att.SetUserString("key", str & "!")
doc.Objects.ModifyAttributes(obj, att, False)

End Sub

You have to use the ID parameter to get the GUID of the referenced objects. So, if you are referencing say breps, you'll have the brep parameter with the referenced breps connected to an ID parameter and the ID parameter connected to the VB.NET scripting component (in this case to the x input).
I haven't checked to see if this works, but your code should look something like this:

Dim obj As New docobjects.ObjRef(id)
Dim att As docobjects.ObjectAttributes = obj.Object.attributes

Dim sIfcType As String = att.GetUserString("TypeObjetIFC")
If ((sIfcType = "IfcBeam") Or (sIfcType = "IfcColumn")) Then

'MsgBox "median = " & y & ", min = " & x& ", max =" & z
att.SetUserString("Longueur", z)
att.SetUserString("Largeur", x)
att.SetUserString("Hauteur", y)

End If
doc.Objects.ModifyAttributes(obj, att, False)

I renamed the first input from x to id, since you have another x input.
Thank you very much Vicente. I didn't ask you directly a practical help in order to don't disturb you so much. Happy to see that you are the first to answer. :-)
I'll check the script and then get back for a feedback.
Thank you again!
M
Vicente, I tryed to put the script into the definition as VBScript component but it doesn't change the geometry's carachteristics.

Sometimes there's an error message which appears on line 84, linked to the definition of a New element. I'm going to share the Rhino+GH files, if you have another bit of time to look into 'em.
Thank you in advance for your attention.
M
Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service