-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the absolute location of a tag? #1635
Comments
One method to access the locations might be with the assembly iterator: import cadquery as cq
def makeBoxWithTag():
result = cq.Workplane("XY").box(1, 1, 1, centered=False)
result.vertices(">X and >Y and >Z").tag("v")
return result
assembly = (
cq.Assembly(name="myassy", loc=cq.Location((5, 0, 0))) # added a name and top level location for testing
.add(cq.Solid.makeBox(1, 1, 1), name="b1")
.constrain("b1", "Fixed")
.add(makeBoxWithTag(), name="b2", loc=cq.Location((0, 0, 1)))
.constrain("b2", "Fixed")
.add(cq.Solid.makeBox(1, 1, 1), name="b3", loc=cq.Location((0, 0, 2)))
.constrain("b3", "Fixed")
.add(cq.Solid.makeSphere(0.2, angleDegrees1=-90), name="m")
.constrain("m", "b2@faces@>Y", "Point")
.solve(0)
)
def toDict(assy):
rv = {}
for shape, name, loc, _ in assy:
val = {}
val["shape"] = shape
val["loc"] = loc
rv[name] = val
return rv
b2loc = toDict(assembly)["myassy/b2"]["loc"] # get the b2 location
b2 = assembly.objects["b2"].obj # the Workplane box object b2
b2face = b2.faces(">Y") # select the face
b2face = b2face.val().locate(b2loc) # apply the location
print(b2face.Center()) |
but this requires a traversal through the entire assembly tree. is there no way to get it directly? |
Is that what you want: |
you can't do that with a tag inside the object, e.g. |
AFAICT there is no well defined location of the tagged object. You'd need to construct it yourself from its center and some prior knowledge or assumptions and then multiply with the Aren't we hitting the xy problem here? What are you trying to achieve in the end? |
The use case is this: I have two tags on my (joint) assembly, There's existing function in |
I guess you want something like this then? name = 'b2'
tag = 'v'
loc = result.objects['b2'].loc
tagged = result.objects['b2'].obj._getTagged('v').val()
result: Vector = tagged.moved(loc).Center() |
Consider this example:
The location of the middle face has
z = 1.5
, but none of the functions I've tried inprint_loc
outputs a location ofz = 1.5
. How can I get its location?The text was updated successfully, but these errors were encountered: