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: 

[Bug] MeasureManager and new component

4 REPLIES 4
Reply
Message 1 of 5
JeromeBriot
299 Views, 4 Replies

[Bug] MeasureManager and new component

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.

 

Labels (5)
4 REPLIES 4
Message 2 of 5
kandennti
in reply to: JeromeBriot

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
in reply to: kandennti

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

👍

Message 4 of 5
adminTCYL2
in reply to: JeromeBriot

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. 

Message 5 of 5
BrianEkins
in reply to: adminTCYL2

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators