Good evening,
I’m trying to read a user string from an object’s instance reference.
I’ve found rhinoobject.Attributes.IsInstanceDefinitionObject to check if the object belongs to a block, but I haven’t found a way to find said instanceObject.
I’ve tried looping though every blocks in the model but it is extremely slow and it needs recursivity because I my usertexts are stored on the higher level of instance objects.
An instance definition object does not have a back pointer to its owning instance definition. You’ll need to dig through each instance definition’s object list to find which one owns the object.
Sounds like another important feature missing from Rhino’s “not ready for prime time” block support. The vibe I get from this forum is that there’s plenty of Rhino users who want the real thing.
Hi @lando.schumpich,
Thank you for helping.
I am working on RhinoObjects gotten from a custom DisplayConduit.
In the overriden sub PreDrawObject(), e.RhinoObject gives me the model objects, but when they are sub objects of a block instance I need to read the block instance usertexts instead of the object usertexts.
Hi @dale,
I’ve looked a bit more in details, and it seems even digging through each instance definition’s object list to find which one owns the object will be a challenge, because every subobjects IDs are empty . Is there anything other than the ID to identify an object inside an instance reference?
This is an example of my code, where I tried to build a proper dictionary to be able to retrieve the instance def from the sub-object ID:
<Extension>
Public Function GetInstanceobjectsParents(ByVal doc As RhinoDoc) As Dictionary(Of Guid, InstanceObject)
RhinoApp.Write("Reading blocks instances... ")
Dim rslt As New Dictionary(Of Guid, InstanceObject)
For Each item As RhinoObject In doc.Objects.FindByObjectType(ObjectType.InstanceReference)
Dim instRef As InstanceObject = TryCast(item, InstanceObject)
For Each ObjID As Guid In instRef.GetAllSubObjects
If Not rslt.ContainsKey(ObjID) Then rslt.Add(ObjID, instRef)
Next
Next
RhinoApp.WriteLine("Done.")
Return rslt
End Function
<Extension>
Public Function GetAllSubObjects(ByVal instRef As InstanceObject) As List(Of Guid)
Dim rslt As New List(Of Guid)
For Each obj As RhinoObject In instRef.GetSubObjects
If obj.ObjectType = ObjectType.InstanceReference Then
Dim SubInstRef As InstanceObject = TryCast(obj, InstanceObject)
For Each item As Guid In SubInstRef.GetAllSubObjects
rslt.Add(item)
Next
Else
rslt.Add(obj.Id)
End If
Next
Return rslt
End Function