Community
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Parameter names on drawing dimensions

Parameter names on drawing dimensions

I have an iPart table referencing the parameter names and thus I would like the parameter names on the dimension lines instead of there numeric value. In order to achieve this I have to write the parameter names all over again and suppress the numeric value. In part modeling I have this ability to switch between value, name, expression, tolerance and precise value depending on what I would like displayed on the dimension lines.

1 Comment
kelly.young
Autodesk Support

This rule will add the parameter name as a prefix to all retrieved dimensions in a drawing. It also adds an equal sign and spaces, so the text will look like "WIDTH = 3". Was tested with Inventor 2023.

If you change the name of a parameter (in the part), the old name will still be shown in the drawing dimension. You have to run the rule again to fix it. Or if you retrieve a new dimension, then you have to run the rule again to format the text. The rule will check all dimensions in the drawing and change only the ones that need to be changed.

Option Explicit On
Imports System.Text.RegularExpressions
Sub Main
    Dim drawingDoc = ThisDrawing.Document
    For Each sheetX As Sheet In drawingDoc.Sheets
        For Each dimX As GeneralDimension In sheetX.DrawingDimensions.GeneralDimensions
            If dimX.Retrieved Then
                Dim fromParameter = LinkedParameter(dimX.RetrievedFrom)
                If fromParameter IsNot Nothing Then
                    UpdateDimension(dimX, fromParameter)
                End If
            End If
        Next
    Next
End Sub
Sub UpdateDimension(dimX As GeneralDimension, fromParameter As Parameter)
    Logger.Debug("dimX.Text.FormattedText = {0}", dimX.Text.FormattedText)
        
    Dim parameterNameText = String.Format("{0} = ", fromParameter.Name)
    Dim originalText = dimX.Text.FormattedText
    Dim newText As String = Nothing
    If Not originalText.Contains("= <") Then
        newText = originalText.Replace("<DimensionValue/>", parameterNameText + "<DimensionValue/>")
    Else
        ' Make sure the parameter name is correct.
        ' The regular expression should match any parameter name.
        newText = Regex.Replace(originalText, "[a-zA-Z_:0-9]* = <" , parameterNameText + "<")
    End If
    If newText IsNot Nothing And originalText <> newText
        Logger.Info("-- new dimension text: {0}", newText)
        dimX.Text.FormattedText = newText
    End If
End Sub
Function LinkedParameter(retrievedFrom As Object) As Parameter
    Try
        Return retrievedFrom.Parameter
    Catch 
    End Try
    Return Nothing
End Function

 

Can't find what you're looking for? Ask the community or share your knowledge.

Submit Idea  

Autodesk Design & Make Report