Change Block/Instance Path via Python


(Willem Derks) #1

Hi,

I’m looking for a way to change the path of a block definition.
So far I have found to get a list of the definitions via

scriptcontext.doc.InstanceDefinitions

However the Definitions appear not to have a method to change the SourceArchive string.

Can anyone tell me how to change a instance SourceArchive path?

Thanks
-Willem


#2

Willem,

This is not really what you are looking for, but it will allow you to change the path of a block definition in python by putting strings through the Rhino command line.

import rhinoscriptsyntax as rs
Blocks=rs.BlockNames()
for Block in Blocks:
    ##Block Properties##
    cmd="-_BlockManager "
    cmd+="Properties "
    cmd+=Block+" "             #Block Name as a String
    cmd+="UpdateType "
    cmd+="LinkedAndEmbedded "  #How you are storing the blocks
    cmd+=BlockDest+" "         #The new filepath for the block 
    cmd+="_Enter "
    cmd+="_Enter "
     rs.Command(cmd)           #Run string in the Rhino command line

Hope this helps, I attempted to do something similar a while back and I was unable to do everything I needed for block editing within the rhinoscriptsyntax and scriptcontext, so I ended up with this rather unsatisfying solution.

Best,
5chmidt


(Willem Derks) #3

Hi Peter,

Thanks for sharing your solution!
I did not think of doing it through the command-line as I thought it was only via the blockmanager GUI you could update the path.

-Willem