Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

measureMinimumDistance between 2 occurrences

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
runeruiterkamp
468 Views, 8 Replies

measureMinimumDistance between 2 occurrences

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

8 REPLIES 8
Message 2 of 9
kandennti
in reply to: runeruiterkamp

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.

Message 3 of 9
runeruiterkamp
in reply to: kandennti

Hi kandennti,

Thank you for verifying this! It's kind of a relief to find that this is probably a bug, since I was almost convinced I was missing something, but the fact that this is possible through the UI Inspect->Measure was suspicious to me.

I'd like to see this fixed as well since I'm relying on this for the add-in I'm trying to develop, is there a place where I can officially report this?
Message 4 of 9
kandennti
in reply to: runeruiterkamp

@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.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/want-to-get-early-access-to-new-functional... 

Message 5 of 9
MichaelT_123
in reply to: kandennti

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

 

 

MichaelT
Message 6 of 9
kandennti
in reply to: MichaelT_123

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.

Message 7 of 9
kandennti
in reply to: kandennti

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
Message 8 of 9
runeruiterkamp
in reply to: kandennti

Hi kandennti,

Thank you! This is working for me, there doesn't seem to be any downside to using TemporaryBRepManager in my use case so this is perfect.

Message 9 of 9
kandennti
in reply to: runeruiterkamp

@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.

Post to forums  

Autodesk Design & Make Report