Change the text size in the Styles Editor using VBA

Change the text size in the Styles Editor using VBA

shastu
Advisor Advisor
3,192 Views
20 Replies
Message 1 of 21

Change the text size in the Styles Editor using VBA

shastu
Advisor
Advisor

This should be so simple, but I can't figure out how to do it.  All I want to do is change the Text Height of "DEFAULT-ANSI" using VBA for the active drawing file.  See screenshot. 

 

Sub TextSize()

    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the active sheet.
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet

 

    ' Code to change the Text Height from 0.120 to .080. 

 

 

End Sub

0 Likes
Accepted solutions (1)
3,193 Views
20 Replies
Replies (20)
Message 2 of 21

bradeneuropeArthur
Mentor
Mentor

try  this:

If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
Dim oIDW As DrawingDocument
Set oIDW = ThisApplication.ActiveDocument
 
Dim oIDWStyles As Inventor.DrawingStylesManager
Set oIDWStyles = oIDW.StylesManager

'MsgBox oIDWStyles.RevisionTableStyles.Count
oIDWStyles.TextStyles.Item(1).FontSize

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 21

JelteDeJong
Mentor
Mentor
Accepted solution

try this

Sub TextSize()
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' make a refrence to the style you want to change.
    ' here i change the text style: "Note Text (DIN)"
    Dim textStyle As textStyle
    Set textStyle = oDrawDoc.StylesManager.TextStyles.Item("Note Text (DIN)")
    
    textStyle.FontSize = 3.5 '<-- this should be set in Cm
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 21

shastu
Advisor
Advisor

Thank you so much!!!  I tried to look through the Autodesk Inventor 2019 API Help, but just couldn't quite get there.  If you have any suggestions on how better to use that tool, I would be forever grateful.

0 Likes
Message 5 of 21

grenee
Observer
Observer

Good day,

When I copy and paste this code this is the error message that comes up:

 

 

User-defined type not defined

0 Likes
Message 6 of 21

shastu
Advisor
Advisor

My first thought was that you just copied and pasted it without any changes?  You have to change the name of the Text style that you want to manipulate.  So in the line Set textStyle = oDrawDoc.StylesManager.TextStyles.Item("Note Text (DIN)" you have to change the "Note Text (DIN)" to be what your text style is called.  However, then I tried doing that and I did not get the error you got, so maybe JelteDeJong can answer you.

0 Likes
Message 7 of 21

grenee
Observer
Observer

Thanks for your response. 

 

However, me aim is to change to text size of the dimension and not the general text.

0 Likes
Message 8 of 21

shastu
Advisor
Advisor

Something like this then:

 

Sub DimensionTextSize()
'set active document as drawing document
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

'get the active dim style
Dim oDStyle As DimensionStyle
Set oDStyle = oDoc.StylesManager.ActiveStandardStyle. _
ActiveObjectDefaults.LinearDimensionStyle

'get current font size
Dim sFontSize As String
sFontSize = oDStyle.textStyle.FontSize
'MsgBox(sFontSize)

'set font size for dim style
oDStyle.textStyle.FontSize = 0.35
End Sub

Message 9 of 21

grenee
Observer
Observer

There is still a problem. The problem is with this Line: Dim oDoc As DrawingDocument

 

That is DrawingDocument is not defined

0 Likes
Message 10 of 21

greneebb
Participant
Participant

This is the result.

 

greneebb_0-1670205582083.png

 

0 Likes
Message 11 of 21

shastu
Advisor
Advisor

I am not as knowledgeable as some others, but my guess would be that you are not pasting this in the correct location.  Are you pasting the code into a Module?  If not, please insert a new Module and paste it in there(in the browser, Right Mouse Click on the Project, then left mouse click on the Insert, then left mouse click on Module).  Then paste the code in that new module and try to run it from that Module.

0 Likes
Message 12 of 21

greneebb
Participant
Participant

Thanks for your response.

 

However, I think it is pasted correctly. But notice that the message says that DrawingDocument is undefined.  So, how is this to be defined?

0 Likes
Message 13 of 21

greneebb
Participant
Participant
Where can I find styles and standard editor?
0 Likes
Message 14 of 21

shastu
Advisor
Advisor

The Line: "Dim oDoc As DrawingDocument" is how you define it.  That is what is confusing me.  That line should not throw an error as you are just telling it to set oDoc as a drawing document.  In other words, if you try to run this code from an ipt file or an iam file, it will error out because it is not a drawing, i.e. dwg or idw file.  Is there any way that you can send me the file that you pasted this code into?  If you are pasting it in a file, send me the file.  If you are pasting it in the default.ivb, then send me that file.

0 Likes
Message 15 of 21

shastu
Advisor
Advisor

Are you talking about the one in Inventor?  If so, it is under the Manage tab.

shastu_0-1670450666790.png

 

0 Likes
Message 16 of 21

greneebb
Participant
Participant
I don't have inventor
0 Likes
Message 17 of 21

greneebb
Participant
Participant
Do I have to have Inventor?
0 Likes
Message 18 of 21

shastu
Advisor
Advisor

Yes.  Given that this is an Inventor forum, I just assumed you were working with Inventor.  What are you working in?

0 Likes
Message 19 of 21

greneebb
Participant
Participant
I am using AutoCAD
0 Likes
Message 20 of 21

greneebb
Participant
Participant

Where can I find a forum for AUTOCAD?

0 Likes