How to create threaded hole feature

jsormaz
Advocate Advocate
440 Views
3 Replies
Message 1 of 4

How to create threaded hole feature

jsormaz
Advocate
Advocate

I am trying to create a custom threaded hole feature. Here is what I have so far. 

 

It successfully creates the hole feature, but I can't figure out the API to add a thread to the hole. In general ThreadFeature doesn't seem very well documented.

 

I get an Exception at the last line below:

 

def command_created(args: adsk.core.CommandCreatedEventArgs):
    inputs = args.command.commandInputs

    inputs.addSelectionInput("point_selection", "Select Points", "Select points")

    point_selection: adsk.core.SelectionCommandInput = inputs.itemById(
        "point_selection"
    )
    point_selection.addSelectionFilter("SketchPoints")
    point_selection.setSelectionLimits(1, 0)

    futil.add_handler(
        args.command.execute, command_execute, local_handlers=local_handlers
    )

 

 

 

def command_execute(args: adsk.core.CommandEventArgs):
    inputs = args.command.commandInputs
    point_selection: adsk.core.SelectionCommandInput = inputs.itemById(
        "point_selection"
    )

    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    rootComp = design.rootComponent

    holeFeatures = rootComp.features.holeFeatures
    holeInput = holeFeatures.createCounterboreInput(
        adsk.core.ValueInput.createByString("8.526 mm"),
        adsk.core.ValueInput.createByString("16 mm"),
        adsk.core.ValueInput.createByString("6 mm"),
    )

    holeInput.setDistanceExtent(
        adsk.core.ValueInput.createByString("28 mm"),
    )

    pointCollection = adsk.core.ObjectCollection.create()
    for p in range(point_selection.selectionCount):
        pointCollection.add(point_selection.selection(p).entity)

    holeInput.setPositionBySketchPoints(pointCollection)

    holeFeature = holeFeatures.add(holeInput)
    # All above is working

    threadFeatures = rootComp.features.threadFeatures

    threadType = "ISO Metric profile"
    threadClass = "6H"
    threadDesignation = "M10x1.5"

    holeFaces = adsk.core.ObjectCollection.create()
    for h in range(holeFeature.sideFaces.count):
        holeFaces.add(holeFeature.sideFaces.item(h))
    if holeFaces.count > 0:
        threadInfo = threadFeatures.createThreadInfo(
            True, threadType, threadDesignation, threadClass
        )
        threadInput = threadFeatures.createInput(holeFaces, threadInfo)
        threadInput.isModeled = False

        threadFeature = threadFeatures.add(threadInput)#This line raises an Exception
# RuntimeError: 2 : InternalValidationError : Xl::Utils::getObjectPath(item.get(), facePath, nullptr, contextPath)

 

FWIW, i'm trying to make the following counterbored threaded hole for Lang quick-point studs

 

jsormaz_0-1708544678466.png

And this is the end result I would like:

jsormaz_1-1708545445584.png

 

Instagram:
@sonsofsormaz
0 Likes
441 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

Unfortunately, you can't create a thread as part of a hole feature. In the early days of Fusion, you had to add a thread feature to a hole to create a hole with a thread. The hole API hasn't been updated since the hole feature was enhanced. Hopefully, it's coming soon. 

 

The current workaround is to create a separate thread feature.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 4

john.kirchner
Autodesk
Autodesk

I think I got your script to run successfully on a quick test file I set up - is there any chance you could share an f3d file where you are getting this error?



0 Likes
Message 4 of 4

jsormaz
Advocate
Advocate

@BrianEkins thanks, at least good to know I'm not crazy. Is it not still possible to add a separate thread feature though?

 

@john.kirchner See attached.

Just run the command, select the 4 points in 'Sketch2' and you should get the error.

Instagram:
@sonsofsormaz
0 Likes