Usertext lost after rs.explodeblockinstance()

Hi,

I believe there is an issue with rs.ExplodeBlock() in rhino6. I have a block instance containing an object with object attactched user text (see .3dm the rectangle), if I run the following code snippet to explode the block, the usertext is lost. I expected it to be in the resulting objects as well, like when I run the command ‘Explode’

import rhinoscriptsyntax as rs

objs = rs.GetObjects('select')

if objs:
    for obj in objs:
       result = rs.ExplodeBlockInstance(obj)

userText_test.3dm (81.0 KB)

the same occurs with
result = scriptcontext.doc.Objects.AddExplodedInstancePieces(rh_block)

cheers,
Tim

Version 6 SR9
(6.9.18271.20591, 28-9-2018)
Educational

Hi Tim, thanks, I’ll take a look. I have a feeling I already made a bug report and a workaround for this, I’ll see if I can find it.

Yeah, found it… @timcastelijn - see if this helps for now:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def ExplodeBlock(thing,instance_xform):
    expStatus = True #check for failure so I know not to delete the input object
    
    xform = thing.InstanceXform
    
    
    # if this is looping through nested blocks there will be
    # an incoming transgform to take into account
    if instance_xform:
        xform = instance_xform * xform

    inst = thing.InstanceDefinition

    objList = []
    # get all the objects in the definition
    for i in range(inst.ObjectCount):
        temp = []
        x = inst.Object(i)
        objList.append(x)
    
    
    # look through the definition objects and send them back  
    # through if they are instances themselves, 
    # else, apply the accumulated transform, the attributes and
    # put them in the document
    
    for n in range(len(objList)):
        if isinstance(objList[n], Rhino.DocObjects.InstanceObject):
            ExplodeBlock(objList[n], xform)
            
        else:
            
            geo = objList[n].Geometry
            geo.Transform(xform)
            new = sc.doc.Objects.Add(geo, objList[n].Attributes)
            
            #check for failure so I know not to delete the input object
            if not new: expStatus = False

    return expStatus
    
def test():
    
    id = rs.GetObject("Select a block instance.", filter = rs.filter.instance,  preselect=True)
    if not id: return
    
    thing = sc.doc.Objects.Find(id)
    
    rc = ExplodeBlock(thing, None)
    
    if rc:
        rs.DeleteObject(id)
        
    sc.doc.Views.Redraw()

    
test()

https://mcneel.myjetbrains.com/youtrack/issue/RH-49260

-Pascal

hi @pascal,

thanks for the temporary solution, For now this does the trick.

cheers,
tim

And it’s still not fixed even in 7.

Hi @Asterisk,

Does the Explode command work in the manner described here?

– Dale