Imports Rhino Imports Rhino.Commands Imports Rhino.DocObjects Namespace TestRhinoCommonVb Public Class TestVbMatthieu Inherits Command ''' ''' Gets the command name. ''' Public Overrides ReadOnly Property EnglishName() As String Get Return "TestVbMatthieu" End Get End Property ''' ''' Call by Rhino to run this command. ''' Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result ' Filter for instance definition objects Dim filter As New ObjectEnumeratorSettings With { .NormalObjects = False, .LockedObjects = False, .HiddenObjects = False, .IdefObjects = True, .ActiveObjects = True } ' Find all instance definition objects Dim rh_objects As RhinoObject() = doc.Objects.FindByFilter(filter) ' For each instance definition object... For Each rh_obj In rh_objects ' ...find the owning instance definition id Dim idef_id As Guid = FindInstanceObjectOwnerId(doc, rh_obj.Id) ' Find the instance definition object Dim idef As InstanceDefinition = doc.InstanceDefinitions.FindId(idef_id) ' Print something helpful If IsNothing(idef) Then RhinoApp.WriteLine("{0} is owned by ", rh_obj.Id) Else RhinoApp.WriteLine("{0} is owned by {1}", rh_obj.Id, idef.Name) End If Next Return Result.Success End Function ''' ''' Given an instance definition object's id, find the owning instance definition. ''' ''' The active document. ''' The id of the instance definition object. ''' The id of the instance definition. Protected Function FindInstanceObjectOwnerId(ByVal doc As RhinoDoc, ByVal objectId As Guid) As Guid If Not IsNothing(doc) Then For Each idef In doc.InstanceDefinitions For Each rh_obj In idef.GetObjects() If rh_obj.Id = objectId Then Return idef.Id End If Next Next End If End Function End Class End Namespace