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

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

david.lopez7E84R
Explorer Explorer
728 Views
3 Replies
Message 1 of 4

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

david.lopez7E84R
Explorer
Explorer

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?

0 Likes
Accepted solutions (1)
729 Views
3 Replies
  • API
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor
Accepted solution

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

david.lopez7E84R
Explorer
Explorer

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?

0 Likes
Message 4 of 4

BrianEkins
Mentor
Mentor

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