MSCE U15 VBA - Apply a Dimension Style to a Note Dimension

I've got a VBA that places a customized Text Note. 

Private Function CreateNote(ptArray() As Point3d, View As View) As DimensionElement
    Dim elNote As DimensionElement
    Dim elLine As LineElement
    Dim pt3 As Point3d
    Dim dAngle As Double
    Dim dStyle As DimensionStyle
    
    '
    ' Text location must be set to InLine for label to be placed on correct side of leader
    '
    Set dStyle = ActiveSettings.DimensionStyle
    With dStyle
        .TextLocation = MsdDimTextLocationInline
    End With
    
    '
    ' Get angle of leader to determine correct placement of label
    '
    Set elLine = CreateLineElement1(Nothing, ptArray)
    dAngle = atn2(elLine.EndPoint.y - elLine.StartPoint.y, elLine.EndPoint.x - elLine.StartPoint.x)
    dAngle = Round(Degrees(dAngle), 1)
    
    '
    ' offset the text label from the leader by the active text height
    '
    pt3 = elLine.EndPoint
    Select Case True
        Case (dAngle < -90)
                pt3.x = pt3.x - ActiveSettings.TextStyle.Height
        Case Else
                pt3.x = pt3.x + ActiveSettings.TextStyle.Height
    End Select
        
    '
    ' create note element
    '
    Set elNote = CreateDimensionElement1(Nothing, Matrix3dIdentity, msdDimTypeNote, View)
    elNote.InsertReferencePoint ActiveModelReference, 1, ptArray(0)
    elNote.InsertReferencePoint ActiveModelReference, 2, ptArray(1)
    elNote.InsertReferencePoint ActiveModelReference, 3, pt3
    elNote.PrimaryText = "Note Text"
    Set elNote.DimensionStyle = dStyle
         
    Set CreateNote = elNote
End Function

In this function I grab the active dimension style, change the TextLocation attribute, and apply it to the newly created Note Dimension Element.

The new note dimension element takes the TextLocation change, but does not take on the attributes of the active Dimension Style.

For example, the leader is always a line, even if I modify the active dimension style to use a curved leader prior to running this macro.

The same kind of thing happens if I change the font or other text style parameters.

Is there something wrong with the way I'm capturing/applying the active dimension style or have I uncovered another defect?

  • Hi Rod,

    I guess this is a little bit of a necro-post but I randomly came across this topic in search results earlier and I noticed you never received any replies which seemed a little strange.

    I'm unsure if you ever found a solution however I thought I'd offer my thoughts on the off chance you hadn't:

    1. I'm a little confused by the following:
      and apply it to the newly created Note Dimension Element.
      What's confusing is that your function aside from creating the note dimension in code, it doesn't add anything to a model when I run the code; I've tested it by providing 3No. dummy point3d values and also plugged it into a class using IPrimitiveCommandEvents where I provide a pair of data points to define the note. I noticed you've used a Function whereas I would instead recommend that a regular Sub be used. The reason for this is that your current function is missing the following line to add the note dimension element to the active design file
      ActiveModelReference.AddElement elNote

      After changing function to sub and inserting the above at the end of the sub, you can delete Set CreateNote = elNote as its not needed.
    2. I'm not sure why you chose to use:
      With dStyle
          .TextLocation = MsdDimTextLocationInline
      End With

      instead of this:
      dStyle.TextLocation = MsdDimTextLocationInline

      It would be understandable if you had multiple dstyle properties to set at once but as its only one, it doesn't seem needed in this instance.
    3. Set isn't required in this line:
      Set elNote.DimensionStyle = dStyle

    The new note dimension element takes the TextLocation change, but does not take on the attributes of the active Dimension Style.

    For example, the leader is always a line, even if I modify the active dimension style to use a curved leader prior to running this macro.

    The same kind of thing happens if I change the font or other text style parameters.

    Is there something wrong with the way I'm capturing/applying the active dimension style or have I uncovered another defect?

    In my edited version of your code, I have no issues with the leader being created as either a line or a curve. I think its worth highlighting that you mention 'Active Dimension Style' when the reality is that Set dStyle = ActiveSettings.DimensionStyle is using not a preset style (or at least, I don't consider it a style) rather the current setting or values used in Style:(none) within the Dimension Styles Dialog. Just be sure that you are changing the Dimension settings with that selected or instead specify the appropriate preset Dimension Style by changing:

    Set dStyle = ActiveSettings.DimensionStyle

    to something like:
    Set dstyle = ActiveDesignFile.DimensionStyles("DimensionStyleWhatever")

    My working Pseudo-code where I removed all the unnecessary stuff to test core note-creation functionality:

    Private Sub CreateNote()
    Dim ptArray(0 To 2)                              As Point3d
    Dim elNote                                       As DimensionElement
    Dim dStyle                                       As DimensionStyle
        
    ptArray(0) = Point3dZero
    ptArray(1) = Point3dFromXYZ(100, 100, 0)
    ptArray(2) = Point3dFromXYZ(125, 100, 0)
            
    Set dStyle = ActiveSettings.DimensionStyle
    dStyle.TextLocation = MsdDimTextLocationInline
            
    Set elNote = CreateDimensionElement1(Nothing, Matrix3dIdentity, msdDimTypeNote)
    elNote.InsertReferencePoint ActiveModelReference, 1, ptArray(0)
    elNote.InsertReferencePoint ActiveModelReference, 2, ptArray(1)
    elNote.InsertReferencePoint ActiveModelReference, 3, ptArray(2)
    elNote.PrimaryText = "Note Text"
    elNote.DimensionStyle = dStyle
             
    ActiveModelReference.AddElement elNote
    End Sub