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: 

Count property is not working

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
kandennti
245 Views, 2 Replies

Count property is not working

I added it to the end of this sample code,
An error occurs in the Count property.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-50d8227e-ee3e-11e4-ab7c-3417ebd3d5be 

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
         # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
 
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)

        # Get the root component of the active design
        rootComp = design.rootComponent
        
        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(0, 0, 0)
        sketchCircles.addByCenterRadius(centerPoint, 5.0)
        
        # Get the profile defined by the circle
        prof = sketch.profiles.item(0)

        # Create an extrusion input
        extrudes = rootComp.features.extrudeFeatures
        extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        
        # Define that the extent is a distance extent of 5 cm
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(True, distance)

        # Create the extrusion
        ext = extrudes.add(extInput)

        # Get the body created by the extrusion
        body = ext.bodies.item(0)
        
        # Create SplitBodyFeatureInput
        splitBodyFeats = rootComp.features.splitBodyFeatures
        splitBodyInput = splitBodyFeats.createInput(body, rootComp.xZConstructionPlane, True)
        
        # Create split body feature
        splitBodyFeats.add(splitBodyInput)

        # ↓It's not working
        ui.messageBox(splitBodyFeats.count)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

The version of Fusion360 is 2.0.6516.
It doesn't seem to work with many collections, not just splitBodyFeats.

2 REPLIES 2
Message 2 of 3
JeromeBriot
in reply to: kandennti

Hello,

 

The Count property returns an integer. So you have to format the value:

 

ui.messageBox('{}'.format(splitBodyFeats.count))
Message 3 of 3
kandennti
in reply to: JeromeBriot

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