Swap a block in Python?

How would I duplicate ReplaceBlock? Do I have to just delete it and replace?

Hi

The blocks in the model are called instance objects, and the underlying block definition is called instance definition. To replace a block you can use the method ReplaceInstanceObject in the object table.

Thanks!

This is my code that’s not working.

def SwapBlock(blockID):
    NewBlockDef=sc.doc.InstanceDefinitions.Find("something")
    OldBlock = rs.coercerhinoobject(blockID,True)
    if sc.doc.Objects.ReplaceInstanceObject(OldBlock,NewBlockDef.Index):
        return True   

Okay I finally got this to work passing the guid, but an object reference should work too…??

def SwapBlock(blockID):
    NewBlockDef=sc.doc.InstanceDefinitions.Find("Thing")
    if sc.doc.Objects.ReplaceInstanceObject(blockID,NewBlockDef.Index):
        return True