Hello,
I'm wondering whether I'm misunderstanding the measureMinimumDistance function. According to the documentation both arguments of this function should be able to accept an Occurrence or a BRepBody:
The first geometry to measure from. This can be an Occurrence, BRepBody, BRepFace, BRepEdge, BRepVertex, ConstructionPlane, ConstructionAxis, ConstructionPoint, and any sketch entity. The only temporary geometry supported is the Plane object.
But when i try to measure the distance between 2 occurrences, or 2 brepbodies:
measureResult = app.measureManager.measureMinimumDistance(occ1body, occ2body)
I keep getting:
return _core.MeasureManager_measureMinimumDistance(self, geometryOne, geometryTwo)
RuntimeError: 3 : invalid argument geometryOne
(I'm selecting the occurrences using a selectionInput and storing them in an ObjectCollection)
Measuring the minimum distance is possible using the UI measure button so I assumed this should be possible as well, am I missing something? I unfortunately cant find any documentation or examples with this setup, they usually use Lines or Edges.
Thank you
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
Hi @runeruiterkamp -San.
I was curious so I ran the following script using the attached file.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
des: fusion.Design = app.activeProduct
root: fusion.Component = des.rootComponent
app.log(f"** Fusion360 ver{app.version} **")
# root Body
rootBody1: fusion.BRepBody = root.bRepBodies[0]
rootBody2: fusion.BRepBody = root.bRepBodies[1]
test_measureMinimumDistance(
"Root Body",
rootBody1,
rootBody2,
)
# root Face
test_measureMinimumDistance(
"Root Body Face",
rootBody1.faces[0],
rootBody2.faces[0],
)
# root Edge
test_measureMinimumDistance(
"Root Body Edge",
rootBody1.edges[0],
rootBody2.edges[0],
)
# root Vertex
test_measureMinimumDistance(
"Root Body Vertex",
rootBody1.vertices[0],
rootBody2.vertices[0],
)
# occ
occ1: fusion.Occurrence = root.occurrences[0]
occ2: fusion.Occurrence = root.occurrences[1]
test_measureMinimumDistance(
"Occurrence",
occ1,
occ2,
)
# occ body
occBody1: fusion.BRepBody = occ1.component.bRepBodies[0]
occBody1 = occBody1.createForAssemblyContext(occ1)
occBody2: fusion.BRepBody = occ2.component.bRepBodies[0]
occBody2 = occBody2.createForAssemblyContext(occ2)
test_measureMinimumDistance(
"Occurrence Body",
occBody1,
occBody2,
)
# occ face
test_measureMinimumDistance(
"Occurrence Body Face",
occBody1.faces[0],
occBody2.faces[0],
)
# occ Edge
test_measureMinimumDistance(
"Occurrence Body Edge",
occBody1.edges[0],
occBody2.edges[0],
)
# occ Vertex
test_measureMinimumDistance(
"Occurrence Body Vertex",
occBody1.vertices[0],
occBody2.vertices[0],
)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def test_measureMinimumDistance(
msg: str,
entity1,
entity2,
) -> None:
res = is_measureMinimumDistance(
entity1,
entity2,
)
app: core.Application = core.Application.get()
app.log(f"{msg} -> {res}")
def is_measureMinimumDistance(
entity1,
entity2,
) -> bool:
try:
app: core.Application = core.Application.get()
measMgr: core.MeasureManager = app.measureManager
measMgr.measureMinimumDistance(entity1, entity2)
return True
except:
return False
Here are the results.
** Fusion360 ver2.0.16490 **
Root Body -> False
Root Body Face -> True
Root Body Edge -> True
Root Body Vertex -> True
Occurrence -> False
Occurrence Body -> False
Occurrence Body Face -> True
Occurrence Body Edge -> True
Occurrence Body Vertex -> True
The measureMinimumDistance method succeeds for face, edge, and vertex, but fails between body and occurrence.
I think this is probably a bug, but I would like to have it fixed as soon as possible, because it is very inconvenient to not be able to perform measurements.
@runeruiterkamp -San.
As a participant in the Insider Program, there is a system for reporting bugs, so I try to report what I am sure is a bug.
Hi Kandennti-San,
... I haven't tried, ... but consider a small change.
Replace:
# occ body
occBody1: fusion.BRepBody = occ1.component.bRepBodies[0]
occBody1 = occBody1.createForAssemblyContext(occ1)
with:
# occ body
occBody1: fusion.BRepBody = occ1.bRepBodies[0]
Regards
MichaelT
Thanks @MichaelT_123 -San.
I tried it and the result was the same.
I had overlooked until now that there is a bRepBodies property in Ocurrence.
This will be useful for other things in the future.
If you really want to measure BRepBody with measureMinimumDistance, you can use the TemporaryBRepManager.copy method.
・・・
tmpMgr: fusion.TemporaryBRepManager = fusion.TemporaryBRepManager.get()
test_measureMinimumDistance(
"Root Body-Clone",
tmpMgr.copy(rootBody1),
tmpMgr.copy(rootBody2),
)
test_measureMinimumDistance(
"Occurrence Body-Clone",
tmpMgr.copy(occBody1),
tmpMgr.copy(occBody2),
)
・・・
Root Body-Clone -> True
Occurrence Body-Clone -> True
@runeruiterkamp -San.
This method can handle the body but not the occurrence.
This bug will be fixed in the near future.
Can't find what you're looking for? Ask the community or share your knowledge.