Description

Réinitialise l’échelle d’un bloc, en conservant la rotation autour du point d’insertion.

Le script suivant fonctionne sur :

  • Rhino pour Windows ;
  • Rhino pour macOS.

Script par Ejnar Brendsdal sous licence MIT.

Code

 
#******* Imports ********************
#************************************
 
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Geometry as G
 
#******* Main function ********************
#******************************************
 
def RunCommand( is_interactive ):
    if sc.escape_test(False):
        print "script cancelled" #do something
 
    print "Resetting..."
 
    #******* Get blocks ***********''****
    #************************************
 
    objectIds = rs.GetObjects("Pick some blocks", 4096, preselect=True)
    if not objectIds:
        print "No objects"
        return False
 
    rs.EnableRedraw(False)
 
    #******* Ref Geometry ***************
    #************************************
 
    points = [
     G.Point3d(0,0,0),
     G.Point3d(1,0,0),
     G.Point3d(0,1,0),
     G.Point3d(0,0,1)
    ]
 
    #gather all new objects when done
    finalObjs = []
 
    for id in objectIds:
 
        #Get the block transformation matrix and name
        blockXForm = rs.BlockInstanceXform(id)
        blockName = rs.BlockInstanceName(id)
 
        #Add reference geometry
        pts = G.Polyline(points)
 
        #Apply block transformation matrix to ref geometry
        pts.Transform(blockXForm)
 
        #create final plane
        finalOrigin = pts[1]
        finalXaxis = rs.VectorSubtract( pts[1], pts[0] )
        finalYaxis = rs.VectorSubtract( pts[2], pts[0] )
        finalPlane = G.Plane(finalOrigin, finalXaxis, finalYaxis)
 
        #create scaling factors
        xFac = 1 / rs.Distance(pts[1],pts[0])
        yFac = 1 / rs.Distance(pts[2],pts[0])
        zFac = 1 / rs.Distance(pts[3],pts[0])
 
        #Scale block
        newXForm = G.Transform.Scale(finalPlane, xFac, yFac, zFac)
        rs.TransformObject(id,newXForm)
 
    #Select all new objects
    rs.SelectObjects(objectIds)
 
    rs.EnableRedraw(True)
 
    print "...aaand its done."
    #End RunCommand()
 
    #end sane
    return 0
 
RunCommand(True) #Run script