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: 

Any method to isolate several occurrences at once?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
en9y37
165 Views, 5 Replies

Any method to isolate several occurrences at once?

Hi all!

 

As long as I know the .isIsolated property in the occurrence object only can be set one by one, so there's no way to isolate several occurrences at once.

 

Is there any known alternative or workaround to make this possible?

Using the .isLigthBulbOn property is not an option to my purposes, I need the occurrences truly isolated, not just a matter of if they are visible or not.

 

Thanks in advance!

 

 

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

Hi @en9y37 -San.

 

I think that the fullPathName property should be used to call the breakLink method from the shallowest level of the hierarchy, but it was too much trouble, so I forced it to be processed.

# 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

        while has_referenced_component():
            occ: fusion.Occurrence = None
            for occ in root.allOccurrences:
                if occ.isReferencedComponent:
                    try:
                        occ.breakLink()
                    except:
                        pass
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def has_referenced_component() -> bool:
    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    return any([occ.isReferencedComponent for occ in root.allOccurrences])
Message 3 of 6
en9y37
in reply to: kandennti

Excuse me @kandennti , are you sure that response was addressed to me?

Message 4 of 6
kandennti
in reply to: en9y37

@en9y37 -San.

 

Sorry, I thought you were talking about breakLink.
Please ignore the sample.

Message 5 of 6
kandennti
in reply to: en9y37

@en9y37 -San.

 

I could not think of any other way than to use the TextCommands.

# 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

        exec_isolate(
            [
                root.allOccurrences[0],
                root.allOccurrences[1],
            ]
        )

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


def exec_isolate(occs: list[fusion.Occurrence]) -> None:
    app: core.Application = core.Application.get()
    ui: core.UserInterface = app.userInterface
    sels: core.Selections = ui.activeSelections

    sels.clear()
    [sels.add(occ) for occ in occs]

    app.executeTextCommand(u"Commands.Start IsolateCmd")

    sels.clear()
Message 6 of 6
en9y37
in reply to: kandennti

Great @kandennti !!!!

 

That was a nice walkaround that worked for my needs.

 

Thanks a lot!!

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