Orienting blocks to other blocks

Hello,

I’m trying to set up a script to orient target blocks to host blocks.

If the name of the target blocks is in the name of the host blocks then the targets will be transformed to the hosts.

It seems to be working well, but if the target blocks have any type of rotation then I need to run the script twice for them to be correctly oriented.

See attached file, script and video.

import rhinoscriptsyntax as rs

hosts = rs.GetObjects("Select host blocks",4096)

hostNames = []
hostXforms = []
hostPlanes = []
for i in hosts:
    name = rs.BlockInstanceName(i)
    hostNames.append(name)
    instanceXform = rs.BlockInstanceXform(i)
    hostXforms.append(instanceXform)
    hostPlane = rs.PlaneTransform(rs.WorldXYPlane(),instanceXform)
    hostPlanes.append(hostPlane)
    rs.LockObject(i)

print hostNames
#print hostXforms
#print hostPlanes

targets = rs.GetObjects("Select target blocks",4096)

targetNames = []
targetXforms = []
targetPlanes = []

for i in targets:
    name = rs.BlockInstanceName(i)
    targetNames.append(name)
    instanceXform = rs.BlockInstanceXform(i)
    targetXforms.append(instanceXform)
    targetPlane = rs.PlaneTransform(rs.WorldXYPlane(),instanceXform)
    targetPlanes.append(targetPlane)
    
    
    
print targetNames
#print targetXforms

for i,hName in enumerate(hostNames):
    for j,tName in enumerate(targetNames):
        if hName in tName:
            print "match: ", hName,tName
            print hosts[i]
            print targets[j]
            xForm = rs.XformChangeBasis(hostPlanes[i],targetPlanes[j])
            rs.TransformObject(targets[j],xForm)
        else:
            print "nomatch: ", hName,tName

for i in hosts:
    rs.UnlockObject(i)

Thanks,

Dan

blockmatching.3dm (176.3 KB)
blockMatching.py (1.4 KB)

1 Like

hi Dan,

I’m not sure why your script won’t work in one go, but see if this helps. The idea is to reverse the targets’ transformation first and then apply the host transformation to it:

blockMatching.py (1.5 KB)

2 Likes