Position object relative to another object using reference points or reference edges #741
-
In 2D CAD a common workflow to move an object in relation to another object is:
I would like to position objects in relation to one another with Build123d using reference edges or reference points. For example, if I have two separate 2D (XY plane) face objects: How can I select the reference vertex points in order to position face1 in relation to face2? or using reference edges, how can one do this?:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Here is an example of how to do this: from build123d import *
from ocp_vscode import show_all
from random import randrange
# Create two frame objects, one at a random location
frame1 = Rectangle(100, 70) - Rectangle(90, 60)
frame2 = (Rectangle(70, 50) - Rectangle(60, 40)).locate(
Pos(randrange(0, 100), randrange(0, 100))
)
# Find two alignment points
pt1 = Vector(
frame1.face().inner_wires()[0].vertices().group_by(Axis.Y)[-1].sort_by(Axis.X)[0]
)
pt2 = Vector(
frame2.face().inner_wires()[0].vertices().group_by(Axis.Y)[-1].sort_by(Axis.X)[0]
)
# Move frame2 to align with frame1
frame2.position += pt1 - pt2
show_all() In Builder mode one could with Hopefully this answers your question. |
Beta Was this translation helpful? Give feedback.
Here is an example of how to do this:
Before move:
After move:
In Builder mode one could with
w…