- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Update old Drawings to current Template help
Hi All,
I am looking for help to create an ilogic to update old drawings to match our standard current template.
If possible id like to to update the title block and border, update styles to standard and purge old styles.
Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok so I have searched and managed to put a few different Ilogics together.
Firstly I open an old drawing and delete unused drawing resources then run the ilogic.
It seems to do what I would like except I have to run the ilogic twice to purge old styles.
Things id like to try add:
1. Delete un used drawing resources in old drawing
2. Id like to get it to copy the sheet formats as well
3. Fix the need to run it twice to purge styles completly
Thanks
Option Explicit
Imports System.Windows.Forms
Dim oTargetDoc, oSourceDoc As DrawingDocument
Dim oTBdef As TitleBlockDefinition
Dim oTBdefs As TitleBlockDefinitions
Dim oBorderDef As BorderDefinition
Dim oBorderDefs As BorderDefinitions
Dim oSymbol As SketchedSymbolDefinition
Dim oSymbols As SketchedSymbolDefinitions
Dim oPrompt As String
If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then
MsgBox("This rule may only be run on drawing documents!",vbOKOnly,"Update Titleblocks")
Exit Sub
End If
oTargetDoc = ThisDrawing.Document
oPrompt = MsgBox("Update Titleblocks and Styles?",vbYesNo,"Update Titleblocks")
Select Case oPrompt
Case vbNo
Exit Sub
Case vbYes
oSourceDoc = ThisApplication.Documents.Open("C:\_Vault\WS\Standards\Inventor Templates\Standard.idw", False)
oTargetDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal
End Select
oTBdefs = oSourceDoc.TitleBlockDefinitions
oBorderDefs = oSourceDoc.BorderDefinitions
oSymbols = oSourceDoc.SketchedSymbolDefinitions
For Each oTBdef In oTBdefs
Try
If oTBdef.Name <> "ANSI - Large" Then
oTBdef.CopyTo(oTargetDoc, True)
End If
Catch
MsgBox("Unknown error in copy title block for " & Chr(34) & oTBdef.Name & Chr(34),vbOKOnly,"Error")
End Try
Next
For Each oBorderDef In oBorderDefs
Try
If oBorderDef.Name <> "Default Border" Then
oBorderDef.CopyTo(oTargetDoc, True)
End If
Catch
MsgBox("Unknown error in copy border definition for " & Chr(34) & oBorderDef.Name & Chr(34),vbOKOnly,"Error")
End Try
Next
For Each oSymbol In oSymbols
Try
oSymbol.CopyTo(oTargetDoc, True)
Catch
MsgBox("Unknown error in copy sketched symbol for " & Chr(34) & oSymbol.Name & Chr(34),vbOKOnly,"Error")
End Try
Next
'Set Styles Standard to suit Template
Const kStandardName = "Company Standards"
Const kObjDefaultsName = "My Defaults"
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oStylesMgr As DrawingStylesManager
oStylesMgr = oDoc.StylesManager
Dim oStandard As DrawingStandardStyle
oStandard = oStylesMgr.StandardStyles _
.Item(kStandardName)
If oStandard Is Nothing Then
oStandard = oStylesMgr.StandardStyles _
.Item(1).Copy(kStandardName)
End If
oStylesMgr.ActiveStandardStyle = oStandard
'Update Sytles
Dim oCM As CommandManager = ThisApplication.CommandManager
Dim oCD As ControlDefinitions = oCM.ControlDefinitions
Dim oUpdateStyles As ControlDefinition = oCD.Item("UpdateStylesCmd")
oUpdateStyles.Execute2(False)
SendKeys.SendWait("Y ")
'Purge Styles
Dim doc As Document = ThisApplication.ActiveDocument
If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
Dim dDoc As DrawingDocument = doc
Dim styles As styles = dDoc.StylesManager.Styles
For Each styl As Style In styles
If (styl.InUse = False And styl.StyleLocation <> StyleLocationEnum.kLibraryStyleLocation) Then
styl.Delete()
End If
Next
ElseIf (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
For Each Asset As Asset In doc.Assets
If (Asset.IsUsed = False) Then
If (Asset.AssetType = AssetTypeEnum.kAssetTypeMaterial Or
Asset.AssetType = AssetTypeEnum.kAssetTypeAppearance) Then
Asset.Delete()
End If
End If
Next
End If
'---Execute twice---
If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
Dim dDoc As DrawingDocument = doc
Dim styles As styles = dDoc.StylesManager.Styles
For Each styl As Style In styles
If (styl.InUse = False And styl.StyleLocation <> StyleLocationEnum.kLibraryStyleLocation) Then
styl.Delete()
End If
Next
ElseIf (doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
For Each Asset As Asset In doc.Assets
If (Asset.IsUsed = False) Then
If (Asset.AssetType = AssetTypeEnum.kAssetTypeMaterial Or
Asset.AssetType = AssetTypeEnum.kAssetTypeAppearance) Then
Asset.Delete()
End If
End If
Next
End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
For 2. all that is required is to loop through the sheetformats collection in the drawing document, get the sheetformat object and use the copy method.
See Links to the API help embeded
Syntax
DrawingDocument.SheetFormats() As SheetFormats
Syntax
SheetFormat.CopyTo( TargetDocument As DrawingDocument ) As SheetFormat
For 1. Loop through each object from the drawing document and try and delete. Use try catch statement. It will not delete anything that is currently in use in the sheet.
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here is the copy for loop for the sheet format
For Each oShtFormat as SheetFormat in oSourceDoc.SheetFormats
oShtFormat.CopyTo( oTargetDoc)
NextTo delete target Drawing resources not in use. *Note: Only run this at the end when you want to purge any unused items. Any resources contained in the sheet will remain untouched.
oTBdefs = oTargetDoc.TitleBlockDefinitions
oBorderDefs = oTargetDoc.BorderDefinitions
oSymbols = oTargetDoc.SketchedSymbolDefinitions
For Each oTBdef In oTBdefs
Try
oTBdef.Delete
Catch
MsgBox("Unknown error in copy title block for " & Chr(34) & oTBdef.Name & Chr(34),vbOKOnly,"Error")
End Try
Next
For Each oBorderDef In oBorderDefs
Try
oBorderDef.Delete
Catch
MsgBox("Unknown error in copy border definition for " & Chr(34) & oBorderDef.Name & Chr(34),vbOKOnly,"Error")
End Try
Next
For Each oSymbol In oSymbols
Try
oSymbol.Delete
Catch
MsgBox("Unknown error in copy sketched symbol for " & Chr(34) & oSymbol.Name & Chr(34),vbOKOnly,"Error")
End Try
Next
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If I run the sheet copy part with my script it copys everything fine, but because I need to run the script twice to purge old styles it creates double of each sheet ect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Unfortunately I have not much experience with updating styles. It sounds like if you need to run the rule twice it is only doing a partial update. This post here describes in more detail how to set this up without using the control definition update style. In your case if your not comfortable with the longer method discussed there you may be able to place the update style in a sub routine and just call it twice in the same rule. If you need more assistance just post the code your working with and hopefully someone can spot the required changes.
Or if this helped you, please, click (like)
Regards
Alan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi,
i use:
For i = 1 To odraw.StylesManager.DimensionStyles.Count
If odraw.StylesManager.DimensionStyles.Item(i).UpToDate = False Then
odraw.StylesManager.DimensionStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.StandardStyles.Count
If odraw.StylesManager.StandardStyles.Item(i).UpToDate = False Then
odraw.StylesManager.StandardStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.BalloonStyles.Count
If odraw.StylesManager.BalloonStyles.Item(i).UpToDate = False Then
odraw.StylesManager.BalloonStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.CentermarkStyles.Count
If odraw.StylesManager.CentermarkStyles.Item(i).UpToDate = False Then
odraw.StylesManager.CentermarkStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.FeatureControlFrameStyles.Count
If odraw.StylesManager.FeatureControlFrameStyles.Item(i).UpToDate = False Then
odraw.StylesManager.FeatureControlFrameStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.HoleTableStyles.Count
If odraw.StylesManager.HoleTableStyles.Item(i).UpToDate = False Then
odraw.StylesManager.HoleTableStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.LeaderStyles.Count
If odraw.StylesManager.LeaderStyles.Item(i).UpToDate = False Then
odraw.StylesManager.LeaderStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.ObjectDefaultsStyles.Count
If odraw.StylesManager.ObjectDefaultsStyles.Item(i).UpToDate = False Then
odraw.StylesManager.ObjectDefaultsStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.PartsListStyles.Count
If odraw.StylesManager.PartsListStyles.Item(i).UpToDate = False Then
odraw.StylesManager.PartsListStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.RevisionTableStyles.Count
If odraw.StylesManager.RevisionTableStyles.Item(i).UpToDate = False Then
odraw.StylesManager.RevisionTableStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.StandardStyles.Count
If odraw.StylesManager.StandardStyles.Item(i).UpToDate = False Then
odraw.StylesManager.StandardStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.TableStyles.Count
If odraw.StylesManager.TableStyles.Item(i).UpToDate = False Then
odraw.StylesManager.TableStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.TextStyles.Count
If odraw.StylesManager.TextStyles.Item(i).UpToDate = False Then
odraw.StylesManager.TextStyles.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.Layers.Count
If odraw.StylesManager.Layers.Item(i).UpToDate = False Then
odraw.StylesManager.Layers.Item(i).UpdateFromGlobal()
End If
Next
For i = 1 To odraw.StylesManager.Styles.Count
If odraw.StylesManager.Styles.Item(i).UpToDate = False Then
odraw.StylesManager.Styles.Item(i).UpdateFromGlobal()
End If
Next
Dim oStyles As DrawingStylesManager = odraw.StylesManager
Dim noneleft As Boolean = True
Dim ostyle As Style
Do While (noneleft)
noneleft = False
For Each ostyle In oStyles.Styles
If ostyle.StyleLocation = 51202 And ostyle.InUse = False Then
' uncomment next line to see styles being deleted
' MsgBox(ostyle.Name)
ostyle.Delete()
noneleft = True
End If
Next
Loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If I try to run your rule I get:
Line 1: 'odraw' is not declared. It may be inaccessible due to its protection level
Line 76 : Type 'DrawingStylesManager' is not defined
line 78 ; Type ' Style' is not defined
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
this was only part of code.
to ruyn it add in first line :
Dim odraw As DrawingDocument = ThisDoc.Document