Get Selected Feature Properties From a Thread Feature

Get Selected Feature Properties From a Thread Feature

mike
Contributor Contributor
657 Views
2 Replies
Message 1 of 3

Get Selected Feature Properties From a Thread Feature

mike
Contributor
Contributor

I'm trying to write a script that will automatically generate a thread undercut for when machining a thread on a lathe.

 

Is it possible to retrieve the thread properties after the thread feature has been selected in the command window. Such as;

 

selectionInput = inputs.addSelectionInput(commandId + '_selection', 'Select', 'Select bodies or occurrences')
selectionInput.setSelectionLimits(1)
selectionInput.selectionFilters = ['Features', 'Occurrences']

 

#Once thread feature has been selected retrieve the thread pitch and thread size e.g Size M6 ; Thread 1mm.

 

Thank you in advance

0 Likes
Accepted solutions (1)
658 Views
2 Replies
Replies (2)
Message 2 of 3

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

Try this:

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:

        app = adsk.core.Application.get()
        ui = app.userInterface

        try:
            selection = ui.selectEntity('Select a thread feature', 'Features')
        except:
            selection = None

        if selection:
            threadFeature = selection.entity
            ui.messageBox('Thread pitch: {}\nThread size: {}'.format(threadFeature.threadInfo.threadPitch, threadFeature.threadInfo.threadSize))

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

 

See ThreadFeature object documentation.

 

0 Likes
Message 3 of 3

mike
Contributor
Contributor

Thank you for the assistance, it's much appreciated

0 Likes