Message 1 of 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have changed a Ilogic rule i have found to change the template and styles from a drawing.
The only thing that isn't working is exchanging the border.
I can't find the fault in this rule.
Sub Main If ThisDoc.Document.DocumentType <> kDrawingDocumentObject Then MsgBox("This rule may only be run on drawing documents!",vbOKOnly,"Update Everything") Exit Sub End If Dim oPrompt As String oPrompt = MsgBox("Update Titleblocks and Styles?", vbYesNo, "Update Everything") Select Case oPrompt Case vbNo Exit Sub Case vbYes 'MessageBox.Show("START", "Title") ImportTemplateItems() 'Copy all stuf over from the Template file. 'MessageBox.Show("Import OK", "Title") ReplaceTitleBlock() 'Replace the current Titleblock with the new Titleblock on all sheets. 'MessageBox.Show("TitleBlock OK", "Title") ReplaceBorder() 'Replace the current border with the new border on all sheets. 'MessageBox.Show("Border OK", "Title") SetActiveStyle() 'Set the Relco Global Style as active. 'MessageBox.Show("Set Active Style OK", "Title") PurgeStyles() 'MessageBox.Show("PurgeStyle", "Title") DimensionUpdates() ' 'MessageBox.Show("Change Dim OK", "Title") End Select End Sub Sub ImportTemplateItems() 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 oTargetDoc = ThisDrawing.Document oSourceDoc = ThisApplication.Documents.Open("K:\Inventor\Inventor settings\Templates\Part.idw", False) 'oTargetDoc.StylesManager.ActiveStandardStyle.UpdateFromGlobal 'TURNED OF BECAUSE OF CONFLICT. Why is this broken? oTBdefs = oSourceDoc.TitleBlockDefinitions oBorderDefs = oSourceDoc.BorderDefinitions oSymbols = oSourceDoc.SketchedSymbolDefinitions For Each oTBdef In oTBdefs Try If oTBdef.Name = "(E) Manders" Then 'Make this string your new TitleBlock name 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 oSourceDoc.Close() End Sub Sub ReplaceTitleBlock() Dim i As Integer 'Replace Titleblock Dim oTitle0 As String oTitle0 = "(E) Manders" 'This should be the New Titleblock ' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Obtain a reference to the desired border defintion. Dim oTitleBlockDef As TitleBlockDefinition oTitleBlockDef = oDrawDoc.TitleBlockDefinitions.Item(oTitle0) Dim oSheet As Sheet 'Count the number of total sheets Dim SheetCount As Integer SheetCount = oDrawDoc.Sheets.Count If (oDrawDoc.Sheets.Count > 0) Then 'Execute if >1 sheets For Each s In oDrawDoc.Sheets s.Activate 'Activate sheet oSheet = oDrawDoc.ActiveSheet ' Check to see if the sheet already has the correct title block and delete it if it doesn't. If Not oSheet.TitleBlock Is oTitle0 Then oSheet.TitleBlock.Delete End If Dim oTitleBlock As TitleBlock oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef) Next Else MessageBox.Show("There is only 1 Sheet. Make more sheets and come back", "Nothing to do") End If End Sub Sub ReplaceBorder() Dim i As Integer 'Replace border Dim oBorder0 As String oBorder0 = "Default Border" 'This should be the New Border ' Set a reference To the drawing document. 'This assumes a drawing document Is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Obtain a reference To the desired border defintion. Dim oBorderDef As BorderDefinition oBorderDef = oDrawDoc.BorderDefinitions.Item(oBorder0) Dim oSheet As Sheet 'Count the number Of total sheets Dim SheetCount As Integer SheetCount = oDrawDoc.Sheets.Count If (oDrawDoc.Sheets.Count > 0) Then 'Execute if >1 sheets For Each s In oDrawDoc.Sheets s.Activate 'Activate sheet oSheet = oDrawDoc.ActiveSheet ' Check To see If the Sheet already has the correct Border And delete it If it doesn't. If Not oSheet.Border Is oBorder0 Then oSheet.Border.Delete End If Dim oBorder As Border oBorder = oSheet.AddBorder(oBorderDef) Next Else MessageBox.Show("There is only 1 Sheet. Make more sheets and come back", "Nothing to do") End If End Sub Sub PurgeStyles() Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oStyles oStyles = oDrawDoc.StylesManager Dim noneleft As Boolean noneleft = 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 ostyle.Delete noneleft = True End If Next Loop End Sub Sub SetActiveStyle() Const kStandardName = "Manders 2021" Const kObjDefaultsName = "Verwijzingen Manders (engels)" Dim oDoc As DrawingDocument On Error Resume Next 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 ' create object defaults Dim oObjDefaults As ObjectDefaultsStyle oObjDefaults = oStylesMgr. _ ObjectDefaultsStyles.Item(kObjDefaultsName) If oObjDefaults Is Nothing Then oObjDefaults = oStylesMgr. _ ObjectDefaultsStyles.Item(1). _ Copy(kObjDefaultsName) End If oStandard.ActiveObjectDefaults = oObjDefaults ' activate standard oStylesMgr.ActiveStandardStyle = oStandard End Sub Private Sub DimensionUpdates() Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument Dim oDim As GeneralDimension Dim oDimStyle As DrawingStandardStyle Dim oSheet As Sheet oDimStyle = oDoc.StylesManager.ActiveStandardStyle For Each oSheet In oDoc.Sheets For Each oDim In oSheet.DrawingDimensions If oDim.Style.Name <> oDimStyle.ActiveObjectDefaults.AngularDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.AngularDimensionStyle End If If oDimStyle.Name <> oDimStyle.ActiveObjectDefaults.LinearDimensionStyle.Name Then oDim.Style = oDimStyle.ActiveObjectDefaults.LinearDimensionStyle End If Next Next End Sub
Solved! Go to Solution.