Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
Got a small issue.
Got this iLogic to update the Drawing Resources on my drawings.
Works fine and updates Everything.
The problem comes later, after running this code on a drawing, I can't start a new Drawing from the Template.
I get this error.
So the question is, How do I Close an Invisible Drawing?
'List of Variables
Dim oDrawingDoc As Inventor.DrawingDocument
Dim oSheetNumber As Integer
Dim oActiveSheetNumber As Integer
Dim oActiveSheetName As String
Dim oSheet As Sheet
Dim oSourceTitleBlockDef As TitleBlockDefinition
Dim oNewTitleBlockDef As TitleBlockDefinition
'Selects this document
oDrawingDoc = ThisApplication.ActiveDocument
'Checks if there is a Title Block on the Active Sheet
oDrawingDoc = ThisApplication.ActiveDocument
If oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
MessageBox.Show ("Please Insert a Title Block on this Sheet!")
Exit Sub
End If
'Gets the Name of the Active Sheet to Activate it at the end of the Code
oActiveSheetName = ActiveSheet.Name
'Gets the Name of the Title Block Currently in the Drawing to Insert at the end of this code
oSheet = oDrawingDoc.ActiveSheet
If (oSheet.TitleBlock.Name = "Rithuvud") Then
oTitleBlockName = "Rithuvud"
Else:
MessageBox.Show ("This drawing has an unknown title block")
Exit Sub
End If
'Gets the Name of the Border Currently in the Drawing to Insert at the end of this code
Try
oBorderName = oSheet.Border.Name
Catch
MessageBox.Show("No border exists", "Title")
Exit Sub
End Try
'Deletes ALL of the Title Blocks Shown in the Drawing
For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(oSheetNumber).Activate
If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then
oDrawingDoc.ActiveSheet.TitleBlock.Delete
End If
Next oSheetNumber
'MessageBox.Show (oActiveSheetName & vbCr & oTitleBlockName)
Dim oTitle As TitleBlockDefinition
Dim oTitleBlock As TitleBlock
For Each oTitle In oDrawingDoc.TitleBlockDefinitions
If oTitle.IsReferenced = False Then
oTitle.Delete
End If
Next
'Deletes ALL of the Borders Shown in the Drawing
For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(oSheetNumber).Activate
If Not oDrawingDoc.ActiveSheet.Border Is Nothing Then
oDrawingDoc.ActiveSheet.Border.Delete
End If
Next oSheetNumber
'Clear drawing resources
If oCurrentPane = "Vault" Then
ThisApplication.ActiveDocument.BrowserPanes.Item("Model").Activate
End If
'delete sheet formats
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveEditDocument
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.ActivePane
Dim oDocNode As BrowserNode
oDocNode = oPane.TopNode
Dim oDrawingResourceNode As BrowserNode
oDrawingResourceNode = oDocNode.BrowserNodes.Item("Drawing Resources")
Dim oTitleBlocksNode As BrowserNode
oTitleBlocksNode = oDrawingResourceNode.BrowserNodes.Item("Sheet Formats")
Dim oBordersNode As BrowserNode
oBordersNode = oDrawingResourceNode.BrowserNodes.Item("Borders")
Dim oTitleBlocks As BrowserNode
oTitleBlocks = oDrawingResourceNode.BrowserNodes.Item("Title Blocks")
Dim oNode As BrowserNode
For Each oNode In oTitleBlocksNode.BrowserNodes'oDocNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = False Then
oNode.Expanded = True
End If
Next
For Each oNode In oBordersNode.BrowserNodes'oDocNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = False Then
oNode.Expanded = True
End If
Next
For Each oNode In oTitleBlocks.BrowserNodes'oDocNode.BrowserNodes
' If the node is visible and expanded, collapse it.
If oNode.Visible = True And oNode.Expanded = False Then
oNode.Expanded = True
End If
Next
Dim oSheetFormatNode As BrowserNode
For Each oSheetFormatNode In oTitleBlocksNode.BrowserNodes
' Select the node in the browser.
oSheetFormatNode.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'Dim oBordersNode As BrowserNode
For Each oBordersNode In oBordersNode.BrowserNodes
' Select the node in the browser.
oBordersNode.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
For Each oTitleBlocks In oTitleBlocks.BrowserNodes
' Select the node in the browser.
oTitleBlocks.DoSelect
' Execute the delete command.
ThisApplication.CommandManager.ControlDefinitions.Item("AppDeleteCmd").Execute
Next
'Adds the Title Blocks from the Template File
ThisDrawing.ResourceFileName = "C:\_Vault_WS\Libraries\Templates\Standard.idw"
ThisDrawing.KeepExtraResources = True
'Add Borders
ActiveSheet.Border = "A1"
ActiveSheet.Border = "A2"
ActiveSheet.Border = "A3"
ActiveSheet.Border = "A4"
'Adds the Same Title Block as before
For oSheetNumber = 1 To oDrawingDoc.Sheets.Count
oDrawingDoc.Sheets(oSheetNumber).Activate
ActiveSheet.TitleBlock = oTitleBlockName
ActiveSheet.Border = oBorderName
Next oSheetNumber
'Activates the Sheet by Full Name
ActiveSheet = ThisDrawing.Sheet(oActiveSheetName)
Thanks in advance.
//Jesper
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Solved! Go to Solution.