Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5834

Copy nested blocks in place -- python

$
0
0

@Rickson wrote:

i’m trying to copy out the nested blocks but having trouble getting them back in their instance locations, they go back to 0. Do i need to create a plane at their instance origin and do plane to plane transformation? It seems to hold some sort of relation to the Top Level Block.

My attempts so far.

import rhinoscriptsyntax as rs
import Rhino


#Select Block
#Get all instances of block
#Explode and get 1st level nested blocks
#place instance of said block at its locations

selBlks = rs.GetObjects("Select Blocks", 4096)
blkcpy = []

for blk in selBlks:
    name = rs.BlockInstanceName(blk)
    allBlks = rs.BlockInstances(name)
    for bk in allBlks:
        blkObjs = rs.BlockObjects(rs.BlockInstanceName(allBlks[0]))
        for blkblk in blkObjs:
            if rs.IsBlockInstance(blkblk):
                blkcpy.append(blkblk)

rs.CopyObjects(blkcpy)
print blkcpy

import rhinoscriptsyntax as rs
import Rhino


#Select Block
#Get all instances of block
#Explode and get 1st level nested blocks
#place instance of said block at its locations

selBlks = rs.GetObjects("Select Blocks", 4096)

for blk in selBlks:
    name = rs.BlockInstanceName(blk)
    allBlks = rs.BlockInstances(name)
    for bk in allBlks:
        blkObjs = rs.BlockObjects(rs.BlockInstanceName(allBlks[0]))
        bkx = rs.BlockInstanceXform(bk)
        for blkblk in blkObjs:
            if rs.IsBlockInstance(blkblk):
                xform = rs.BlockInstanceXform(blkblk)
                bname = rs.BlockInstanceName(blkblk)
                #needs transformation of bkx to xform
                #insrtbk = rs.InsertBlock2(bname, bkx)
            

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5834

Latest Images

Trending Articles



Latest Images