[API] How to obtain CosmeticThread data?

Dear all,

I've asked this question before but can't find the original posted.

I want to obtain the information of CosmeticThread feature but I cannot find out the CosmeticThread object in Sldworks object tree. Could anyone direct me for this issue.

Thank very much for any recommendation.

Billy

Reply to
Billy
Loading thread data ...

Hi, not sure if it's wat you are looking for, but there is an example included in the SW API helpfile. Search for "traverse all cosmetic threads example"

best, JM

Reply to
JM

Here is a link to your original thread

formatting link

Reply to
Paul Delhanty

Please see the following example. The example assumes, that you have a part open, and a feature such as hole wizard hole is selected from feature manager tree. The very point is, that the cosmetic thread is a sub-feature for the feature to which the thread is applied. So you have to loop through the subfeatures until you find a cosmetic thread. Cut-paste to macro editor and step through the code to see how it works.

Hope this helps!

-h-

Option Explicit Sub main() 'Get the handle to SolidWorks Dim swApp As SldWorks.SldWorks Set swApp = Application.SldWorks

'Get the active document Dim objModel As SldWorks.ModelDoc2 Set objModel = swApp.ActiveDoc

'Validate proper document type If objModel Is Nothing Then Exit Sub If objModel.GetType swDocPart Then Exit Sub

'Get the selection manager handle Dim objSelMgr As SldWorks.SelectionMgr Set objSelMgr = objModel.SelectionManager

'Validate right selection count If objSelMgr.GetSelectedObjectCount 1 Then Exit Sub

'Validate right selection type If objSelMgr.GetSelectedObjectType2(1) swSelBODYFEATURES Then Exit Sub

'Get the selected feature Dim objFeature As SldWorks.feature Set objFeature = objSelMgr.GetSelectedObject5(1)

'Get the first subfeature of this feature Set objFeature = objFeature.GetFirstSubFeature

'Loop through each subfeature While Not objFeature Is Nothing 'Display data if the subfeature is a cosmetic thread If objFeature.GetTypeName = "CosmeticThread" Then 'Get the cosmetic thread feature definition object Dim objCosThread As SldWorks.CosmeticThreadFeatureData Set objCosThread = objFeature.GetDefinition

'Display the data With objCosThread MsgBox "Cosmetic thread data for " & objFeature.Name & vbCrLf & _ "Blind Depth: " & Str(.BlindDepth * 1000) & vbCrLf & _ "Diameter: " & Str(.diameter * 1000) & vbCrLf & _ "Thread Callout: " & .ThreadCallout End With End If

'Get the next subfeature Set objFeature = objFeature.GetNextSubFeature Wend End Sub

Reply to
Heikki Leivo

Dear Heikki Leivo,

Thank you very much for your kindly help! I am also using VB for coding, but I can't find out the feature: CosmeticThreadFeatureData from the object browser of VB interface. So it cannot be recognised by VB. I wonder whether this feature is no longer exist in type library for SW version 2001 or later.

Billy

Reply to
Billy

Thanks Paul Delhanty,

But I can't reach the link you posted as:

formatting link
Billy

Reply to
Billy

You're welcome!

According to SolidWorks API help, this feature is supported in SW 2003 SP

0.0 and later versions, so CosmeticThreadData object may not be in SW2001 type library.

Hope this helps!

-h-

Reply to
Heikki Leivo

Well the link still works for me. If it doesn't redirect automatically to google groups then you may have to manually click on the second link.

Anyway, it was only a link back to your original post that you couldn't find plus Heikki's answer. I think Heikki has answered again in more detail in this thread, so the original post and reply is now somewhat redundant.

Reply to
Paul Delhanty

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.