Skip to content

Position object relative to another object using reference points or reference edges #741

Answered by gumyr
WayneSherman asked this question in Q&A
Discussion options

You must be logged in to vote

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()

Before move:

After move:

In Builder mode one could with w…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@WayneSherman
Comment options

@gumyr
Comment options

Answer selected by WayneSherman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants