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: 

How to edit a loft by API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
bjoern79de
543 Views, 2 Replies

How to edit a loft by API

I'm able to remove items from loftFeature.loftSections by:

 

for section in loftFeat.loftSections:
    section.deleteMe()
 
But I'm not able to add new profiles:
for sketch in component.sketches:
    loftFeats.loftSections.add(sketch.profiles[0])
 
"InternalValidationError: entities_size > 0"
 
Any suggestions?
 
 
 
2 REPLIES 2
Message 2 of 3
kandennti
in reply to: bjoern79de

Hi @bjoern79de .

 

Using the attached file, I was able to process it like an image.

1.png

This is the source code.

#Fusion360API Python script
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des  :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # get loft
        loft = root.features.loftFeatures.item(0)
        sects :adsk.fusion.LoftSections = loft.loftSections

        # get insert profile
        prof :adsk.fusion.Profile = root.sketches.item(2).profiles.item(0)

        # backup markerPosition
        tlPos :int = des.timeline.markerPosition

        # change timeline before loft
        des.timeline.markerPosition = loft.timelineObject.index

        # get the last LoftSection
        endSect :adsk.fusion.LoftSection = sects.item(sects.count - 1)

        # backup the last entity
        endEnt = endSect.entity

        # change the last LoftSection entity
        # LoftSection.entity was a read/write property
        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-E0CE293E-9ED4-4E00-A5E6-32695A0F0A40
        endSect.entity = prof

        # add last entity backed up
        sects.add(endEnt)

        # Restore timeline
        des.timeline.markerPosition = tlPos

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 3 of 3
kandennti
in reply to: kandennti

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

Post to forums  

Autodesk Design & Make Report