Updating Local Styles from Global Styles using VBA

Updating Local Styles from Global Styles using VBA

Anonymous
Not applicable
3,126 Views
2 Replies
Message 1 of 3

Updating Local Styles from Global Styles using VBA

Anonymous
Not applicable
Hi All
I have tried the following approach, but, it doesn't seem to work ... the SaveToGlobal fails with "Automation error Unspecified error" ... Approach is
1) Activate Drawing Template
2) Save Template Stlyes to Global
3) Activate Drawing
4) Copy Global Styles to the Drawing's Local Styles or Update the Drawing's Local Styles with the Global Styles


Dim oTdoc As Inventor.DrawingDocument --> Template
Dim oTstyle As Inventor.Style
Dim oDoc As Inventor.DrawingDocument --> Drawing
Dim strStyle As String

oTdoc.Activate
strStyle = oTdoc.StylesManager.ActiveStandardStyle.Name --> "StandardStyles"
oTdoc.StylesManager.ActiveStandardStyle.SaveToGlobal --> fails with "Automation error Unspecified error"

oDoc.Activate
If oDoc.StylesManager.StandardStyles(strStyle).InUse = False Then
Set oTstyle = oDoc.StylesManager.ActiveStandardStyle.ConvertToLocal.Copy(strStyle)
Else
oDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal
End If

Any assistance with this would be terrific ...
0 Likes
3,127 Views
2 Replies
Replies (2)
Message 2 of 3

Rene-J
Collaborator
Collaborator
Hi
This might help you ?
http://discussion.autodesk.com/adskcsp/thread.jspa?messageID=5207092

René J
0 Likes
Message 3 of 3

amattos
Enthusiast
Enthusiast
KL,

you can check this out, it may help...

This is a late update of the thread "Drawing Styles Update via VBA" http://discussion.autodesk.com/adskcsp/thread.jspa?messageID=5700442 and could be helpful...

Using Inv 11 API only supports 5 of 18 styles of Inventor. The good news is that Inventor 2008 supports a base class ("Style"). A generic Styles collection is provided. You can simply loop thru all styles (no special casing needed) and update the required ones. See my VBA Macro for a batch Styles Update from the Styles Library(already includes the IV2008 Styles definition). It is NOT fast but works.

Good luck

'----------------------------------------------------------
Sub IDW_UpdateStylesIV2008()
'message box strings
msgPrm1 = " This Macro Only Works with Drawings Documents "
msgPrm2 = " Please open a Drawing "
msgTit = "Wrong Active Document Type"
Prm1 = Len(msgPrm1) + 4
Prm2 = Len(msgPrm2) + 4
Tit = Len(msgTit)
cmsgPrm2 = String((Prm1 - Prm2) / 2, Chr(32)) & msgPrm2
cmsgTit = String((Prm1 - Prm2) / 2, Chr(32)) & msgTit

'check if the active document is a drawing document
If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
Dim oIDW As DrawingDocument
Set oIDW = ThisApplication.ActiveDocument

Dim oIDWStyles As Inventor.DrawingStylesManager
Set oIDWStyles = oIDW.StylesManager
Else
MsgBox msgPrm1 & Chr(13) & Chr(13) & cmsgPrm2, vbExclamation, cmsgTit
End If

Dim i As Integer

'loop thru all styles and check if they are up to date
For i = 1 To oIDWStyles.StandardStyles.Count
'Debug.Print "Std Styles - " + oIDWStyles.StandardStyles.Item(I).Name
If oIDWStyles.StandardStyles.Item(i).UpToDate = False Then
oIDWStyles.StandardStyles.Item(i).UpdateFromGlobal
End If
Next

For i = 1 To oIDWStyles.ObjectDefaultsStyles.Count
'Debug.Print "Obj Def Styles - " + oIDWStyles.ObjectDefaultsStyles.Item(I).Name
If oIDWStyles.ObjectDefaultsStyles.Item(i).UpToDate = False Then
oIDWStyles.ObjectDefaultsStyles.Item(i).UpdateFromGlobal
End If
Next

For i = 1 To oIDWStyles.DimensionStyles.Count
'Debug.Print "Dim Styles - " + oIDWStyles.DimensionStyles.Item(I).Name
If oIDWStyles.DimensionStyles.Item(i).UpToDate = False Then
oIDWStyles.DimensionStyles.Item(i).UpdateFromGlobal
End If
Next

For i = 1 To oIDWStyles.TextStyles.Count
'Debug.Print "TXT Styles - " + oIDWStyles.TextStyles.Item(I).Name
If oIDWStyles.TextStyles.Item(i).UpToDate = False Then
oIDWStyles.TextStyles.Item(i).UpdateFromGlobal
End If
Next

For i = 1 To oIDWStyles.Layers.Count
'Debug.Print "Layers Styles - " + oIDWStyles.Layers.Item(I).Name
If oIDWStyles.Layers.Item(i).UpToDate = False Then
oIDWStyles.Layers.Item(i).UpdateFromGlobal
End If
Next

'Inv2008 Styles Class
For i = 1 To oIDWStyles.Styles.Count
Debug.Print "Styles - " + oIDWStyles.Styles.Item(I).Name
If oIDWStyles.Styles.Item(i).UpToDate = False Then
oIDWStyles.Styles.Item(i).UpdateFromGlobal
End If
Next

oIDW.Update
oIDW.Save
'set Drawing settings
If oIDW.DrawingSettings.DeferUpdates = True Then
oIDW.DrawingSettings.DeferUpdates = False
oIDW.Save
End If
'oIDW.Close
End Sub
'----------------------------------------------------
0 Likes