Я столкнулся с проблемами в части сценария, когда мне нужно запрашивать потоки с разным шагом каждый раз, когда они создаются.
sideFace = bodyExt.sideFaces[0] >
threads = newComp.features.threadFeatures
threadDataQuery = threads.threadDataQuery
defaultThreadType = threadDataQuery.defaultMetricThreadType
recommendData = threadDataQuery.recommendThreadData(self.bodyDiameter, False, defaultThreadType)
ifrecommendData[0] : threadInfo = threads.createThreadInfo(False, defaultThreadType, рекомендованные данные) [1],рекомендоватьДанные[2])faces =adsk.core.ObjectCollection.create()faces.add(sideFace) threadInput = threads.createInput(faces, threadInfo) threads.add(threadInput), за исключением: if ui: ui.messageBox («Не удалось вычислить болт. Скорее всего, это связано с тем, что входные значения определяют недопустимый болт».)
Полагаю, мне придется внести изменения в эту часть примера сценария, который я взял со страницы документации продукта pf fusion 360, но при изменении рекомендованных данных[0] , рекомендованных данных[1], рекомендованных данных[2] на любые другие значения, такие как рекомендованные данные[3] или рекомендуемыеДанные[4], fusion выдает ошибку, сообщающую о недопустимости params и генерирует простой болт без каких-либо потоков. Мне известно о том, что все определения потоков хранятся в файлах XML, где объект ThreadDataQuery в API позволяет запрашивать эти файлы XML. Как запрашивать файлы XML по порядку изменить шаг генерируемого болта?
Я прикрепляю ниже файл metricTappingThreadsForPlastics.xml и сценарий, с которым у меня возникла проблема, в виде двух блоков кода. Можете ли вы помочь мне с частью сценария, предложив изменения в том, как можно изменить шаг резьбы при создании болтов с помощью сценария, пожалуйста?
& l t ; T h r e a d T y p e & g t ; < b r / > & l t ; N a m e & g t ; M e t r i c T a p p i n g T h r e a d s f o r P l a s t i c s & l t ; / N a m e & g t ; < b r / > & l t ; C u s t o m N a m e & g t ; M e t r i c T a p p i n g T h r e a d s f o r P l a s t i c s & l t ; / C u s t o m N a m e & g t ; < b r / > & l t ; U n i t & g t ; m m & l t ; / U n i t & g t ; < b r / > & l t ; A n g l e & g t ; 3 0 & l t ; / A n g l e & g t ; < b r / > & l t ; S o r t O r d e r & g t ; 2 6 & l t ; / S o r t O r d e r & g t ; < b r / > & l t ; E x t e r n a l O n l y & g t ; y e s & l t ; / E x t e r n a l O n l y & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 x 0 . 4 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 x 0 . 4 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 4 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 0 . 8 2 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 6 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 2 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 2 x 0 . 5 1 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 2 x 0 . 5 1 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 5 1 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 2 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 0 . 9 9 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 7 8 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 2 x 0 . 5 3 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 2 x 0 . 5 3 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 5 3 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 2 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 0 . 9 7 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 7 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 4 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 4 x 0 . 5 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 4 x 0 . 5 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 5 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 4 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 1 6 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 9 3 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 4 x 0 . 6 2 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 4 x 0 . 6 2 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 2 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 4 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 1 2 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 8 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 5 x 0 . 6 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 5 x 0 . 6 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 1 9 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 8 9 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 6 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 6 x 0 . 6 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 6 x 0 . 6 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 6 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 3 3 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 0 7 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 6 x 0 . 6 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 6 x 0 . 6 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 6 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 2 6 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 9 2 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 8 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 8 x 0 . 7 1 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 8 x 0 . 7 1 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 7 1 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 8 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 5 1 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 2 2 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 8 x 0 . 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 8 x 0 . 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 8 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 4 2 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 0 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 2 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 x 0 . 7 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 x 0 . 7 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 7 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 6 8 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 3 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 x 0 . 8 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 x 0 . 8 9 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 8 9 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 5 7 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 1 5 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 2 . 2 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 2 x 0 . 8 5 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 2 x 0 . 8 5 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 8 5 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 2 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 8 5 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 5 1 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 2 x 0 . 9 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 2 x 0 . 9 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 9 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 2 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 7 7 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 2 5 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 2 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 5 x 0 . 9 5 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 5 x 0 . 9 5 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 9 5 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 5 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 7 6 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 7 2 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 5 x 1 . 1 2 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 5 x 1 . 1 2 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 1 2 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 5 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 9 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 4 0 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 3 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 x 1 . 1 2 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 x 1 . 1 2 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 1 2 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 5 4 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 0 9 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 x 1 . 3 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 x 1 . 3 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 3 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 7 3 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 6 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 3 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 . 5 x 1 . 2 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 . 5 x 1 . 2 9 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 2 9 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 9 7 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 4 5 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 . 5 x 1 . 5 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 . 5 x 1 . 5 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 5 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 5 8 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 6 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 4 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 4 x 1 . 4 6 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 4 x 1 . 4 6 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 4 6 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 4 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 4 0 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 8 1 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 4 x 1 . 7 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 4 x 1 . 7 9 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 7 9 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 4 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 3 4 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 1 7 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 4 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 4 . 5 x 1 . 6 3 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 4 . 5 x 1 . 6 3 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 6 3 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 4 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 8 3 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 3 . 1 7 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 5 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 5 x 1 . 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 5 x 1 . 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 5 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 4 . 7 6 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 3 . 5 3 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 5 x 2 . 2 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 5 x 2 . 2 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 2 . 2 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 5 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 8 4 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 6 8 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 6 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 6 x 2 . 1 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 6 x 2 . 1 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 2 . 1 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 6 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 5 . 6 3 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 4 . 2 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 6 x 2 . 6 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 6 x 2 . 6 9 & l t ; / C TD>
2.69
external
h14
6.0
4.595
3.19
7.0
7x2.48
7x2.48
2.48
external
h14
7.0
5.99
4.98
7x3.14
7x3.14
3.14
external
h14
7.0
5.85
3.7
8.0
8x2.82
8x2.82
2.82
external
h14
8.0
6.85
5.7
8x3.59
8x3.59
3.59
external
h14
8.0
6.105
4.21
9.0
9x3.24
9x3.24
3.24
external
h14
9.0
7.699
6.399
9x4
9x4
4
external
h14
9.0
6.715
4.43
10.0
10x3.6
10x3.6
3.6
external
h14
10.0
8.555
7.11
10x4.49
10x4.49
4.49
external
h14
10.0
7.615
5.23
Текущий скрипт не может создать ни одного болта с резьбой
import adsk.core, adsk.fusion, traceback
import math
import random
import time
import os
import json
defaultBoltName = 'Bolt'
defaultHeadDiameter = 0.75
defaultBodyDiameter = 0.5
defaultHeadHeight = 0.3125
defaultBodyLength = 1.0
defaultCutAngle = 30.0 * (math.pi / 180)
defaultChamferDistance = 0.03845
defaultFilletRadius = 0.02994
# Define metric thread data from XML
METRIC_THREAD_DATA = {
1.0: [0.44],
1.2: [0.51, 0.53],
1.4: [0.57, 0.62],
1.5: [0.67],
1.6: [0.64, 0.67],
1.8: [0.71, 0.8],
2.0: [0.78, 0.89],
2.2: [0.85, 0.98],
2.5: [0.95, 1.12],
3.0: [1.12, 1.34],
3.5: [1.29, 1.57],
4.0: [1.46, 1.79],
4.5: [1.63],
5.0: [1.8, 2.24],
6.0: [2.14, 2.69],
7.0: [2.48, 3.14],
8.0: [2.82, 3.59],
9.0: [3.24, 4.0],
10.0: [3.6, 4.49]
}
handlers = []
app = adsk.core.Application.get()
if app:
ui = app.userInterface
class ThreadData:
def __init__(self, threadFeatures):
self.threadFeatures = threadFeatures
self.threadDataQuery = threadFeatures.threadDataQuery
def getThreadInfoForDiameter(self, diameter_inches):
# Convert inches to mm for metric thread lookup
diameter_mm = diameter_inches * 25.4
# Find closest available diameter
available_diameters = list(METRIC_THREAD_DATA.keys())
closest_diameter = min(available_diameters, key=lambda x: abs(x - diameter_mm))
if abs(closest_diameter - diameter_mm) > 0.5: # If no close match found
return None
# Get available pitches for this diameter
available_pitches = METRIC_THREAD_DATA[closest_diameter]
selected_pitch = random.choice(available_pitches)
# Create thread info
threadInfo = self.threadFeatures.createThreadInfo(
False,
"Metric Tapping Threads for Plastics",
f"{closest_diameter}x{selected_pitch}",
"h14"
)
return threadInfo
class Bolt:
def __init__(self):
self._boltName = defaultBoltName
self._headDiameter = defaultHeadDiameter
self._bodyDiameter = defaultBodyDiameter
self._headHeight = defaultHeadHeight
self._bodyLength = adsk.core.ValueInput.createByReal(defaultBodyLength)
self._cutAngle = defaultCutAngle
self._chamferDistance = adsk.core.ValueInput.createByReal(defaultChamferDistance)
self._filletRadius = adsk.core.ValueInput.createByReal(defaultFilletRadius)
# Property getters and setters remain the same as in your original code
@property
def boltName(self):
return self._boltName
@boltName.setter
def boltName(self, value):
self._boltName = value
@property
def headDiameter(self):
return self._headDiameter
@headDiameter.setter
def headDiameter(self, value):
self._headDiameter = value
@property
def bodyDiameter(self):
return self._bodyDiameter
@bodyDiameter.setter
def bodyDiameter(self, value):
self._bodyDiameter = value
@property
def headHeight(self):
return self._headHeight
@headHeight.setter
def headHeight(self, value):
self._headHeight = value
@property
def bodyLength(self):
return self._bodyLength
@bodyLength.setter
def bodyLength(self, value):
self._bodyLength = value
@property
def cutAngle(self):
return self._cutAngle
@cutAngle.setter
def cutAngle(self, value):
self._cutAngle = value
@property
def chamferDistance(self):
return self._chamferDistance
@chamferDistance.setter
def chamferDistance(self, value):
self._chamferDistance = value
@property
def filletRadius(self):
return self._filletRadius
@filletRadius.setter
def filletRadius(self, value):
self._filletRadius = value
def buildBolt(self, component, threadData):
try:
newComp = component
# Create hexagonal head and body (same as original code)
sketches = newComp.sketches
xyPlane = newComp.xYConstructionPlane
xzPlane = newComp.xZConstructionPlane
sketch = sketches.add(xyPlane)
center = adsk.core.Point3D.create(0, 0, 0)
# Create hexagonal head
vertices = []
for i in range(6):
vertex = adsk.core.Point3D.create(
center.x + (self.headDiameter/2) * math.cos(math.pi * i / 3),
center.y + (self.headDiameter/2) * math.sin(math.pi * i / 3),
0
)
vertices.append(vertex)
for i in range(6):
sketch.sketchCurves.sketchLines.addByTwoPoints(vertices[(i+1) % 6], vertices)
# Extrude head
extrudes = newComp.features.extrudeFeatures
prof = sketch.profiles[0]
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(self.headHeight)
extInput.setDistanceExtent(False, distance)
headExt = extrudes.add(extInput)
# Name the body
fc = headExt.faces[0]
bd = fc.body
bd.name = self.boltName
# Create the body
bodySketch = sketches.add(xyPlane)
bodySketch.sketchCurves.sketchCircles.addByCenterRadius(center, self.bodyDiameter/2)
bodyProf = bodySketch.profiles[0]
bodyExtInput = extrudes.createInput(bodyProf, adsk.fusion.FeatureOperations.JoinFeatureOperation)
bodyExtInput.setAllExtent(adsk.fusion.ExtentDirections.NegativeExtentDirection)
bodyExtInput.setDistanceExtent(False, self.bodyLength)
bodyExt = extrudes.add(bodyExtInput)
# Create chamfer and fillet (same as original code)
edgeCol = adsk.core.ObjectCollection.create()
edges = bodyExt.endFaces[0].edges
for edgeI in edges:
edgeCol.add(edgeI)
chamferFeats = newComp.features.chamferFeatures
chamferInput = chamferFeats.createInput(edgeCol, True)
chamferInput.setToEqualDistance(self.chamferDistance)
chamferFeats.add(chamferInput)
# Create fillet
edgeCol.clear()
loops = headExt.endFaces[0].loops
for edgeLoop in loops:
if len(edgeLoop.edges) == 1:
edgeCol.add(edgeLoop.edges[0])
break
filletFeats = newComp.features.filletFeatures
filletInput = filletFeats.createInput()
filletInput.addConstantRadiusEdgeSet(edgeCol, self.filletRadius, True)
filletFeats.add(filletInput)
# Create revolve features for bolt head
self.createRevolveFeature(newComp, xzPlane, center, self.headDiameter/2, self.headHeight, self.cutAngle)
# Create thread feature using ThreadData
sideFace = bodyExt.sideFaces[0]
threads = newComp.features.threadFeatures
# Get appropriate thread info for the bolt diameter
threadInfo = threadData.getRandomThreadInfo(
threads,
self.bodyDiameter * 0.9, # Allow some tolerance
self.bodyDiameter * 1.1
)
if threadInfo:
faces = adsk.core.ObjectCollection.create()
faces.add(sideFace)
threadInput = threads.createInput(faces, threadInfo)
threadInput.isModeled = True
threadInput.threadLength = self.bodyLength
threads.add(threadInput)
return True
except:
if ui:
ui.messageBox(f'Failed to compute the bolt {self.boltName}. This is most likely because the input values define an invalid bolt.')
return False
def createRevolveFeature(self, component, plane, center, radius, height, angle):
sketches = component.sketches
revolveSketch = sketches.add(plane)
point1 = revolveSketch.modelToSketchSpace(adsk.core.Point3D.create(center.x + radius*math.cos(math.pi/6), 0, center.y))
point2 = revolveSketch.modelToSketchSpace(adsk.core.Point3D.create(center.x + radius, 0, center.y))
point3 = revolveSketch.modelToSketchSpace(adsk.core.Point3D.create(point2.x, 0, (point2.x - point1.x) * math.tan(angle)))
revolveSketch.sketchCurves.sketchLines.addByTwoPoints(point1, point2)
revolveSketch.sketchCurves.sketchLines.addByTwoPoints(point2, point3)
revolveSketch.sketchCurves.sketchLines.addByTwoPoints(point3, point1)
zAxis = component.zConstructionAxis
revolves = component.features.revolveFeatures
revProf = revolveSketch.profiles[0]
revInput = revolves.createInput(revProf, zAxis, adsk.fusion.FeatureOperations.CutFeatureOperation)
revAngle = adsk.core.ValueInput.createByReal(math.pi*2)
revInput.setAngleExtent(False, revAngle)
revolves.add(revInput)
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('Please switch to MODEL workspace and try again.')
return
root = design.rootComponent
threadData = ThreadData(root.features.threadFeatures)
def generate_valid_bolt_params(index):
# Generate base diameter in inches (converted from mm range 1-10mm)
min_diameter_inch = 1.0 / 25.4 # 1mm in inches
max_diameter_inch = 10.0 / 25.4 # 10mm in inches
# Generate random body diameter within valid range
body_diameter = random.uniform(min_diameter_inch, max_diameter_inch)
#Standard proportions based on body diameter
head_diameter = body_diameter * 1.5
head_height = body_diameter * 0.625
body_length = body_diameter * 2.0
# Small variations in chamfer and fillet (proportional to body diameter)
chamfer_distance = body_diameter * 0.077
fillet_radius = body_diameter * 0.06
# Add very small random variations
variation = 0.001
return {
'name': f'Bolt{index}',
'headDiameter': head_diameter * (1 + random.uniform(-variation, variation)),
'bodyDiameter': body_diameter, # Keep exact for thread matching
'headHeight': head_height * (1 + random.uniform(-variation, variation)),
'bodyLength': body_length * (1 + random.uniform(-variation, variation)),
'cutAngle': 30.0 * (math.pi / 180),
'chamferDistance': chamfer_distance * (1 + random.uniform(-variation, variation)),
'filletRadius': fillet_radius * (1 + random.uniform(-variation, variation))
}
def create_bolt(params, x, y, z):
try:
bolt = Bolt()
bolt.boltName = params['name']
bolt.headDiameter = params['headDiameter']
bolt.bodyDiameter = params['bodyDiameter']
bolt.headHeight = params['headHeight']
bolt.bodyLength = adsk.core.ValueInput.createByReal(params['bodyLength'])
bolt.cutAngle = params['cutAngle']
bolt.chamferDistance = adsk.core.ValueInput.createByReal(params['chamferDistance'])
bolt.filletRadius = adsk.core.ValueInput.createByReal(params['filletRadius'])
transform = adsk.core.Matrix3D.create()
transform.translation = adsk.core.Vector3D.create(x, y, z)
boltOcc = root.occurrences.addNewComponent(transform)
success = bolt.buildBolt(boltOcc.component, threadData)
if success:
export_as_stl(boltOcc.component, params['name'])
else:
if boltOcc:
boltOcc.deleteMe()
return success
except:
print(f"Failed to create bolt: {params['name']}")
if 'boltOcc' in locals() and boltOcc:
boltOcc.deleteMe()
return False
# Generate bolts
num_bolts = 10
grid_size = int(num_bolts ** 0.5) + 1
spacing = 2.0
successful_bolts = 0
start_time = time.time()
for i in range(num_bolts):
params = generate_valid_bolt_params(current_bolt_count + i + 1)
row = i // grid_size
col = i % grid_size
x = col * spacing
y = row * spacing
z = 0
if create_bolt(params, x, y, z):
successful_bolts += 1
print(f"Successfully created bolt {params['name']}")
else:
print(f"Failed to create bolt {params['name']}")
if (i + 1) % (num_bolts // 10) == 0:
progress = (i + 1) / num_bolts * 100
elapsed_time = time.time() - start_time
estimated_total_time = elapsed_time / (progress / 100)
remaining_time = estimated_total_time - elapsed_time
print(f"Progress: {progress:.1f}% - Estimated time remaining: {remaining_time:.1f} seconds")
adsk.doEvents()
total_time = time.time() - start_time
# Update and save configuration
current_bolt_count += successful_bolts
random_seed = random.randint(0, 1000000)
config = {'bolt_count': current_bolt_count, 'random_seed': random_seed}
with open(config_file, 'w') as f:
json.dump(config, f)
ui.messageBox(f'Created and exported {successful_bolts} bolts successfully.\n'
f'Total bolts created so far: {current_bolt_count}\n'
f'Total time taken: {total_time:.1f} seconds\n'
f'STL files are saved in the "stl_files" folder on your desktop.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Подробнее здесь: https://stackoverflow.com/questions/791 ... api-script
Как изменить параметры резьбы, такие как шаг, с помощью сценария API? ⇐ Python
Программы на Python
1730791954
Anonymous
Я столкнулся с проблемами в части сценария, когда мне нужно запрашивать потоки с разным шагом каждый раз, когда они создаются.
sideFace = bodyExt.sideFaces[0] >
threads = newComp.features.threadFeatures
threadDataQuery = threads.threadDataQuery
defaultThreadType = threadDataQuery.defaultMetricThreadType
recommendData = threadDataQuery.recommendThreadData(self.bodyDiameter, False, defaultThreadType)
ifrecommendData[0] : threadInfo = threads.createThreadInfo(False, defaultThreadType, рекомендованные данные) [1],рекомендоватьДанные[2])faces =adsk.core.ObjectCollection.create()faces.add(sideFace) threadInput = threads.createInput(faces, threadInfo) threads.add(threadInput), за исключением: if ui: ui.messageBox («Не удалось вычислить болт. Скорее всего, это связано с тем, что входные значения определяют недопустимый болт».)
Полагаю, мне придется внести изменения в эту часть примера сценария, который я взял со страницы документации продукта pf fusion 360, но при изменении рекомендованных данных[0] , рекомендованных данных[1], рекомендованных данных[2] на любые другие значения, такие как рекомендованные данные[3] или рекомендуемыеДанные[4], fusion выдает ошибку, сообщающую о недопустимости params и генерирует простой болт без каких-либо потоков. Мне известно о том, что все определения потоков хранятся в файлах XML, где объект ThreadDataQuery в API позволяет запрашивать эти файлы XML. Как запрашивать файлы XML по порядку изменить шаг генерируемого болта?
Я прикрепляю ниже файл metricTappingThreadsForPlastics.xml и сценарий, с которым у меня возникла проблема, в виде двух блоков кода. Можете ли вы помочь мне с частью сценария, предложив изменения в том, как можно изменить шаг резьбы при создании болтов с помощью сценария, пожалуйста?
& l t ; T h r e a d T y p e & g t ; < b r / > & l t ; N a m e & g t ; M e t r i c T a p p i n g T h r e a d s f o r P l a s t i c s & l t ; / N a m e & g t ; < b r / > & l t ; C u s t o m N a m e & g t ; M e t r i c T a p p i n g T h r e a d s f o r P l a s t i c s & l t ; / C u s t o m N a m e & g t ; < b r / > & l t ; U n i t & g t ; m m & l t ; / U n i t & g t ; < b r / > & l t ; A n g l e & g t ; 3 0 & l t ; / A n g l e & g t ; < b r / > & l t ; S o r t O r d e r & g t ; 2 6 & l t ; / S o r t O r d e r & g t ; < b r / > & l t ; E x t e r n a l O n l y & g t ; y e s & l t ; / E x t e r n a l O n l y & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 x 0 . 4 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 x 0 . 4 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 4 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 0 . 8 2 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 6 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 2 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 2 x 0 . 5 1 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 2 x 0 . 5 1 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 5 1 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 2 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 0 . 9 9 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 7 8 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 2 x 0 . 5 3 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 2 x 0 . 5 3 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 5 3 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 2 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 0 . 9 7 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 7 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 4 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 4 x 0 . 5 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 4 x 0 . 5 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 5 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 4 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 1 6 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 9 3 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 4 x 0 . 6 2 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 4 x 0 . 6 2 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 2 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 4 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 1 2 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 8 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 5 x 0 . 6 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 5 x 0 . 6 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 1 9 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 8 9 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 6 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 6 x 0 . 6 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 6 x 0 . 6 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 6 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 3 3 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 0 7 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 6 x 0 . 6 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 6 x 0 . 6 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 6 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 6 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 2 6 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 0 . 9 2 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 1 . 8 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 8 x 0 . 7 1 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 8 x 0 . 7 1 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 7 1 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 8 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 5 1 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 2 2 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 1 . 8 x 0 . 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 1 . 8 x 0 . 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 1 . 8 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 4 2 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 0 4 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 2 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 x 0 . 7 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 x 0 . 7 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 7 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 6 8 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 3 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 x 0 . 8 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 x 0 . 8 9 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 8 9 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 5 7 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 1 5 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 2 . 2 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 2 x 0 . 8 5 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 2 x 0 . 8 5 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 8 5 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 2 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 8 5 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 5 1 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 2 x 0 . 9 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 2 x 0 . 9 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 9 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 2 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 7 7 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 2 5 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 2 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 5 x 0 . 9 5 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 5 x 0 . 9 5 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 0 . 9 5 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 5 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 7 6 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 7 2 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 2 . 5 x 1 . 1 2 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 2 . 5 x 1 . 1 2 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 1 2 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 2 . 5 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 1 . 9 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 4 0 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 3 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 x 1 . 1 2 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 x 1 . 1 2 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 1 2 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 5 4 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 0 9 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 x 1 . 3 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 x 1 . 3 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 3 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 0 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 7 3 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 6 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 3 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 . 5 x 1 . 2 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 . 5 x 1 . 2 9 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 2 9 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 9 7 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 4 5 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 3 . 5 x 1 . 5 7 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 3 . 5 x 1 . 5 7 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 5 7 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 3 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 2 . 5 8 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 1 . 6 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 4 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 4 x 1 . 4 6 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 4 x 1 . 4 6 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 4 6 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 4 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 4 0 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 8 1 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 4 x 1 . 7 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 4 x 1 . 7 9 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 7 9 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 4 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 3 4 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 1 7 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 4 . 5 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 4 . 5 x 1 . 6 3 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 4 . 5 x 1 . 6 3 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 6 3 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 4 . 5 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 8 3 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 3 . 1 7 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 5 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 5 x 1 . 8 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 5 x 1 . 8 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 1 . 8 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 5 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 4 . 7 6 5 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 3 . 5 3 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 5 x 2 . 2 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 5 x 2 . 2 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 2 . 2 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 5 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 3 . 8 4 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 2 . 6 8 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; / T h r e a d S i z e & g t ; < b r / > & l t ; T h r e a d S i z e & g t ; < b r / > & l t ; S i z e & g t ; 6 . 0 & l t ; / S i z e & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 6 x 2 . 1 4 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 6 x 2 . 1 4 & l t ; / C T D & g t ; < b r / > & l t ; P i t c h & g t ; 2 . 1 4 & l t ; / P i t c h & g t ; < b r / > & l t ; T h r e a d & g t ; < b r / > & l t ; G e n d e r & g t ; e x t e r n a l & l t ; / G e n d e r & g t ; < b r / > & l t ; C l a s s & g t ; h 1 4 & l t ; / C l a s s & g t ; < b r / > & l t ; M a j o r D i a & g t ; 6 . 0 & l t ; / M a j o r D i a & g t ; < b r / > & l t ; P i t c h D i a & g t ; 5 . 6 3 & l t ; / P i t c h D i a & g t ; < b r / > & l t ; M i n o r D i a & g t ; 4 . 2 6 & l t ; / M i n o r D i a & g t ; < b r / > & l t ; / T h r e a d & g t ; < b r / > & l t ; / D e s i g n a t i o n & g t ; < b r / > & l t ; D e s i g n a t i o n & g t ; < b r / > & l t ; T h r e a d D e s i g n a t i o n & g t ; 6 x 2 . 6 9 & l t ; / T h r e a d D e s i g n a t i o n & g t ; < b r / > & l t ; C T D & g t ; 6 x 2 . 6 9 & l t ; / C TD>
2.69
external
h14
6.0
4.595
3.19
7.0
7x2.48
7x2.48
2.48
external
h14
7.0
5.99
4.98
7x3.14
7x3.14
3.14
external
h14
7.0
5.85
3.7
8.0
8x2.82
8x2.82
2.82
external
h14
8.0
6.85
5.7
8x3.59
8x3.59
3.59
external
h14
8.0
6.105
4.21
9.0
9x3.24
9x3.24
3.24
external
h14
9.0
7.699
6.399
9x4
9x4
4
external
h14
9.0
6.715
4.43
10.0
10x3.6
10x3.6
3.6
external
h14
10.0
8.555
7.11
10x4.49
10x4.49
4.49
external
h14
10.0
7.615
5.23
Текущий скрипт не может создать ни одного болта с резьбой
import adsk.core, adsk.fusion, traceback
import math
import random
import time
import os
import json
defaultBoltName = 'Bolt'
defaultHeadDiameter = 0.75
defaultBodyDiameter = 0.5
defaultHeadHeight = 0.3125
defaultBodyLength = 1.0
defaultCutAngle = 30.0 * (math.pi / 180)
defaultChamferDistance = 0.03845
defaultFilletRadius = 0.02994
# Define metric thread data from XML
METRIC_THREAD_DATA = {
1.0: [0.44],
1.2: [0.51, 0.53],
1.4: [0.57, 0.62],
1.5: [0.67],
1.6: [0.64, 0.67],
1.8: [0.71, 0.8],
2.0: [0.78, 0.89],
2.2: [0.85, 0.98],
2.5: [0.95, 1.12],
3.0: [1.12, 1.34],
3.5: [1.29, 1.57],
4.0: [1.46, 1.79],
4.5: [1.63],
5.0: [1.8, 2.24],
6.0: [2.14, 2.69],
7.0: [2.48, 3.14],
8.0: [2.82, 3.59],
9.0: [3.24, 4.0],
10.0: [3.6, 4.49]
}
handlers = []
app = adsk.core.Application.get()
if app:
ui = app.userInterface
class ThreadData:
def __init__(self, threadFeatures):
self.threadFeatures = threadFeatures
self.threadDataQuery = threadFeatures.threadDataQuery
def getThreadInfoForDiameter(self, diameter_inches):
# Convert inches to mm for metric thread lookup
diameter_mm = diameter_inches * 25.4
# Find closest available diameter
available_diameters = list(METRIC_THREAD_DATA.keys())
closest_diameter = min(available_diameters, key=lambda x: abs(x - diameter_mm))
if abs(closest_diameter - diameter_mm) > 0.5: # If no close match found
return None
# Get available pitches for this diameter
available_pitches = METRIC_THREAD_DATA[closest_diameter]
selected_pitch = random.choice(available_pitches)
# Create thread info
threadInfo = self.threadFeatures.createThreadInfo(
False,
"Metric Tapping Threads for Plastics",
f"{closest_diameter}x{selected_pitch}",
"h14"
)
return threadInfo
class Bolt:
def __init__(self):
self._boltName = defaultBoltName
self._headDiameter = defaultHeadDiameter
self._bodyDiameter = defaultBodyDiameter
self._headHeight = defaultHeadHeight
self._bodyLength = adsk.core.ValueInput.createByReal(defaultBodyLength)
self._cutAngle = defaultCutAngle
self._chamferDistance = adsk.core.ValueInput.createByReal(defaultChamferDistance)
self._filletRadius = adsk.core.ValueInput.createByReal(defaultFilletRadius)
# Property getters and setters remain the same as in your original code
@property
def boltName(self):
return self._boltName
@boltName.setter
def boltName(self, value):
self._boltName = value
@property
def headDiameter(self):
return self._headDiameter
@headDiameter.setter
def headDiameter(self, value):
self._headDiameter = value
@property
def bodyDiameter(self):
return self._bodyDiameter
@bodyDiameter.setter
def bodyDiameter(self, value):
self._bodyDiameter = value
@property
def headHeight(self):
return self._headHeight
@headHeight.setter
def headHeight(self, value):
self._headHeight = value
@property
def bodyLength(self):
return self._bodyLength
@bodyLength.setter
def bodyLength(self, value):
self._bodyLength = value
@property
def cutAngle(self):
return self._cutAngle
@cutAngle.setter
def cutAngle(self, value):
self._cutAngle = value
@property
def chamferDistance(self):
return self._chamferDistance
@chamferDistance.setter
def chamferDistance(self, value):
self._chamferDistance = value
@property
def filletRadius(self):
return self._filletRadius
@filletRadius.setter
def filletRadius(self, value):
self._filletRadius = value
def buildBolt(self, component, threadData):
try:
newComp = component
# Create hexagonal head and body (same as original code)
sketches = newComp.sketches
xyPlane = newComp.xYConstructionPlane
xzPlane = newComp.xZConstructionPlane
sketch = sketches.add(xyPlane)
center = adsk.core.Point3D.create(0, 0, 0)
# Create hexagonal head
vertices = []
for i in range(6):
vertex = adsk.core.Point3D.create(
center.x + (self.headDiameter/2) * math.cos(math.pi * i / 3),
center.y + (self.headDiameter/2) * math.sin(math.pi * i / 3),
0
)
vertices.append(vertex)
for i in range(6):
sketch.sketchCurves.sketchLines.addByTwoPoints(vertices[(i+1) % 6], vertices[i])
# Extrude head
extrudes = newComp.features.extrudeFeatures
prof = sketch.profiles[0]
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
distance = adsk.core.ValueInput.createByReal(self.headHeight)
extInput.setDistanceExtent(False, distance)
headExt = extrudes.add(extInput)
# Name the body
fc = headExt.faces[0]
bd = fc.body
bd.name = self.boltName
# Create the body
bodySketch = sketches.add(xyPlane)
bodySketch.sketchCurves.sketchCircles.addByCenterRadius(center, self.bodyDiameter/2)
bodyProf = bodySketch.profiles[0]
bodyExtInput = extrudes.createInput(bodyProf, adsk.fusion.FeatureOperations.JoinFeatureOperation)
bodyExtInput.setAllExtent(adsk.fusion.ExtentDirections.NegativeExtentDirection)
bodyExtInput.setDistanceExtent(False, self.bodyLength)
bodyExt = extrudes.add(bodyExtInput)
# Create chamfer and fillet (same as original code)
edgeCol = adsk.core.ObjectCollection.create()
edges = bodyExt.endFaces[0].edges
for edgeI in edges:
edgeCol.add(edgeI)
chamferFeats = newComp.features.chamferFeatures
chamferInput = chamferFeats.createInput(edgeCol, True)
chamferInput.setToEqualDistance(self.chamferDistance)
chamferFeats.add(chamferInput)
# Create fillet
edgeCol.clear()
loops = headExt.endFaces[0].loops
for edgeLoop in loops:
if len(edgeLoop.edges) == 1:
edgeCol.add(edgeLoop.edges[0])
break
filletFeats = newComp.features.filletFeatures
filletInput = filletFeats.createInput()
filletInput.addConstantRadiusEdgeSet(edgeCol, self.filletRadius, True)
filletFeats.add(filletInput)
# Create revolve features for bolt head
self.createRevolveFeature(newComp, xzPlane, center, self.headDiameter/2, self.headHeight, self.cutAngle)
# Create thread feature using ThreadData
sideFace = bodyExt.sideFaces[0]
threads = newComp.features.threadFeatures
# Get appropriate thread info for the bolt diameter
threadInfo = threadData.getRandomThreadInfo(
threads,
self.bodyDiameter * 0.9, # Allow some tolerance
self.bodyDiameter * 1.1
)
if threadInfo:
faces = adsk.core.ObjectCollection.create()
faces.add(sideFace)
threadInput = threads.createInput(faces, threadInfo)
threadInput.isModeled = True
threadInput.threadLength = self.bodyLength
threads.add(threadInput)
return True
except:
if ui:
ui.messageBox(f'Failed to compute the bolt {self.boltName}. This is most likely because the input values define an invalid bolt.')
return False
def createRevolveFeature(self, component, plane, center, radius, height, angle):
sketches = component.sketches
revolveSketch = sketches.add(plane)
point1 = revolveSketch.modelToSketchSpace(adsk.core.Point3D.create(center.x + radius*math.cos(math.pi/6), 0, center.y))
point2 = revolveSketch.modelToSketchSpace(adsk.core.Point3D.create(center.x + radius, 0, center.y))
point3 = revolveSketch.modelToSketchSpace(adsk.core.Point3D.create(point2.x, 0, (point2.x - point1.x) * math.tan(angle)))
revolveSketch.sketchCurves.sketchLines.addByTwoPoints(point1, point2)
revolveSketch.sketchCurves.sketchLines.addByTwoPoints(point2, point3)
revolveSketch.sketchCurves.sketchLines.addByTwoPoints(point3, point1)
zAxis = component.zConstructionAxis
revolves = component.features.revolveFeatures
revProf = revolveSketch.profiles[0]
revInput = revolves.createInput(revProf, zAxis, adsk.fusion.FeatureOperations.CutFeatureOperation)
revAngle = adsk.core.ValueInput.createByReal(math.pi*2)
revInput.setAngleExtent(False, revAngle)
revolves.add(revInput)
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('Please switch to MODEL workspace and try again.')
return
root = design.rootComponent
threadData = ThreadData(root.features.threadFeatures)
def generate_valid_bolt_params(index):
# Generate base diameter in inches (converted from mm range 1-10mm)
min_diameter_inch = 1.0 / 25.4 # 1mm in inches
max_diameter_inch = 10.0 / 25.4 # 10mm in inches
# Generate random body diameter within valid range
body_diameter = random.uniform(min_diameter_inch, max_diameter_inch)
#Standard proportions based on body diameter
head_diameter = body_diameter * 1.5
head_height = body_diameter * 0.625
body_length = body_diameter * 2.0
# Small variations in chamfer and fillet (proportional to body diameter)
chamfer_distance = body_diameter * 0.077
fillet_radius = body_diameter * 0.06
# Add very small random variations
variation = 0.001
return {
'name': f'Bolt{index}',
'headDiameter': head_diameter * (1 + random.uniform(-variation, variation)),
'bodyDiameter': body_diameter, # Keep exact for thread matching
'headHeight': head_height * (1 + random.uniform(-variation, variation)),
'bodyLength': body_length * (1 + random.uniform(-variation, variation)),
'cutAngle': 30.0 * (math.pi / 180),
'chamferDistance': chamfer_distance * (1 + random.uniform(-variation, variation)),
'filletRadius': fillet_radius * (1 + random.uniform(-variation, variation))
}
def create_bolt(params, x, y, z):
try:
bolt = Bolt()
bolt.boltName = params['name']
bolt.headDiameter = params['headDiameter']
bolt.bodyDiameter = params['bodyDiameter']
bolt.headHeight = params['headHeight']
bolt.bodyLength = adsk.core.ValueInput.createByReal(params['bodyLength'])
bolt.cutAngle = params['cutAngle']
bolt.chamferDistance = adsk.core.ValueInput.createByReal(params['chamferDistance'])
bolt.filletRadius = adsk.core.ValueInput.createByReal(params['filletRadius'])
transform = adsk.core.Matrix3D.create()
transform.translation = adsk.core.Vector3D.create(x, y, z)
boltOcc = root.occurrences.addNewComponent(transform)
success = bolt.buildBolt(boltOcc.component, threadData)
if success:
export_as_stl(boltOcc.component, params['name'])
else:
if boltOcc:
boltOcc.deleteMe()
return success
except:
print(f"Failed to create bolt: {params['name']}")
if 'boltOcc' in locals() and boltOcc:
boltOcc.deleteMe()
return False
# Generate bolts
num_bolts = 10
grid_size = int(num_bolts ** 0.5) + 1
spacing = 2.0
successful_bolts = 0
start_time = time.time()
for i in range(num_bolts):
params = generate_valid_bolt_params(current_bolt_count + i + 1)
row = i // grid_size
col = i % grid_size
x = col * spacing
y = row * spacing
z = 0
if create_bolt(params, x, y, z):
successful_bolts += 1
print(f"Successfully created bolt {params['name']}")
else:
print(f"Failed to create bolt {params['name']}")
if (i + 1) % (num_bolts // 10) == 0:
progress = (i + 1) / num_bolts * 100
elapsed_time = time.time() - start_time
estimated_total_time = elapsed_time / (progress / 100)
remaining_time = estimated_total_time - elapsed_time
print(f"Progress: {progress:.1f}% - Estimated time remaining: {remaining_time:.1f} seconds")
adsk.doEvents()
total_time = time.time() - start_time
# Update and save configuration
current_bolt_count += successful_bolts
random_seed = random.randint(0, 1000000)
config = {'bolt_count': current_bolt_count, 'random_seed': random_seed}
with open(config_file, 'w') as f:
json.dump(config, f)
ui.messageBox(f'Created and exported {successful_bolts} bolts successfully.\n'
f'Total bolts created so far: {current_bolt_count}\n'
f'Total time taken: {total_time:.1f} seconds\n'
f'STL files are saved in the "stl_files" folder on your desktop.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Подробнее здесь: [url]https://stackoverflow.com/questions/79158047/what-is-the-way-to-change-the-thread-paramters-like-pitch-using-the-api-script[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия