How to directly access thread paramters of a bolt using the API script ?

How to directly access thread paramters of a bolt using the API script ?

f20212766GTEE9
Explorer Explorer
275 Views
2 Replies
Message 1 of 3

How to directly access thread paramters of a bolt using the API script ?

f20212766GTEE9
Explorer
Explorer

I am working on bolt classification problem involving to generate a labelled dataset as a CAD classifier,  I need to generate a dataset of 1000 different bolts with varying parameters like diameter, thread features like pitch , length of the bolt etc using an API script. I am facing difficulty in directly accessing the thread features using the script, since in the sample bolt script given on fusion, the thread features are accessed indirectly by this piece of code:

threads = newComp.features.threadFeatures
threadDataQuery = threads.threadDataQuery
defaultThreadType = threadDataQuery.defaultMetricThreadType
recommendData = threadDataQuery.recommendThreadData(self.bodyDiameter, False, defaultThreadType)
if recommendData[0] :
threadInfo = threads.createThreadInfo(False, defaultThreadType, recommendData[1], recommendData[2])
faces = adsk.core.ObjectCollection.create()
faces.add(sideFace)
threadInput = threads.createInput(faces, threadInfo
threads.add(threadInput)                                                                                                                                                                    I am looking for a way to somehow access the thread info, be able to look in what thread features are available and be able to choose from them in order to generate my dataset. It would be great if someone could help me out here with the API script for this
    
 
0 Likes
276 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

All of the threads are defined in XML files that are delivered with Fusion. You can find them here:

C:\Users\<username>\AppData\Local\Autodesk\webdeploy\production\<VersionSpecificID>\Fusion\Server\Fusion\Configuration\ThreadData

 

The ThreadDataQuery object in the API allows you to query these XML files using the API to get valid thread information.

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

f20212766GTEE9
Explorer
Explorer

Thank you for that answer, i was able to locate the xml files. I am kind off facing issues in the script part where i want to query threads with different pitch each time it is generated.  

sideFace = bodyExt.sideFaces[0]

threads = newComp.features.threadFeatures

threadDataQuery = threads.threadDataQuery

defaultThreadType = threadDataQuery.defaultMetricThreadType

recommendData = threadDataQuery.recommendThreadData(self.bodyDiameter, False, defaultThreadType)

if recommendData[0] : threadInfo = threads.createThreadInfo(False, defaultThreadType, recommendData[1], recommendData[2]) faces = adsk.core.ObjectCollection.create() faces.add(sideFace) threadInput = threads.createInput(faces, threadInfo) threads.add(threadInput) except: if ui: ui.messageBox('Failed to compute the bolt. This is most likely because the input values define an invalid bolt.')

On changing the recommendData[0] , recommendData[1], recommendData[2] to any other values, fusion throws an error saying invalid params and genarates a plain bolt without any threads. can you please help me with this?

 

0 Likes