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 get the depth of a hole from a from model parameters?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
david.lopez7E84R
172 Views, 3 Replies

how to get the depth of a hole from a from model parameters?

I can get counterbore hole depth and diameter to include the hole's diameter using:

 

hole_dia = adsk.fusion.Design.cast(self.app.activeProduct).features.holeFeatures.item(0).holeDiameter.expression

cb_depth = adsk.fusion.Design.cast(self.app.activeProduct).features.holeFeatures.item(0).counterboreDepth.expression

cs_dia = adsk.fusion.Design.cast(self.app.activeProduct).features.holeFeatures.item(0).countersinkDiameter.expression

I need to figure out how to consistently get the depth of the hole because that measurement is not readily available.

My issue isn't so much in getting the depth of the hole, I can see the values I need in a number of ways, the problem is mapping the value in a consistent way that lets me get the value the same way in my script to automate the identification of feature in a part designed in fusion. For example, I can get the depth of the hole in a series of timeline values returned in the order the parameter and its name were drawn:


param_name = adsk.fusion.Design.cast(self.app.activeProduct).allParameters.item(0).name

 

The problem is that the name parameter is not the name field available the way item(0).name is available for Hole1. Please see this picture:

Screen Shot 2022-10-12 at 9.14.59 PM.png

 

the HoleDepth ParameterName is what Im after, I want to iterate through those names with a for loop at the same time I am iterating through the values I am identifying for the other dimensions so I can map the correct dimensions together.

any other way to get the length of the hole?

Labels (1)
  • API
3 REPLIES 3
Message 2 of 4

Hi @david.lopez7E84R .

 

How about this?

# 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
        root: adsk.fusion.Component = des.rootComponent

        for holeFeat in root.features.holeFeatures:
            msg = f'{holeFeat.name} - {holeFeat.extentDefinition.distance.expression}'
            app.log(msg)

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

 

 

Message 3 of 4

wow

 

thats the solution I was expecting however, it wasn't showing up in the visual studio drop down as an available option and I assumed there was no distance measurement and expression values

I only tried it because you proposed it as a solution; I am relying too much on the suggested methods!!

Maybe we found a bug to report?

Message 4 of 4

What you're seeing isn't a bug. The depth of a hole can be defined in several different ways; a specific depth, through all, to a face, etc. The HoleFeature has the extentDefinition property that returns an ExtentDefinition object. The ExtentDefinition object is the base class and what's really returned is a DistanceExtentDefinition, ToEntityExtentDefinition, or ThroughAllExtentDefinition. What you get back will be determined at runtime based on how the hole was created. In your case, you only want to handle if a DistanceExtentDefinition object is returned because it's the only type that has the distance property.

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