Message 1 of 1
Diameter automation in drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to do a code that do the following, but I am totally stuck in the part of deleting duplicated dimensions with lower quantities
1. Create diameter dimensions
2. Track dimension quantities
3. Label dimensions with quantities: (e.g., "3x ⌀50mm" if that dimension is used 3 times).
4.Delete duplicate dimensions with lower quantities: (e.g., delete "1x ⌀50mm" & "2x ⌀50mm" if that dimension is used 3 times)
Below my code:
' Create a dictionary to store view names and their used dimension values with their counts Dim viewUsedValues As New Dictionary(Of String, Dictionary(Of String, Integer)) Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet Dim oTG As TransientGeometry = ThisApplication.TransientGeometry ' Initialize dictionary for all views For Each oView As DrawingView In oSheet.DrawingViews viewUsedValues(oView.Name) = New Dictionary(Of String, Integer) Next ' Process each view and create dimensions For Each oView As DrawingView In oSheet.DrawingViews ' Temporary list to hold curves for dimension creation Dim tempCurves As New List(Of DrawingCurve) ' Collect curves that will be used for dimensioning For Each oCurve As DrawingCurve In oView.DrawingCurves If oCurve.CurveType = CurveTypeEnum.kCircleCurve Then tempCurves.Add(oCurve) End If Next ' Starting Y offset for dimension placement Dim yOffset As Double = oView.Top + 1 Dim spacing As Double = 1 ' Adjust as needed for spacing between dimensions ' Create dimensions based on collected curves For Each oCurve As DrawingCurve In tempCurves ' Get the geometry intent from the curve Dim oIntent As GeometryIntent = oSheet.CreateGeometryIntent(oCurve) ' Define the point where the dimension should be placed Dim oPt1 As Point2d = oTG.CreatePoint2d(oView.Left + oView.Width, yOffset) ' Create the diameter dimension Dim oID As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddDiameter(oPt1, oIntent, False, False, True) ' Get the dimension value in centimeters and convert to millimeters Dim dimValueInCm As Double = oID.ModelValue Dim dimValueInMm As Double = dimValueInCm * 10 ' Convert cm to mm Dim dimValue As String = dimValueInMm.ToString() ' Check if the value has been used already If viewUsedValues(oView.Name).ContainsKey(dimValue) Then ' Increment the count for this diameter value viewUsedValues(oView.Name)(dimValue) += 1 Else ' Add the new diameter value to the dictionary with a count of 1 viewUsedValues(oView.Name).Add(dimValue, 1) End If ' Update the dimension's text with the quantity and diameter symbol Dim quantity As Integer = viewUsedValues(oView.Name)(dimValue) Dim diameterSymbol As String = "⌀" ' Replace with your preferred symbol oID.Text.FormattedText = quantity.ToString() & "x " & "<DimensionValue/>" ' Increment the Y offset for the next dimension yOffset -= spacing Next ' Remove dimensions with lower quantities If viewUsedValues(oView.Name).Count > 0 Then Dim maxQuantity As Integer = viewUsedValues(oView.Name).Values.Max() For Each dimValue As String In viewUsedValues(oView.Name).Keys.ToList() If viewUsedValues(oView.Name)(dimValue) < maxQuantity Then ' Find and delete the dimension with this value For Each oID As GeneralDimension In oSheet.DrawingDimensions.GeneralDimensions If oID.Text.FormattedText.Contains(dimValue & "x") Then oID.Delete() End If Next End If Next End If Next