Insert block python


#1

Hi,

I thought that rs.InsertBlock should import a block instance that is allready in the document, but when I do the following, I get the message: does not exist in InstanceDefinitionsTable

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def blocks():
    rs.EnableRedraw(False)
    topfwd=rs.FindFile("topfwd.3dm")
    centerfwdps=rs.FindFile("centerfwdps.3dm")
    centerfwdsb=rs.FindFile("centerfwdsb.3dm")
    topcenterps=rs.FindFile("topcenterps.3dm")
    topcentersb=rs.FindFile("topcentersb.3dm")
    rs.Command("_-Insert File=Yes LinkMode=Embed "+topfwd+" Block 0,0,0 1.0 0.0")
    rs.Command("_-Insert File=Yes LinkMode=Embed "+centerfwdps+" Block 0,0,0 1.0 0.0")
    rs.Command("_-Insert File=Yes LinkMode=Embed "+centerfwdsb+" Block 0,0,0 1.0 0.0")
    rs.Command("_-Insert File=Yes LinkMode=Embed "+topcenterps+" Block 0,0,0 1.0 0.0")
    rs.Command("_-Insert File=Yes LinkMode=Embed "+topcentersb+" Block 0,0,0 1.0 0.0")
    arrow_blocks=rs.ObjectsByType(4096, select=False)
    rs.DeleteObjects(arrow_blocks)
    rs.EnableRedraw(True)
    
    point = [10,0,0]
    rs.InsertBlock(topfwd,point)
    
blocks()

ps. when I remove the line rs.DeleteObjects(arrow_blocks) all blocks are inserted


#2

Hi Thomas,

hm, i do not know what topfwd.3dm contains. Does it contain a block definition already ? My guess is that this line returns the path with filename first:

topfwd=rs.FindFile("topfwd.3dm")

If that file does not contain a named block instance already, this line below created a block from the file content using the filename (no path, no extension) as the new block name:

rs.Command("_-Insert File=Yes LinkMode=Embed "+topfwd+" Block 0,0,0 1.0 0.0")

Maybe it fails since:

rs.InsertBlock(topfwd,point)

method asks for the instance name only but your “topfwd” variable still contains the path + filename + extension ? If you print the content of topfwd before above line, is the identical instance name listed when using _SelBlockInstanceNamed command in Rhino ?

c.