Grasshopper

algorithmic modeling for Rhino

How to test if a document object is inherited from IGH_Component interface?

I am iteratign through all document objects on the canvas.

I only want to interrogate objects which are compoennts i.e. they inherit the IGH_Component interface. For insatnce I dont wnat to interrogate string panels or color swatches

Is there a quick way of determining is this is true other than iterating throught teh collection and doing a try catch for each object when trying to convert to the interface?

i.e.

Dim ghObjects As New List(Of Grasshopper.Kernel.IGH_DocumentObject)
Dim ghDocument As Grasshopper.Kernel.GH_Document = GH_InstanceServer.ActiveCanvas.Document
ghObjects = ghDocument.Objects

For each ghObject in ghobjects

try

Ctype(ghobject, Grasshopper.Kernel.IGH_Component)

catch

etc etc etc

cheers

Views: 416

Replies to This Discussion

If (TypeOf ghObject Is IGH_Component) Then

  ...

End If

or

Dim ghComponent As IGH_Component = TryCast(ghObject, IGH_Component)

If (ghComponent IsNot Nothing) Then

  ...

End If

Don't use CType() by the way. If you're casting to types you're better of using TryCast() and DirectCast().

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Ah, thank you very much Mr Rutten

 

Steve

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