[API] How to obtain CosmeticThread data?

Discussion in 'SolidWorks' started by Billy, Dec 27, 2003.

  1. Billy

    Billy Guest

    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
     
    Billy, Dec 27, 2003
    #1
  2. Billy

    JM Guest

    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
     
    JM, Dec 27, 2003
    #2
  3. Here is a link to your original thread

    http://makeashorterlink.com/?H152427E6
     
    Paul Delhanty, Dec 27, 2003
    #3
  4. Billy

    Heikki Leivo Guest

    Dear all,
    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
     
    Heikki Leivo, Dec 28, 2003
    #4
  5. Billy

    Billy Guest

    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
     
    Billy, Dec 31, 2003
    #5
  6. Billy

    Billy Guest

    Billy, Dec 31, 2003
    #6
  7. Billy

    Heikki Leivo Guest

    Dear Heikki Leivo,
    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-
     
    Heikki Leivo, Dec 31, 2003
    #7
  8. 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.
     
    Paul Delhanty, Jan 1, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.