Template open after Drawing resources update.

Template open after Drawing resources update.

Jesper_S
Collaborator Collaborator
618 Views
3 Replies
Message 1 of 4

Template open after Drawing resources update.

Jesper_S
Collaborator
Collaborator

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. 

 

Error.PNG

 

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.
0 Likes
Accepted solutions (1)
619 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

There are two tools for this situation, depending on if you still have access to the document object, or not.

You can use the following 'ReleaseReference' method for individual document situations, where the document is no longer being referenced by anything.

Document.ReleaseReference Method 

Or you can use the CloseAll method to clean-up after dealing with a bunch of documents (like after a loop, or at the end of a rule).  It has an option that allows you to only close 'unreferenced' documents.

Documents.CloseAll Method

These are primarily used to release memory, for performance reasons.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

You also try to close the document only.

For Each oDoc As Document In ThisApplication.Documents
	If oDoc.FullDocumentName = "C:\_Vault_WS\Libraries\Templates\Standard.idw" Then
		oDoc.Close(True)
	End If
Next

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 4

Jesper_S
Collaborator
Collaborator

Thanks alot. 

 

That was a simple and fast way to solve my problem.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes