Wanted to post this hoping others will find it useful. Works for most versions of Inventor.
Changes all dimensions, balloons, ect (define more if you want) to current object default in active standard.
Try it out, let me know if it works well for you.
Sub ChangeDimStyle() 'J.Kriek 2012 Dim oApp As Application Dim oIdw As DrawingDocument Dim oDim As DrawingDimension Dim oBalloon As Balloon Dim oDimStyle As DrawingStandardStyle Dim oSheet As Sheet Set oApp = ThisApplication Set oIdw = oApp.ActiveDocument Set oDimStyle = oIdw.StylesManager.ActiveStandardStyle For Each oSheet In oIdw.Sheets For Each oDim In oSheet.DrawingDimensions 'Add more Styles here If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.LinearDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.AngularDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.AngularDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.ChamferNoteStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.ChamferNoteStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.DiameterDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.DiameterDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.LeaderTextStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.LeaderTextStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.BendNoteStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.BendNoteStyle End If Next For Each oBalloon In oSheet.Balloons If oBalloon.Style.Name <> oDimStyle.ActiveObjectDefaults.BalloonStyle.Name Then oBalloon.Style = oDimStyle.ActiveObjectDefaults.BalloonStyle End If Next Next End Sub
Solved! Go to Solution.
Solved by jdkriek. Go to Solution.
Very nice. I've been trying to create something similiar for a couple of hours now. Thanks for the share, it's much appreciated.
Jon Brabbs
Hi
How do I use this rule in Inventor 2012 64bit. I am unfamiliar with I-logic, but this seems ideal for what I'm wanting to achieve. Any sort of help is welcome. Thanks
A
This is VBA (Visual Basic for Applications). It can be rewritten in iLogic fairly easy (essentially VB.NET)
Or you could use as is, simply go to Tools > VBA Editor > Paste it into a Module.
Then from iLogic you could run with
InventorVb.RunMacro("projectName", "moduleName", "macroName")
Or simply run it manually by adding it as a button. Right-click on toolbar > Customize User Commands > Change Drop-down to Macros > Select Macro > Click Add > Then Ok.
I appreciate your Help on this. I'm trying to get this to work, but may need some pointers.
I have some old Legacy drawings which I'm trying to bring up to date by applying the current standard’s Layers & Styles. My drawings are from 2003 and are typically using a local style called ANSI. I am looking to convert all Layers and styles to a new Active Standard called Default Standard (ISO). Presently, I am manually replacing all local styles within the Style Editor, but this is a long and tedious process and I have to do this for every drawing. Really, it’s something I should be automating.
For example, I wish to change all Linear, Diameter, Angular dimensions to Layer - Default Standard (ISO) and Style - Dimension ISO.
If you can point me in the right direction I’ll figure out how to do the rest of the layers such as Centerlines, Symbols, Annotations etc. I take it these will all have some sort of tag that I’ll need to find out in order to input them into the snippet, or do I just use the layer and style names within the angle brackets <> ?
Thanks again
Few questons first. Are you using the Style Library Manager (outside Inventor) for global styles? Is Default Standard (ISO) a global standard? Are Dimension ISO, ect setup as the Object Defaults for that standard?
This script will make sure all the elements specificed on the drawing get updated to the active standard. And yes they do have specific "tags" as you call them. Some even have diffrent methods in order to access them. It would be a proccess of letting me know which elements in addition to what's already here you need and me showing you that method.
Yes, I am using a Style Library Manager (which reads styles from an external folder), and the Standard I use is a modified Global ISO standard (mostly using Imperial units instead of Metric; 3rd Angle etc.). The object defaults have been set up for this.
If you like, I can show you a typical legacy drawing, as well as an up-to-date drawing with the layers applied by the Standard from the Style Library. This way you can see the styles that I am needing changed, and may, hopefully, be able to offer some advice.
I tend to carry out 'Drawing Resource Transfer Wizard' first, so that Drawing Border, Title block and Symbols can be transferred before I start replacing the Styles.
Ok, so when you go to Tools > Document Settings > Your Style is listed as the active standard?
If so, then script will work fine. We have the ability to change every elemenet on the drawing, including section and view labels, but not everyone needs those updated.
Just let me know what you need help with.
My style is the active standard, so yes, I am hoping to apply styles to the following:
Dimension; Text; Tables; Revision Table; Table.
Most of these use custom styles names that are no longer in the Active Standard i.e' COMPANY ANSI'; 'Table_COMPANY ANSI' etc. I wish to change these to 'Default (Imperial)' for example, which is now the Active Standard for the Styles.
I have attached a list of all the Object Types, i'd like to include in the Macro.
My question then would be where to find/identify the 'tags' and write them into the snippet?
@Anonymous wrote:My question then would be where to find/identify the 'tags' and write them into the snippet?
The nice thing about the VBA Editor is IntelliSense, which is an autocompletion system designed to help you troubleshoot and write code. If you copy any statement with oDimStyle.ActiveObjectDefaults and backspace the specific style off, then as you type "." it will trigger IntelliSense showing you all available "tags" (see image). Hope this helps.
Please note some styles like balloons will require thier own For Each() loop. While others don't support direct compare, so I had to go about them diffrently.
View labels are especiallly difficult, because the text DETAIL, SECTION, and VIEW was getting removed by resetting the style. So I had rewrite the text back in, but it was worth it to insure correct compliance with our standards.
This shows you a few diffrent methods.
Sub ChangeDimStyle() 'J.Kriek 2012 Set oApp = ThisApplication Set oIDW = oApp.ActiveDocument Set oDimStyle = oIDW.StylesManager.ActiveStandardStyle For Each oSheet In oIDW.Sheets For Each oDim In oSheet.DrawingDimensions 'Add more Dim Styles here 'Debug.Print "Name, Val: " & oDim.Style.Name & ", " & oDim.ModelValue If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.LinearDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.AngularDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.AngularDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.ChamferNoteStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.ChamferNoteStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.DiameterDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.DiameterDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.LeaderTextStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.LeaderTextStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.BendNoteStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.BendNoteStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.OrdinateDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.OrdinateDimensionStyle End If If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.OrdinateDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.OrdinateDimensionStyle End If 'Set automaticly because it doesn't support compare oDim.Style = oDimStyle.ActiveObjectDefaults.ChamferNoteStyle Next For Each oBalloon In oSheet.Balloons 'Debug.Print "Name: " & oBalloon.Style.Name If oBalloon.Style.Name <> oDimStyle.ActiveObjectDefaults.BalloonStyle.Name Then oBalloon.Style = oDimStyle.ActiveObjectDefaults.BalloonStyle End If Next Dim i As Integer For i = 1 To oSheet.DrawingViews.count Set oView = oSheet.DrawingViews.Item(i) If oView.ShowLabel = True Then 'B Size: .396 = .156 Text 'D Dize: .458 = .180in Text Dim LabelB As String Dim LabelD As String 'Added detection for type of view 9/5/2012 - JDK Select Case oView.ViewType Case kDetailDrawingViewType LabelB = "<StyleOverride FontSize='.396' Underline='True'>DETAIL <DrawingViewName/></StyleOverride>" LabelD = "<StyleOverride FontSize='.458' Underline='True'>DETAIL <DrawingViewName/></StyleOverride>" Case kSectionDrawingViewType LabelB = "<StyleOverride FontSize='.396' Underline='True'>SECTION <DrawingViewName/>-<DrawingViewName/></StyleOverride>" LabelD = "<StyleOverride FontSize='.458' Underline='True'>SECTION <DrawingViewName/>-<DrawingViewName/></StyleOverride>" Case kProjectedDrawingViewType LabelB = "<StyleOverride FontSize='.396' Underline='True'>VIEW <DrawingViewName/>-<DrawingViewName/></StyleOverride>" LabelD = "<StyleOverride FontSize='.458' Underline='True'>VIEW <DrawingViewName/>-<DrawingViewName/></StyleOverride>" Case kStandardDrawingViewType 'oView.ShowLabel = False LabelB = "<StyleOverride FontSize='.396' Underline='True'><DrawingViewName/></StyleOverride>" LabelD = "<StyleOverride FontSize='.458' Underline='True'><DrawingViewName/></StyleOverride>" End Select 'Set automaticly because it doesn't support compare oView.Label.TextStyle = oDimStyle.ActiveObjectDefaults.ViewLabelStyle 'Debug.Print "Name: " & oView.Label.TextStyle.Name Select Case oView.Label.TextStyle.Name Case "LABEL_B" oView.Label.FormattedText = LabelB Case "LABEL_B_16" oView.Label.FormattedText = LabelB Case "LABEL_D" oView.Label.FormattedText = LabelD Case "LABEL_D_16" oView.Label.FormattedText = LabelD End Select End If End If Next Next End Sub
Hi Johnathan,
I also have a similar situation where i need to change all the elements (dims, text, leaders etc) on an idw to the currently active style
Do you have a code snippet for this process?
regards
Mark Tommis
INV 2013 64bit
Hi jdkriek!
i try you rule but i have this error message?
And this is my rule
Dim oIDWDoc As DrawingDocument
oIDWDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDim As DrawingDimension
Dim oDimStyle As DrawingStandardStyle
Dim oGeneralDimensions As GeneralDimension
oDimStyle = oIDWDoc.StylesManager.ActiveStandardStyle
For Each oSheet In oIDWDoc.Sheets
For Each oDim In oSheet.DrawingDimensions
Debug.Print ("Style Name and Val: " & oDim.style.Name & " " & oDim.ModelValue)
If oDim.style.Name <> oDimStyle.ActiveObjectDefaults.LinearDimensionStyle.Name Then
iProperties.Value("Custom", "test1") = oDim.style.Name
iProperties.Value("Custom", "test2") = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle.Name
oDim.Style = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle
End If
If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.LeaderTextStyle.Name Then
oDim.Style = oDimStyle.ActiveObjectDefaults.LeaderTextStyle
End If
If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.AngularDimensionStyle.Name Then
oDim.Style = oDimStyle.ActiveObjectDefaults.AngularDimensionStyle
End If
If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.ChamferNoteStyle.Name Then
oDim.Style = oDimStyle.ActiveObjectDefaults.ChamferNoteStyle
End If
If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.DiameterDimensionStyle.Name Then
oDim.Style = oDimStyle.ActiveObjectDefaults.DiameterDimensionStyle
End If
Next
Next
Thanks for your help!
just want to spam a thank you. This saves me quite some time.
And you are not getting enough likes for your generous sharing!
Ok I have been cheering a bit too early.
Somehow this works:
MsgBox(oDim.Style.Name & " - " & oDimStyle.ActiveObjectDefaults.LinearDimensionStyle.Name)
But this fails:
oDim.style = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle
(Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
And it looked like easy copy paste code.
Also, when I look at all the options within DrawingDimension, I can't see 'Style'. msgbox(oDim.Style.Name) seems to work, but I dont see it in the 'intelliSense'. Why is that?
Ok so I currently work for a company that needs to update external drawings to their styles
If the styles does not exist, it updates the styles to some base style.
I wanted to update every dimension and balloon to the new style as explained in this post, only to learn that is not possible for every object (for example break lines, details or section lines were not updatable)
Then after some heavy meditating, I tried renaming the current style to the style that is in our styles library, and then update it. And that works flawless. So a whole day work for these few lines:
Dim oSTDStyle As DrawingStandardStyle = oStylMan.ActiveStandardStyle
If Not oSTDStyle.Name = "companyname" Then oSTDStyle.Name = "companyname"
For Each oStyle In oDoc.StylesManager.Styles
If oStyle.UpToDate = False Then
oStyle.UpdateFromGlobal()
End If
Next
Can't find what you're looking for? Ask the community or share your knowledge.