VBA - Change currently active dimension style

VBA - Change currently active dimension style

Anonymous
Not applicable
3,382 Views
14 Replies
Message 1 of 15

VBA - Change currently active dimension style

Anonymous
Not applicable

Hello!

 

I am trying to create a macro that I can run with a button, that enables the Dimension tool, and automatically sets a specific style as active, so I do not have to do it manually each time..

 

This code enables the Dimension tool in the drawing: 

 

    Dim oCommandMgr As CommandManager 
     oCommandMgr = ThisApplication.CommandManager 

    Dim oControlDef As ControlDefinition 
     oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingGeneralDimensionCmd")  
    Call oControlDef.Execute 
	
	  oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingNewDimensionStyleCtxCmd")  
   

 

So far Its working great.. But now I would have to set the style to a specific one. Is there a way to do it via VBA?

 

Thanks

 

Best regards

0 Likes
3,383 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

I managed to find the style i need, but I do not know how to activate it..

 

 

SyntaxEditor Code Snippet

doc.StylesManager.DimensionStyles(2)
0 Likes
Message 3 of 15

Anonymous
Not applicable

Nobody? 😞 searched for hours but couldnt find a solution on this..

0 Likes
Message 4 of 15

GeorgK
Advisor
Advisor
Sub ChangeDimStyle()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oNewDimStyle As DimensionStyle
Set oNewDimStyle =
oDoc.StylesManager.DimensionStyles.Item("MyDimensionStyle")

Dim oGeneralDim As GeneralDimension
For Each oGeneralDim In
oDoc.ActiveSheet.DrawingDimensions.GeneralDimensions

oGeneralDim.Style = oNewDimStyle
Next

End Sub
0 Likes
Message 5 of 15

Anonymous
Not applicable

Hello, 

 

thanks for your reply.. I am not trying to change already placed dimensions.. I am trying to change the currently active style so i can place NEW dimensions with the style i need...

 

thanks!

 

Best regards

 

Igor

0 Likes
Message 6 of 15

Anonymous
Not applicable

Just for clarification, I would need to change the highlited setting via VBA/iLogic, once that the Dimension command is active. (activating the dimension command is already done in vba..)

 

2018-01-29_12h49_24.png

0 Likes
Message 7 of 15

bradeneuropeArthur
Mentor
Mentor

Public Sub ChangeStyles()

 

Dim d As DrawingDocument
Set d = ThisApplication.ActiveDocument


d.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle = d.StylesManager.Styles.Item("YOUR STYLE NAME")

d.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.########### = d.StylesManager.Styles.Item("YOUR STYLE NAME")

d.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.########### = d.StylesManager.Styles.Item("YOUR STYLE NAME")

'ETC ETC

d.Save
End Sub

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 8 of 15

Anonymous
Not applicable

Hello Braden,

 

Thanks for your answer.. I have already tried this, but unfortunately it does not change the dropdown in th eimage.. instead it changes the default style, thus, changing the style of all the dimensions I already placed.. What i need is a way to set the style only for the currently active command (Dimension) and have the style applied only for the dimensions I am going to place while the command is active..

 

0 Likes
Message 9 of 15

bradeneuropeArthur
Mentor
Mentor

for me it does.

 

but you need to change the necessary dimension type!!! 

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 10 of 15

Anonymous
Not applicable

This is how i tried it:

 

place to sheets in the document. put a view on the first sheet, and one on the second sheet. 

Add a linear dimension with the default style on the second sheet.

 

go back to sheet 1, and run this:

 

 

[code]

 

' Get the CommandManager object.
Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager

' Get control definition for the line command.
Dim oControlDef As ControlDefinition
oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingGeneralDimensionCmd")
' Execute the command.
'Call oControlDef.Execute

Dim doc As DrawingDocument
doc = ThisApplication.ActiveDocument

doc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle = doc.StylesManager.DimensionStyles(2)

 

[/code]

 

Now place the linear dimension (command already activated by the script) on the view on sheet 1.

If you go to sheet 2 now, you will see that also the dimension you placed earlier using the default style has changed to the new style.

0 Likes
Message 11 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Your are right.

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 12 of 15

Anonymous
Not applicable

Do you think there is a solution? 

0 Likes
Message 13 of 15

bradeneuropeArthur
Mentor
Mentor

Hi,

 

I am still investigating the issue between other issues.

I will inform you about it I a solution is found, ok? 

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 14 of 15

nicolas_fruhauf
Community Visitor
Community Visitor

Any news 5 years later ??....

0 Likes
Message 15 of 15

nanduadityas
Community Visitor
Community Visitor

Try this

 

ThisDrawing.ActiveDimStyle = ThisDrawing.DimStyles(0)

0 Likes