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:
Rod Wing said: and apply it to the newly created Note Dimension Element.
ActiveModelReference.AddElement elNote
Set CreateNote = elNote
With dStyle .TextLocation = MsdDimTextLocationInline End With
dStyle.TextLocation = MsdDimTextLocationInline
Set elNote.DimensionStyle = dStyle
Rod Wing said: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
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
Barry,
Thanks for taking the time to take a look at this. I'm finally getting back to working at this macro.
The solution to my problem turned out to be pretty easy actually. Instead of capturing the entire dimension style, modifying a single property, and reapplying the dimension style, I found I could just modify the style property in the dimension element itself.
elNote.DimensionStyle.TextLocation = MsdDimTextLocationInline
Rod WingSenior Systems Analyst
Answer Verified By: Rod Wing