Select all ballons and dimensions to overwrite the styles

Select all ballons and dimensions to overwrite the styles

Anonymous
Not applicable
1,865 Views
14 Replies
Message 1 of 15

Select all ballons and dimensions to overwrite the styles

Anonymous
Not applicable

I would like to select all ballons and dimensions in the drawing and change current style to new one. Here i have the code (unfortunately i just started to learn ilogic and dont have expiarence with it) and something goes wrong. The same id like to do for welding symbols but i have no idea how to adaptate it accordingly. Thank you for any ideas

 

 

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oStyles As DrawingStylesManager
oStyles = oDrawDoc.StylesManager

Dim oSheet As Sheet
Dim oBalloon As Balloon
Dim oDrawingDim As DrawingDimension

For Each oSheet In oDrawDoc.Sheets 
	'change ballons
	For Each oBalloon In oSheet.Balloons
		oBalloon.Style = oStyles.BalloonStyles.Item("DC-STD_Ballon")
	Next
	
' Iterate over all dimensions in the drawing and change style
For Each oDrawingDim In oSheet.DrawingDimensions
	oDrawingDim.Style = oStyles.DimensionStyle.Item("DC-STD_Dim")
    Next
	
Next
0 Likes
Accepted solutions (1)
1,866 Views
14 Replies
Replies (14)
Message 2 of 15

bradeneuropeArthur
Mentor
Mentor

Welding symbols are not API supported!

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 15

Anonymous
Not applicable

Okay, how to repair code to ajust changing style of dimensions?

0 Likes
Message 4 of 15

bradeneuropeArthur
Mentor
Mentor

for me that code works fine.

what is wrong than?

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

Anonymous
Not applicable

I have next error message

Error in rule: select all dimensions and ballons, in document: 08518915.idw

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

______

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.BalloonStylesEnumerator.get_Item(Object Index)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 6 of 15

bradeneuropeArthur
Mentor
Mentor

can you send one drawing with:

  • one balloon with each style
  • one dimension in it with each style

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

Anonymous
Not applicable

Please find it in attached. Thanks

0 Likes
Message 8 of 15

WCrihfield
Mentor
Mentor

Hi @Anonymous .  The error message is saying it is having trouble with the portion of your one line of code, where it is trying to retrieve a balloon style.  Is there a copy of that specifically named style in your local document, or is it only present in the global/external style library?  You may need make sure the style is copied from the style library to your local document, before trying to assign it to objects in your drawing like this.

Also, I noticed that your line of code which is trying  to set the dimension style by name, is missing a letter at the end of one of the words.  "oStyles.DimensionStyle.Item("DC-STD_Dim")" is missing the "s" at the end of DimensionStyle(s), so it should be oStyles.DimensionStyles.Item("DC-STD_Dim").  The same goes for making sure the dimension style is available locally in the document.

Try this code, and see if it works any better for you:

 

 

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oStyles As DrawingStylesManager = oDrawDoc.StylesManager
'name of the balloon style
Dim oBStyleName As String = "DC-STD_Ballon"
'name of the dimesion style
Dim oDStyleName As String = "DC-STD_Dim"

Dim oMyBStyle As BalloonStyle
For Each oBStyle As BalloonStyle In oStyles.BalloonStyles
	If oBStyle.Name = oBStyleName Then
		oMyBStyle = oBStyle.ConvertToLocal
	End If
Next
If oMyBStyle Is Nothing Then
	MsgBox("Couldn't find a balloon style named '" & oBStyleName & "'.  Exiting.", , "")
	Exit Sub
End If

Dim oMyDimStyle As DimensionStyle
For Each oDStyle As DimensionStyle In oStyles.DimensionStyles
	If oDStyle.Name = oDStyleName Then
		oMyDimStyle = oDStyle.ConvertToLocal
	End If
Next
If oMyDimStyle Is Nothing Then
		MsgBox("Couldn't find a dimension style named '" & oDStyleName & "'.  Exiting.", , "")
	Exit Sub
End If

Dim oSheet As Sheet
Dim oBalloon As Balloon
Dim oDrawingDim As DrawingDimension

For Each oSheet In oDrawDoc.Sheets 
	'change ballons
	For Each oBalloon In oSheet.Balloons
		Try
			oBalloon.Style = oMyBStyle
		Catch
			MsgBox("Failed to set balloon style.",,"")
		End Try
	Next
	
	' Iterate over all dimensions in the drawing and change style
	For Each oDrawingDim In oSheet.DrawingDimensions
		Try
			oDrawingDim.Style = oMyDimStyle
		Catch
			MsgBox("Failed to set dimension style.",,"")
		End Try
    Next
Next

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 15

Anonymous
Not applicable

Unfortunately in my drawings its not working. But strage because i have Ballon and Dimensions styles in my local styles. Screenshot_1.jpgScreenshot_2.jpg

0 Likes
Message 10 of 15

WCrihfield
Mentor
Mentor

Hmm... I may have missed a step by not first checking the style's location, before attempting to convert it to local.  I'm not sure, but that method may return Nothing when the style was already local, causing the problem.  I updated the code to include checking the styles location first.  When it is located in the library, it then proceeds to convert it to local (or both), and if it is already either local or both, it will simply transfer the style to our final variable for use below.

I also updated the last part of the code, where it attempts to update the styles of the dimensions, because the DrawingDimension object doesn't have a Style property, but it's derived dimension type objects do have that property.

Give this a try:

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oStyles As DrawingStylesManager = oDrawDoc.StylesManager
'name of the balloon style
Dim oBStyleName As String = "DC-STD_Ballon"
'name of the dimesion style
Dim oDStyleName As String = "DC-STD_Dim"

Dim oMyBStyle As BalloonStyle
For Each oBStyle As BalloonStyle In oStyles.BalloonStyles
	If oBStyle.Name = oBStyleName Then
		If oBStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
			oMyBStyle = oBStyle.ConvertToLocal
		Else
			'it is located in both the library and local
			oMyBStyle = oBStyle
		End If
	End If
Next
If oMyBStyle Is Nothing Then
	MsgBox("Couldn't find a balloon style named '" & oBStyleName & "'.  Exiting.", , "")
	Exit Sub
End If

Dim oMyDimStyle As DimensionStyle
For Each oDStyle As DimensionStyle In oStyles.DimensionStyles
	If oDStyle.Name = oDStyleName Then
		If oDStyle.StyleLocation = StyleLocationEnum.kLibraryStyleLocation Then
			oMyDimStyle = oDStyle.ConvertToLocal
		Else
			'it is located both the library and local
			oMyDimStyle = oDStyle
		End If
	End If
Next
If oMyDimStyle Is Nothing Then
		MsgBox("Couldn't find a dimension style named '" & oDStyleName & "'.  Exiting.", , "")
	Exit Sub
End If

For Each oSheet As Inventor.Sheet In oDrawDoc.Sheets 
	'change ballons
	For Each oBalloon As Inventor.Balloon In oSheet.Balloons
		Try
			oBalloon.Style = oMyBStyle
		Catch
			MsgBox("Failed to set balloon style.",,"")
		End Try
	Next
	
	'update dimension styles
	Dim oDDims As DrawingDimensions = oSheet.DrawingDimensions
	For Each oGDim As GeneralDimension In oDDims.GeneralDimensions
		oGDim.Style = oMyDimStyle
    Next
	For Each oBLDim As BaselineDimensionSet In oDDims.BaselineDimensionSets
		oBLDim.Style = oMyDimStyle
	Next
	For Each oCDimSet As ChainDimensionSet In oDDims.ChainDimensionSets
		oCDimSet.Style = oMyDimStyle
	Next
	For Each oOrdDim As OrdinateDimension In oDDims.OrdinateDimensions
		oOrdDim.Style = oMyDimStyle
	Next
	For Each oODimSet As OrdinateDimensionSet In oDDims.OrdinateDimensionSets
		oODimSet.Style = oMyDimStyle
	Next
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 15

Anonymous
Not applicable

Unfortunately the same situation. Did you try this code on your computer? 

0 Likes
Message 12 of 15

WCrihfield
Mentor
Mentor
Accepted solution

Yes.  It worked on my machine, after I created the same two styles in a test drawing document, then created some dimensions and balloons using another style to monitor.  But there was one obvious little mistake in the code I posted, that I had to correct before it would run correctly.  I misspelled the name of the Balloon Style name right at the top, where I'm assigning it to the String variable. 🙄  In the code I posted I had typed it in as "DC-STD_Ballon", when it should have been "DC-STD_Balloon".  Sorry about that.  Apparently, I had never altered it from your original copied over code, because it was misspelled there too. 😂

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 15

Anonymous
Not applicable

Thanks! Ive changed the code a litle and now its works nice!

0 Likes
Message 14 of 15

Anonymous
Not applicable
 

 

0 Likes
Message 15 of 15

WCrihfield
Mentor
Mentor

That's a tough one.  When you place a dimension on a drawing, it is initially the way it's style dictates.  If you do anything special to that dimension afterwards, like change its displayed precision, set it to show tolerance, change the tolerance's displayed precision, those settings will be lost when you switch that dimension's style to another style, because those special settings likely aren't standard in the new style.

 

It might be possible, but depending on how we choose to deal with that situation, it could potentially make the code a lot more complicated.  Each dimension type object has some properties we can check (Precision, Tolerance, Tolerance Precision, etc.).  Whether we choose to simply check to see if they are set to a certain value, or if we attempt to compare their value to an equivalent property value in the new style object, is one choice we would have to make.  Then what to do about it if they are set to those certain values, or if the comparison results one way or the other is the next choice we would have to make.  One option would be to simply not change that dimension's style over to the new style, if it is settings are a certain way (the simpler option).  The next option (and more complex) would be to attempt to record how these things are currently set within the dimension object, then change the dimension's style to the new style (the dimension looses those custom settings), then attempt to re-set those settings within the dimension object afterwords.  Since we have 5 different loops for the different types of dimension objects, I would recommend putting this checking piece of code into a reference Sub or Function of its own, below Sub Main...your existing code...End Sub, so it can be called to run within each of those 5 loops.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes