InsertBlock with Xform?

I am still trying to Replace a bunch of instances with a different block definition using Python. It seems there is always another roadblock in the way.

Since ReplaceBlock doesn’t appear to be scriptable, I am getting the transforms of all instances I want to replace and then want to use InsertBlock with a transform to insert the new blocks.

But I am getting an error that it could not convert the matrix to a point3d, but the rhinoscript syntax for InsertBlock states that I can just use a name and a transform:

How do I pass the transform to it?

Here is my Python code:

def get_block_instances_and_transforms(block_name):
    """Get the instances and transforms of a block."""
    block_instances = rs.BlockInstances(block_name)
    if not block_instances:
        return []

    transforms = []
    for instance in block_instances:
        rhobj = sc.doc.Objects.Find(instance)
        if type(rhobj.Geometry) is Rhino.Geometry.InstanceReferenceGeometry:
            iref = rhobj.Geometry
            xform = iref.Xform

    return transforms

def replace_block_instances(old_block_name, new_block_name):
    """Replace instances of a block with instances of a new block."""
    transforms = get_block_instances_and_transforms(old_block_name)
    for transform in transforms:
        rs.InsertBlock(new_block_name, transform)

The error I am getting is:

Message: Could not convert R0=(1.40962254135957E-06,-1.32118725776672,0,-6625.6318359375), R1=(0,0,2.63138914108276,1600.00036621094), R2=(-3.94159054756165,-4.72493383085748E-07,0,8854.2724609375), R3=(0,0,0,1) to a Point3d

What am I missing?

oh, this isn’t even up to date:

You might want to set up a robots.txt file so it doesn’t get indexed by Google, because when you google “rhinoscript xxx” for a topic, you always land on the old page.

I imagine a meeting at McNeel: “Hey, what shall we call InsertBlock, but with a transform?” … “How about InsertBlock2”… “That’ll do”. :smiley: