Option Explicit 'Script written by 'Script copyrighted by 'Script version Tuesday, May 16, 2017 11:31:31 AM Call Main() Sub Main() Dim New_Block 'The block to replace with New_Block = Rhino.GetObject("Pick block to replace with", 4096) Dim New_Ref_Pt(2) 'A reference point on the block 'New_Ref_Pt = Rhino.GetPoint("Pick block reference point") Dim New_Box New_Box = Rhino.BoundingBox(New_Block) New_Ref_Pt(0) = (New_Box(0)(0) + New_Box(1)(0) + New_Box(2)(0) + New_Box(3)(0)) / 4 New_Ref_Pt(1) = (New_Box(0)(1) + New_Box(1)(1) + New_Box(2)(1) + New_Box(3)(1)) / 4 New_Ref_Pt(2) = (New_Box(0)(2) + New_Box(1)(2) + New_Box(2)(2) + New_Box(3)(2)) / 4 'Call Rhino.AddPoint(New_Ref_Pt) Dim New_Ins_Pt 'The block insertion point New_Ins_Pt = Rhino.BlockInstanceInsertPoint(New_Block) Dim New_Ref_Ins_Vect 'The vector between the insertion point and the reference point New_Ref_Ins_Vect = Rhino.VectorCreate(New_ins_Pt, New_Ref_Pt) Dim Blocks 'The blocks to replace Blocks = Rhino.GetObjects("Pick blocks, groups or any object to replace", 0) Dim i,j,k Dim ref_Pt(2), ins_Pt, Ins_Ref_Vect, Box 'similar attributes to blocks to replace as above Dim Transf_Matrix 'The transformation matrix of the block to replace (Translation,rotation,scale) Dim Copied_Block 'Loop variables Dim Top_Group, Obj_Group, Grp_List(), InList Redim Preserve Grp_List(0) Grp_List(0) = "" k = 0 Call Rhino.EnableRedraw(False) For i=0 To Ubound(Blocks) If Rhino.IsBlockInstance(Blocks(i)) Then Transf_Matrix = Rhino.BlockInstanceXform(Blocks(i)) Call Rhino.TransformObject(Blocks(i), Rhino.XformInverse(Transf_Matrix)) ins_Pt = Rhino.BlockInstanceInsertPoint(Blocks(i)) Box = Rhino.BoundingBox(Blocks(i)) Ref_Pt(0) = (Box(0)(0) + Box(1)(0) + Box(2)(0) + Box(3)(0)) / 4 Ref_Pt(1) = (Box(0)(1) + Box(1)(1) + Box(2)(1) + Box(3)(1)) / 4 Ref_Pt(2) = (Box(0)(2) + Box(1)(2) + Box(2)(2) + Box(3)(2)) / 4 'Call Rhino.AddPoint(Ref_Pt) Ins_Ref_Vect = Rhino.VectorCreate(Ref_Pt, ins_Pt) Copied_Block = Rhino.CopyObject(New_Block, Rhino.Vectorreverse(New_Ins_Pt)) Call Rhino.MoveObject(Copied_Block, Ins_Ref_Vect) Call Rhino.MoveObject(Copied_Block, New_Ref_Ins_Vect) Call Rhino.TransformObject(Copied_Block, Transf_Matrix) Call Rhino.DeleteObject(Blocks(i)) Else If Not Isnull(Rhino.ObjectTopGroup(Blocks(i))) Then Top_Group = Rhino.ObjectTopGroup(Blocks(i)) Obj_Group = Rhino.ObjectsByGroup(Top_Group) InList = False For j=0 To Ubound(Grp_List) If Top_Group = Grp_List(j) Then InList = True Rhino.DeleteObject(Blocks(i)) End If Next If Not Inlist Then ReDim Preserve Grp_List(k) Grp_List(k) = Top_Group k = k + 1 Box = Rhino.BoundingBox(Obj_Group) Ref_Pt(0) = (Box(0)(0) + Box(1)(0) + Box(2)(0) + Box(3)(0)) / 4 Ref_Pt(1) = (Box(0)(1) + Box(1)(1) + Box(2)(1) + Box(3)(1)) / 4 Ref_Pt(2) = (Box(0)(2) + Box(1)(2) + Box(2)(2) + Box(3)(2)) / 4 Copied_Block = Rhino.CopyObject(New_Block, New_Ref_Pt, Ref_Pt) Call Rhino.DeleteObject(Blocks(i)) End If Else Box = Rhino.BoundingBox(Blocks(i)) Ref_Pt(0) = (Box(0)(0) + Box(1)(0) + Box(2)(0) + Box(3)(0)) / 4 Ref_Pt(1) = (Box(0)(1) + Box(1)(1) + Box(2)(1) + Box(3)(1)) / 4 Ref_Pt(2) = (Box(0)(2) + Box(1)(2) + Box(2)(2) + Box(3)(2)) / 4 Copied_Block = Rhino.CopyObject(New_Block, New_Ref_Pt, Ref_Pt) Call Rhino.DeleteObject(Blocks(i)) End If End If Next Call Rhino.EnableRedraw(True) End Sub