Get all dimensions in a part

Get all dimensions in a part

Anonymous
Not applicable
602 Views
2 Replies
Message 1 of 3

Get all dimensions in a part

Anonymous
Not applicable

I want to list all dimensions in a part. How to do it?

 

Steps I will follow are

    1) Open the part.

    2) Gather all features in the part (Which VB .NET  object and method will get the all the features in the part as a container class)

    3) For each feature get the dimensions associated with that feature 

    4) For each feature get the sketch associated with the feature

    5) Get the dimensions in the sketch.

 

How to do the above steps?

I have the following code which does Step 1, 2 and 3

 

Sub QueryAndShowFeatureDimensions()
    Try


         Dim oDoc As Document
         oDoc = InventorApplication.ActiveDocument


          ' Get the component definition. This owns the part specific info for the part.
           Dim partDef As PartComponentDefinition
           partDef = oDoc.ComponentDefinition
           Dim partSketches As PlanarSketches
            partSketches = partDef.Sketches
           'For Each partFeature In oDoc.


           ' Set a reference to the selected feature.
            Dim oFeature As PartFeature
            Dim oFeatures As PartFeatures
            oFeatures = partDef.Features

            Dim oFeatureDim As FeatureDimension
            Dim i As Long
            Dim j As Long
            i = 0
            j = 0
           ' Iterate over all dimensions of the feature.
MessageBox.Show("Number of features in part is >" + oFeatures.Count.ToString + "<")
For Each oFeature In oFeatures
j = j + 1
i = 0
For Each oFeatureDim In oFeature.FeatureDimensions
i = i + 1
MessageBox.Show(" Feature " + CStr(j) + ". Dimension " + CStr(i) + ". Name >" + oFeatureDim.Parameter.Name + "< . Model Value >" + CStr(oFeatureDim.Parameter.ModelValue) + "<")
Next
' Show all the feature dimensions
oFeature.FeatureDimensions.Show()
Next

i = 0
MessageBox.Show(" Number of sketches is >" + CStr(partSketches.Count) + "<")
For Each partSkethch As Sketch In partSketches

Next


Catch ex As Exception
MessageBox.Show(ex.Message)
MessageBox.Show(ex.StackTrace)
End Try
End Sub

0 Likes
603 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

I did more reading in Inventor Help (Community Resources---->Programming Help)

Based on that I tried to retrieve and set the dimension constraints of sketches or profiles. I tried two alternatives 

   1st Alternative) Features-->Sketches--->Dimension Constraints.  But got struck on how get the dimension value and update the value

   2nd Alternative) ExtrudeFeatures--->Profiles--->ProfilePath--->ProfileEntity---->Sketch----->SketchConstraints . But got struck on how to get the dimension values and update the value.

 

  Any help on how to proceed further is appreciated.   Code Snippet provided below.

Thanks

Regards

PV Subramanian

 

 

Sub QueryAndShowFeatureDimensions()
Try

Dim oDoc As Document
oDoc = InventorApplication.ActiveDocument

' Get the component definition. This owns the part specific info for the part.
Dim partDef As PartComponentDefinition
partDef = oDoc.ComponentDefinition

 

Dim partSketches As PlanarSketches
partSketches = partDef.Sketches

Dim oFeature As PartFeature
Dim oFeatures As PartFeatures
oFeatures = partDef.Features

Dim oFeatureDim As FeatureDimension
Dim i As Long
Dim j As Long
i = 0
j = 0

 

' Iterate over all dimensions of the feature.
MessageBox.Show("Number of features in part is >" + oFeatures.Count.ToString + "<")
For Each oFeature In oFeatures
    j = j + 1
    i = 0
    For Each oFeatureDim In oFeature.FeatureDimensions
          i = i + 1
          'MessageBox.Show(" Feature " + CStr(j) + ". Dimension " + CStr(i) + ". Name >" + oFeatureDim.Parameter.Name + "< . Model Value >" + CStr(oFeatureDim.Parameter.ModelValue) + "<")

     Next
     ' Show all the feature dimensions
       oFeature.FeatureDimensions.Show()
Next

 

MessageBox.Show(" Number of sketches is >" + CStr(partSketches.Count) + "<")
Dim oSketch As Sketch

 

For Each oSketch In oDoc.ComponentDefinition.Sketches
    MessageBox.Show(" SketchName >" + oSketch.Name + "<")
    Dim dimConstraints As DimensionConstraints = oSketch.DimensionConstraints()
    MessageBox.Show(" SketchName >" + oSketch.Name + "< No. of dim constraints >" + CStr(dimConstraints.Count) + "<")
    Dim dimConstraint As DimensionConstraint
    Dim x As Integer = 1
    For Each dimConstraint In dimConstraints  
       MessageBox.Show(" SketchName >" + oSketch.Name + "< Dim constraint >" + CStr(x) + "< " + dimConstraint.ToString())
       MessageBox.Show("Dim constraint Type >" + dimConstraint.GetType().ToString() + "<")
       x = x + 1
   Next
Next

 

Dim partExtrudeFeatures As ExtrudeFeatures
partExtrudeFeatures = partDef.Features.ExtrudeFeatures
MessageBox.Show(" Number of extrude Features is >" + CStr(partExtrudeFeatures.Count) + "<")

 

Dim k As Integer = 0
For Each extrudeFeat In partExtrudeFeatures
   Dim extrudeProfile As Profile = extrudeFeat.Profile
   MessageBox.Show("Extrude Feature >" + CStr(k) + "< Number of profiles >" + CStr(extrudeProfile.Count) + "<")
   For i = 1 To extrudeProfile.Count Step 1
       Dim profile As ProfilePath = extrudeProfile.Item(CInt(i))
       MessageBox.Show("Extrude Feature >" + CStr(k) + "< Profile >" + CStr(i) + "< Number of profile entities >" + CStr(profile.Count) + "<")
       For j = 1 To profile.Count Step 1
           Dim profileEntity As ProfileEntity = profile.Item(CInt(j))
           Dim curveType As Curve2dTypeEnum = profileEntity.CurveType
           MessageBox.Show("Extrude Feature >" + CStr(k) + "< Profile >" + CStr(i) + "< Profile entity >" + CStr(j) + "< Profile Entity Type >" + curveType.ToString + "<")
           If curveType = Curve2dTypeEnum.kCircleCurve2d Then
                 Dim sketchEnt As SketchEntity = profileEntity.SketchEntity
                 Dim sketchEntConstraints As SketchConstraintsEnumerator = sketchEnt.Constraints
MessageBox.Show("Extrude Feature >" + CStr(k) + "< Profile >" + CStr(i) + "< Profile entity >" + CStr(j) + "< Profile Entity Type >" + curveType.ToString + "< No of constraints >" + CStr(sketchEntConstraints.Count) + "< Type >" + sketchEntConstraints.GetType().ToString() + "<")
                 Dim x As Integer
                 

                 For x = 1 To sketchEntConstraints.Count Step 1
                      Dim sketchConstraint As Object = sketchEntConstraints.Item(x)
                      MessageBox.Show("Extrude Feature >" + CStr(k) + "< Profile >" + CStr(i) + "< Profile entity >" + CStr(j) + "< Profile Entity Type >" + curveType.ToString + "< Constraints >" + CStr(x) + "<")

                           
                 Next

         End If

      Next
  Next
  k = k + 1
Next

Catch ex As Exception
MessageBox.Show(ex.Message)
MessageBox.Show(ex.StackTrace)
End Try
End Sub

 

0 Likes
Message 3 of 3

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

I've just answered your other post http://forums.autodesk.com/t5/inventor-customization/how-to-edit-update-change-dimension-of-a-featur...

Does that help you solve this one or you need more help?

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes