highlighting a features

highlighting a features

Anonymous
Not applicable
981 Views
5 Replies
Message 1 of 6

highlighting a features

Anonymous
Not applicable

Hi  every body .. this forum is really help to me ... i have been learning a lot from this forum. thankyou soo much for all you help...!

          i need help in highlighting a feature in an occurrence....

 

here is the code i am using...  design file is attached below... keep the code and design file in the same directory... i want to highlight a feature named 'hole'  ...  

 

 

 

import adsk.core, adsk.fusion, traceback

import os.path, sys

numberOfTeeths = 25

internalDia = 10

def run(context):

ui = None

try:

app = adsk.core.Application.get()

ui = app.userInterface

 

# Get import manager

importManager = app.importManager

 

 

 

 

# Get active design

product = app.activeProduct

design = adsk.fusion.Design.cast(product)

 

# Get root component

rootComp = design.rootComponent

 

 

 

 

 

 

 

# Get archive import options and importing files

archiveFileName = os.path.join(os.path.dirname(os.path.realpath(__file__)), '1.f3d')

archiveOptions = importManager.createFusionArchiveImportOptions(archiveFileName)

 

#getting occurence

importManager.importToTarget(archiveOptions, rootComp)

pulleyOccurrence = rootComp.occurrences.item(rootComp.occurrences.count-1)

parametersList = pulleyOccurrence.component.parentDesign.allParameters

numberOfTeethspara = parametersList.itemByName('nt')

InternalDiapara = parametersList.itemByName('id')

numberOfTeethspara.expression = str(numberOfTeeths)

InternalDiapara.expression = str(internalDia)

 

 

 

 

 

pulleyComponent = pulleyOccurrence.component

holeFeature = pulleyComponent.features.extrudeFeatures.itemByName('hole')

 

 

 

 

 

 

 

except:

if ui:

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

 

0 Likes
Accepted solutions (1)
982 Views
5 Replies
Replies (5)
Message 2 of 6

marshaltu
Autodesk
Autodesk

Hello,

 

Please give a try and see if the following codes work for you. We had to wait for some time(e.g. 1s) before selecting "hole" feature because there was a timing issue. Otherwise the "hole" feature could not be highlighted in scene, only selected in timeline. You can extend the time longer if 1s doesn't work for you. 

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback
import os.path, sys, time
numberOfTeeths = 25
internalDia = 10
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
 
        # Get import manager
        importManager = app.importManager
        
        # Get active design
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        # Get root component
        rootComp = design.rootComponent
        
        # Get archive import options and importing files
        archiveFileName = os.path.join(os.path.dirname(os.path.realpath(__file__)), '1.f3d')
        archiveOptions = importManager.createFusionArchiveImportOptions(archiveFileName)
        
        #getting occurence
        importManager.importToTarget(archiveOptions, rootComp)
        pulleyOccurrence = rootComp.occurrences.item(rootComp.occurrences.count-1)
        parametersList = pulleyOccurrence.component.parentDesign.allParameters
        numberOfTeethspara = parametersList.itemByName('nt')
        InternalDiapara = parametersList.itemByName('id')
        numberOfTeethspara.expression = str(numberOfTeeths)
        InternalDiapara.expression = str(internalDia)
        
        for i in range(100):
            time.sleep(0.01)
            adsk.doEvents()
        
        pulleyComponent = pulleyOccurrence.component
        holeFeature = pulleyComponent.features.extrudeFeatures.itemByName('hole')
        
        holeFeatProxy = holeFeature.createForAssemblyContext(pulleyOccurrence)
        ui.activeSelections.add(holeFeatProxy)
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
Message 3 of 6

Anonymous
Not applicable

thankyou soo much .... its works perfectly ... but can you plz explain this part of code marked red .. i understand that  time.sleep is needed to give processor some time.. but the rest i dont understand... i actually wanted to use that hole feature and and a cylinder to make a revolute joint.. but could not select that hole feature... thankyou soo much for your help and time..!

 

 

for i in range(100):

time.sleep(0.01)

adsk.doEvents()

 

pulleyComponent = pulleyOccurrence.component

holeFeature = pulleyComponent.features.extrudeFeatures.itemByName('hole')

 

holeFeatProxy = holeFeature.createForAssemblyContext(pulleyOccurrence)

ui.activeSelections.add(holeFeatProxy)

0 Likes
Message 4 of 6

marshaltu
Autodesk
Autodesk

Hello,

 

"adsk.doEvents()" gives Fusion a chance to react during sleeping. We have some detailed description about the method in "Python Specific Issues" -> "Miscellaneous".

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-743C88FB-CA3F-44B0-B0B9-FCC378D0D782

 

A proxy object(extrude feature) with absolute path from root component is needed to create selection. Otherwise, "ui.activeSelections.add()" will fail. For proxy objects, please refer to the help "Document and Assembly Structure" for more details.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 5 of 6

marshaltu
Autodesk
Autodesk
Accepted solution

Hello,

 

I am aware there is no need to do sleep instead we can call adsk.doEvents() to let Fusion have a chance to refresh UI/finish compute. The codes look as below:

 

import adsk.core, adsk.fusion, traceback
import os.path, sys
numberOfTeeths = 25
internalDia = 10
def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
 
        # Get import manager
        importManager = app.importManager
        
        # Get active design
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        
        # Get root component
        rootComp = design.rootComponent
        
        # Get archive import options and importing files
        archiveFileName = os.path.join(os.path.dirname(os.path.realpath(__file__)), '1.f3d')
        archiveOptions = importManager.createFusionArchiveImportOptions(archiveFileName)
        
        #getting occurence
        importManager.importToTarget(archiveOptions, rootComp)
        pulleyOccurrence = rootComp.occurrences.item(rootComp.occurrences.count-1)
        parametersList = pulleyOccurrence.component.parentDesign.allParameters
        numberOfTeethspara = parametersList.itemByName('nt')
        InternalDiapara = parametersList.itemByName('id')
        numberOfTeethspara.expression = str(numberOfTeeths)
        InternalDiapara.expression = str(internalDia)
        
        adsk.doEvents()
        
        pulleyComponent = pulleyOccurrence.component
        holeFeature = pulleyComponent.features.extrudeFeatures.itemByName('hole')
        
        holeFeatProxy = holeFeature.createForAssemblyContext(pulleyOccurrence)
        ui.activeSelections.add(holeFeatProxy)
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
Message 6 of 6

Anonymous
Not applicable

thank you soo much sir

0 Likes