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: 

Previous working API Python script now fails at Project Body Projection Link

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
info83PHN
216 Views, 5 Replies

Previous working API Python script now fails at Project Body Projection Link

I have a python API script I wrote about a year ago ( around 3 or 4 Fusion updates ago ).

It was working perfectly at the time.

Now it fails when I try and Project existing Bodies to a new Sketch.

It appears that the script is executing the Project Body with the 'Projection Link' turned OFF.

If I create the Body Projections manually with 'Projection Link' turned ON, then the result is exactly as I need it to be.

Is it possible to set the 'Projection Link' to ON within a Script ?

 

 

 

                # create a sketch for the border shape
                # create sketch on the 'TextPlane' plane
                uTextPlane = rootComp.constructionPlanes.itemByName('TextPlane')
                sketches = rootComp.sketches
                sketch = sketches.add(uTextPlane)
                sketch.name = 'Border'
            
                projectedSketchEntities = []

                for body in inputColl:
                    projectedEntities = sketch.project(body)
                    projectedSketchEntities.extend([e for e in projectedEntities])

 

5 REPLIES 5
Message 2 of 6
kandennti
in reply to: info83PHN

Hi @info83PHN .

 

I tried it and saw that the link was indeed broken. I think it is probably a bug.

The screen moves, but I made a sample using text commands as an alternative.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        rootComp: adsk.fusion.Component = des.rootComponent

        uTextPlane = rootComp.constructionPlanes.itemByName('TextPlane')
        sketches = rootComp.sketches
        sketch = sketches.add(uTextPlane)
        sketch.name = 'Border'
    
        projectedEntities = projectBodies(sketch, rootComp.bRepBodies)

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


def projectBodies(
    skt: adsk.fusion.Sketch,
    bodies: list) -> list:

    tokens = [c.entityToken for c in skt.sketchCurves]
    tokens.extend([p.entityToken for p in skt.sketchPoints])

    app: adsk.core.Application = adsk.core.Application.get()
    sels: adsk.core.Selections = app.userInterface.activeSelections

    sels.clear()
    sels.add(skt)
    app.executeTextCommand(u'Commands.Start SketchActivate')

    sels.clear()
    app.executeTextCommand(u'Commands.Start ProjectNewCmd')
    app.executeTextCommand(u'Commands.SetString infoFilterType {}'.format('infoFilterTypeBodies'))
    [sels.add(body) for body in bodies]
    app.executeTextCommand(u'NuCommands.CommitCmd')

    app.executeTextCommand(u'Commands.Start SketchStop')

    projectedEntities = [c for c in skt.sketchCurves if not c.entityToken in tokens]
    projectedEntities.extend([p for p in skt.sketchPoints if not p.entityToken in tokens])

    return projectedEntities
Message 3 of 6
BrianEkins
in reply to: info83PHN

I can reproduce this and confirm it is a bug. Hopefully, it can be fixed soon.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 4 of 6
info83PHN
in reply to: BrianEkins

Many Thanks
Do we need to report this bug somewhere to get it corrected ?
I am wasting hours with having to manually do the projections manually

Message 5 of 6
BrianEkins
in reply to: info83PHN

Autodesk is aware of the problem, thanks to you reporting it, and are looking into it.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 6 of 6
BrianEkins
in reply to: BrianEkins

It looks like this has been fixed in the latest update.

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

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report