rs.AddBlock always uses the Origin as base_point

Hi there,

I was trying to do the following:

block = rs.AddBlock([obj], pt, str(obj), False)
rs.InsertBlock(block, pt)

where pt is the base point I want to keep, but the result always uses the Origin as the base point for blockinstance, and the inserted block will not be at the same place as the original object.

Is this a known bug or am I missing something? I am working on (7.5.21100.3001, 2021-04-10).

Best,
Vincent

Hi @vincentfs,

This seems to work:

import rhinoscriptsyntax as rs

def test_block():
    
    rect = rs.GetRectangle()
    if not rect:
        return
    
    pt = rect[0]
    rs.AddPoint(pt)
    
    points = list(rect)
    points.append(pt)
    rect = tuple(points)
    
    id = rs.AddPolyline(rect)
    
    blk = rs.AddBlock([id], pt, 'test_block', True)
    rs.InsertBlock(blk, pt)
    
test_block()

What am I missing?

– Dale

Hi @dale ,

I think I found the problem here. When you run the script once, the rhino python definition for AddBlock will do:

rc = scriptcontext.doc.InstanceDefinitions.Add(name, “”, base_point, geometry, attrs)

which passes in the base_point correctly.

But when you run the script again, since the block already exists, it will do:

rc = scriptcontext.doc.InstanceDefinitions.ModifyGeometry(found.Index, geometry, attrs)

which completely ignores the base_point.

So is there a way to modify the base_point for an existing block through script? Or I will have to reimplement the AddBlock to make it work.

Best,
Vincent

Hi @vincentfs,

RhinoCommon doesn’t have a method that will modify the insertion point of an instance definition. I’ve added an item to the wish list for this.

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

– Dale

Great. Thank you.