API - Close drawing when string matches

API - Close drawing when string matches

Anonymous
Not applicable
506 Views
2 Replies
Message 1 of 3

API - Close drawing when string matches

Anonymous
Not applicable

This should close the drawing when sting matches. I dont know why this doest work. Tested it with other value, its fine.

 

 

Dim oFileDlg As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Autodesk Inventor Drawings (*.idw)|*.idw"
oFileDlg.DialogTitle = "Select Drawings To Check"
oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileDlg.MultiSelectEnabled =True 
oFileDlg.FilterIndex = 1
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
Dim oDrgDoc As DrawingDocument
If Err.Number <> 0 Then
	MsgBox("File not chosen.",,"Dialog Cancellation")
ElseIf oFileDlg.FileName <> "" Then
	For Each oFileName As String In oFileDlg.FileName.Split("|")
		oDrgDoc = ThisApplication.Documents.Open(oFileName)
		doc = ThisApplication.ActiveDocument
		oDwgName = IO.Path.GetFileNameWithoutExtension(oFileName).ToUpper
		'MsgBox(oDwgName)
		
		Dim oFD As FileDescriptor
		oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
		oModelRef = (oFD.FullFileName.Split("\").Last()).Split(".").First().ToUpper
		'MsgBox(oModelRef)
		
		'Test
'			DwgName = "one"
'			oModelRef = "one"

		If DwgName = oModelRef  Then 
			oDrgDoc.Close(True)
			oDrgDoc.ReleaseReference
		End If

	Next
End If
0 Likes
Accepted solutions (1)
507 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

To compare you use the variable "DwgName", this is never declared. I suppose you just missed an "o"?

So it should be:

If oDwgName = oModelRef  Then 
			oDrgDoc.Close(True)
			oDrgDoc.ReleaseReference
		End If

Insted 🙂

 

Message 3 of 3

Anonymous
Not applicable

OMG! Thank you @JhoelForshav