[Bug] MeasureManager and new component

[Bug] MeasureManager and new component

JeromeBriot
Mentor Mentor
718 Views
4 Replies
Message 1 of 5

[Bug] MeasureManager and new component

JeromeBriot
Mentor
Mentor

Hello,

 

I can't use the measure manager between geometries inside a component.

 

The code below works only if the createNewComponent variable is set to False. If not, it returns this error:

measure-manager-error.PNG

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        createNewComponent = False

        if not createNewComponent:
            parentComp = design.rootComponent
        else:
            rootComp = design.rootComponent
            occ = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
            parentComp = occ.component

        baseFeats = parentComp.features.baseFeatures
        baseFeat = baseFeats.add()
        baseFeat.startEdit()

        pointInput = parentComp.constructionPoints.createInput()

        pointInput.setByPoint(adsk.core.Point3D.create(0.0, 0.0, 0.0))
        point1 = parentComp.constructionPoints.add(pointInput)

        pointInput.setByPoint(adsk.core.Point3D.create(1.0, 0.0, 0.0))
        point2 = parentComp.constructionPoints.add(pointInput)

        baseFeat.finishEdit()

        measure = app.measureManager.measureMinimumDistance(point1, point2)

        ui.messageBox('Distance: {} cm'.format(measure.value))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Thank you.

 

0 Likes
719 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor

Hi @JeromeBriot .

 

I don't know why, but it was possible to measure between geometry.

・・・
measure = app.measureManager.measureMinimumDistance(point1.geometry, point2.geometry)
・・・
Message 3 of 5

JeromeBriot
Mentor
Mentor

Thank you @kandennti for the workaround. I really appreciate it.

👍

Message 4 of 5

adminTCYL2
Enthusiast
Enthusiast

I got nearly the same problem. I measure an Angle. That works in rootComp with: 

measureResult = app.measureManager.measureAngle(edge, line)
But when I have my lines and edges in a new component, it does not work.  The workaround "edge.geometry, line.geometriy" does not work either. 

0 Likes
Message 5 of 5

BrianEkins
Mentor
Mentor

It looks like MeasureManager expects all of the entities to be in the context of the root component.  This doesn't mean they have to exist in the root component but if they don't you need to pass in a proxy for the entity so it is in the context of the root.  Temporary geometry is an exception because it's not associated with any space and in this case is assumed to be in the root space.  This case could also potentially be an exception where both entities exist within the same component but it seems this exception isn't supported.

 

To get the script to work in the initial question, I added the following two lines just before the measureMinimumDistance call.

 

        point1 = point1.createForAssemblyContext(occ)
        point2 = point2.createForAssemblyContext(occ)

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com