6 Replies Latest reply on Oct 31, 2014 9:53 AM by Chris Johnson

    Get Chamfer Feature dimensions?

    Chris Johnson

      Hi All,



      how do you get the dimension values  for D1& D2 of a chamfer feature?


      I would like to create a macro that loops through all the chamfers and renames them based on length and angle.

      the feature would look like this ".06 X 45°" after running the macro.



      basically we have a drafting standard that requires the features to be renamed and people are not that good at updating the feature after they change it. this macro should fix this problem but im not sure how to get those values!


      as usual, thanks & have a good weekend!



        • Re: Get Chamfer Feature dimensions?
          Daniel Andersson

          Hi, Try this one, just wrote it so I have only tested it on a part with metric dimensions. The macro will assign a complete new name to all chamfer features including the number of the chamfer "Chamfer1",  "Chamfer2" etc. The numbering will follow the order of the chamfer in the feature manager.


          Please let me know if it works out well or not.

          Option Explicit
          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swFeatMgr As SldWorks.FeatureManager
          Dim vFeatures As Variant
          Dim swFeature As SldWorks.Feature
          Dim swChamfer As SldWorks.ChamferFeatureData2
          Dim i As Integer
          Dim k As Integer
          Dim Pi As Double
          Dim Digits As Long


          Sub main()

          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc

          If swModel Is Nothing Then Exit Sub
          If Not swModel.GetType = swDocumentTypes_e.swDocPART Then Exit Sub

          Set swFeatMgr = swModel.FeatureManager
          vFeatures = swFeatMgr.GetFeatures(False)

          k = 0
          Pi = 3.14159265358979
          Digits = 3 'Number of digits of angle to be shown in feature name


          'Set a temporary name in order to avoid possible naming conflicts
          'this might consider to be not necessary. Remove or comment the code if you want to disable it.

          For i = 0 To UBound(vFeatures)
              Set swFeature = vFeatures(i)
              If swFeature.GetTypeName2 = "Chamfer" Then
                  Set swChamfer = swFeature.GetDefinition
                  k = k + 1
                  swFeature.Name = "Chamfer_temp_name_" & k
              End If
          'End of setting temp. names to chamfers.


          k = 0


          For i = 0 To UBound(vFeatures)
              Set swFeature = vFeatures(i)
              If swFeature.GetTypeName2 = "Chamfer" Then
                  Set swChamfer = swFeature.GetDefinition
                  k = k + 1
                  Select Case swChamfer.Type 'Depending on chamfer type, get different data and set the feature name different.
                  Case swChamferType_e.swChamferAngleDistance
                  swFeature.Name = "Chamfer" & k & " " & swChamfer.GetEdgeChamferDistance(0) * 1000 & "x" & Round((swChamfer.EdgeChamferAngle * (180 / Pi)), Digits) & Chr(176)
                  Case swChamferType_e.swChamferDistanceDistance
                  swFeature.Name = "Chamfer" & k & " " & swChamfer.GetEdgeChamferDistance(0) * 1000 & "x" & swChamfer.GetEdgeChamferDistance(1) * 1000
                  Case swChamferType_e.swChamferEqualDistance
                  swFeature.Name = "Chamfer" & k & " " & swChamfer.GetEdgeChamferDistance(0) * 1000 & "x" & swChamfer.GetEdgeChamferDistance(0) * 1000
                  Case swChamferType_e.swChamferVertex
                   swFeature.Name = "Chamfer" & k & " " & swChamfer.GetVertexChamferDistance(0) * 1000 & "x" & swChamfer.GetVertexChamferDistance(1) * 1000 & "x" & swChamfer.GetVertexChamferDistance(2) * 1000
                  End Select
              End If

          End Sub

          1 person found this helpful