Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
in reply to: Ktomberlin

There was a problem with the mentioned line in your code. You have mentioned it as ThisDrawing that leads to the error because the opened document was not a drawing document.

 

 modelFullFileName = ThisDrawing.ModelDocument.FullFileName
       

 

 

I hope the modified code will be helpful.

 

Dim oDoc As Document
oDoc = ThisDoc.Document
Dim oDocType As Inventor.DocumentTypeEnum
oDocType = oDoc.DocumentType
Dim drwquestion As String
Dim modelFullFileName As String
If oDocType = kPartDocumentObject  Then
            If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
            MessageBox.Show("You have a sketch active in a part file.", "iLogic")
            Else
            MessageBox.Show("This is a part file.", "iLogic")
            End If
Else If oDocType = kAssemblyDocumentObject Then
            If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
            MessageBox.Show("You have a sketch active in an assembly file.", "iLogic")
            Else
            MessageBox.Show("This is an assembly file.", "iLogic")
            End If
Else If oDocType = kDrawingDocumentObject Then
            drwquestion = MessageBox.Show("This is a drawing file, Do you want to open the file?","Ilogic", MessageBoxButtons.YesNo,MessageBoxIcon.Question)
   'set condition based on answer 
      If drwquestion = vbYes Then
'       'Try
       modelFullFileName = oDoc.FullFileName
'       'Catch
'       'End Try


      ThisApplication.Documents.Open(modelFullFileName, True)
		
      ElseIf drwquestion = vbNo Then

   End If
'    Return
End If

If you find this was helpful please accept this as solution / press the kudos button Smiley Wink

 

Cheers,

SK.