Fairly new to scripting. This seems like something I should be able to accomplish on my own, but I’m struggling to solve.
I’m trying to move a group of object in the X axis. I’d like the move distance to be full distance of it’s bounding box + 3mm. Then I paste the original copy.
The result will be two identical objects next to each other with a gap of 3mm in the middle of the object.
I don’t fully understand how arrays work. but this is the code I have so far.
Have a look at the following and see if it makes sense… I used all native Rhinoscript functions.
Let me know if there is something you don’t understand. --Mitch
Option Explicit
Call Main()
Sub Main()
Dim arrObjs,arrBoundingBox, arrNewInsertPt,dblMoveDist,arrCopies
'Rhino.NormalObjects should be all selectable objects'
arrObjs = Rhino.NormalObjects
If Not ISNull(arrObjs) Then
arrBoundingBox = Rhino.BoundingBox(arrObjs)
'arrBoundingBox(0) is lower left corner'
'arrBoundingBox(1) is lower right corner'
'Get length of bounding box X, add 3'
dblMoveDist = arrBoundingBox(1)(0) - arrBoundingBox(0)(0) + 3
'copy objects from original point to new point'
arrCopies = Rhino.CopyObjects(arrObjs, Array(dblMoveDist, 0, 0))
End If
End Sub
Wow Mitch, that worked perfectly. I really appreciate the comments you added to explain the script. It really helped to dissect whats happening. I’ve modified it to do different things to gain a better understanding and I think I get it!!
Can you tell me if the other corners of a bounding box follow the same convention? Can I reference all 8 corners?
‘arrBoundingBox(0) is lower left corner’
‘arrBoundingBox(1) is lower right corner’
Yes, and yes, you can.
0, 1, 2, and 3 are the corners of the lower BB face starting in the lower left corner and traveling CCW.
4, 5, 6 and 7 are the corners of the upper BB face starting in the lower left corner (of the upper face) and traveling CCW.
What you’re looking at here is an array of arrays, so maybe the notation is confusing you…
The outer array is the array of bounding box corners - 8 in total, with indices from 0 to 7
arrBB(0), arrBB(1)…arrBB(7)
Each corner point is in itself an array of 3 coordinates (x,y,z). In a point array, the “0” index is always the x coordinate, the “1” index is the y coordinate and the “2” index is the z coordinate.
So, when you have arrBB(0), you are first addressing the lower left hand corner point of the box
When you have arrBB(0)(0) you are addressing the x coordinate value of the lower left hand corner point of the box.
So, to get the Z height of your box, you can actually subtract any of the upper 4 box corner point Z coordinates (they are all the same) from any of the lower box point z coordinates… the (n)(2) is always the Z coordinate…
So the following work:
zoffset = arrBoundingBox(4)(2) - arrBoundingBox(0)(2)
OR
zoffset = arrBoundingBox(5)(2) - arrBoundingBox(1)(2)
OR
zoffset = arrBoundingBox(7)(2) - arrBoundingBox(3)(2)
OR
zoffset = arrBoundingBox(6)(2) - arrBoundingBox(2)(2)
If I wanted to find the X distance it could read.
zoffset = arrBoundingBox(0)(0) - arrBoundingBox(1)(0)
OR
zoffset = arrBoundingBox(3)(0) - arrBoundingBox(2)(0)
OR
zoffset = arrBoundingBox(4)(0) - arrBoundingBox(5)(0)
OR
zoffset = arrBoundingBox(7)(0) - arrBoundingBox(6)(0)
If I wanted to find the Y distance it could read.
zoffset = arrBoundingBox(0)(1) - arrBoundingBox(3)(1)
OR
zoffset = arrBoundingBox(1)(1) - arrBoundingBox(2)(1)
OR
zoffset = arrBoundingBox(4)(1) - arrBoundingBox(7)(1)
OR
zoffset = arrBoundingBox(5)(1) - arrBoundingBox(6)(1)
If I wanted to find the Z distance it could read.
zoffset = arrBoundingBox(4)(2) - arrBoundingBox(0)(2)
OR
zoffset = arrBoundingBox(5)(2) - arrBoundingBox(1)(2)
OR
zoffset = arrBoundingBox(7)(2) - arrBoundingBox(3)(2)
OR
zoffset = arrBoundingBox(6)(2) - arrBoundingBox(2)(2)