VBA Create new text style for general note

VBA Create new text style for general note

pball
Mentor Mentor
1,559 Views
3 Replies
Message 1 of 4

VBA Create new text style for general note

pball
Mentor
Mentor

I'm wasting a lot of time trying to find or figure out how to create and apply a text style to a new note. I'm using the following code to create a new note but I can't get it to use a new text style so I can format it differently.

 

I would also accept if it's possible to add rotation in the styleoverride in the formattedtext of a note. I've tried adding it but it doesn't seem to affect anything unlike the fontsize which appears to work.

 

    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    Dim stext As String
'The rotation override sadly does not seem to work at any value I've tried, other wise I'd just use this method stext = "<StyleOverride FontSize = '0.1524' Rotation = '90'>PRINTED: " & Now() & "<Br/>BY: " & ThisApplication.GeneralOptions.UserName & "</StyleOverride>" ' Set a reference to the GeneralNotes object Dim oGeneralNotes As GeneralNotes Set oGeneralNotes = invDoc.ActiveSheet.DrawingNotes.GeneralNotes Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry Dim oGeneralNote As GeneralNote Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(0.3, 1.5), stext)
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Accepted solutions (1)
1,560 Views
3 Replies
Replies (3)
Message 2 of 4

Owner2229
Advisor
Advisor
Accepted solution

Try this:

 

Dim invDoc As Document
Set invDoc = ThisApplication.ActiveDocument

Dim stext As String
stext = "<StyleOverride Font='ARIAL' FontSize = '0.1524' >PRINTED: " & Now() & "<Br/>BY: " & ThisApplication.GeneralOptions.UserName & "</StyleOverride>"

' Set a reference to the GeneralNotes object
Dim oGeneralNotes As GeneralNotes
Set oGeneralNotes = invDoc.ActiveSheet.DrawingNotes.GeneralNotes
    
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
    
Dim oGeneralNote As GeneralNote
Set oGeneralNote = oGeneralNotes.AddFitted(oTG.CreatePoint2d(0.3, 1.5), stext)
' Set the color of the note if needed
Dim oColor As Color
Set oColor = 
ThisApplication.TransientObjects.CreateColor(128, 128, 128)
oGeneralNote.Color = oColor

' Set the rotation of the note in Radians
oGeneralNote.Rotation = 1.57
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 4

pball
Mentor
Mentor
Wow that is stupidly simple. Every example I've seen of creating a new note and altering it involved messing with styles. Thanks
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 4 of 4

Owner2229
Advisor
Advisor

You're welcomed Smiley Happy

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes