close all opened drawings

close all opened drawings

m.magini
Participant Participant
426 Views
2 Replies
Message 1 of 3

close all opened drawings

m.magini
Participant
Participant

I have some drawings open in my inventor session.
I'd to run a macro saved in one file called "rule".dwg
macro simply gets the file name, display it with message box
and then close the "processed" file if it is not the "rule" one.
At th end only "rule" drawing will remain open.
I have some proble with close command line
oDocument.Close does nothing.

ThisApplication.Document.close returns error

Thanks for helping

 

' Declaration
Dim oDocument As DrawingDocument

' Starting cycle
For Each oDocument In ThisApplication.Documents.VisibleDocuments

' Get file name
Dim myoutputname As String
myoutputname = System.IO.Path.GetFileNameWithoutExtension(oDocument.FullFileName)

'Code
	If myoutputname <> "rule" Then
			MessageBox.Show(myoutputname, "Title")
			'oDocument.Close'????????
	Else
			MessageBox.Show("This file contains the rule", "Title")
	End If

'end for each cycle
Next

 

0 Likes
Accepted solutions (1)
427 Views
2 Replies
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @m.magini . In my case the code works fine. Maybe it's because I'm specifying True or False for the SkipSave value in the Close() method.

' Declaration
Dim oDocument As DrawingDocument

' Starting cycle
For Each oDocument In ThisApplication.Documents.VisibleDocuments

	' Get file name
	Dim myoutputname As String
	myoutputname = System.IO.Path.GetFileNameWithoutExtension(oDocument.FullFileName)
	
	'Code
		If myoutputname <> "rule" Then
				MessageBox.Show(myoutputname, "Title")
				'oDocument.Close'????????
		Else
				MessageBox.Show("This file contains the rule", "Title")
		End If
	
	'end for each cycle
	oDocument.Close(True)
Next

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 3

m.magini
Participant
Participant

Thanks, it works for me too now.

Thank you

Bye

0 Likes