- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on rule and it was working just fine for parts and assemblies, but now that I added drawings to it, it no longer works for parts or assemblies. I then found Cutis Waguespack's example, which I get the same issue with. When I run the following code on a part or assembly. I get the error. "ThisDrawing: This document "testfile.ipt" is not a drawing." I know its not a drawing. Anyone know why this is behaving this way?
Dim oDoc As Document oDoc = ThisDoc.Document If oDoc.DocumentType = Inventor.DocumentTypeEnum.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 oDoc.DocumentType = Inventor.DocumentTypeEnum.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 oDoc.DocumentType = Inventor.DocumentTypeEnum.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 = ThisDrawing.ModelDocument.FullFileName
'Catch
'End Try
ThisApplication.Documents.Open(modelFullFileName, True)
Else If drwquestion = vbNo Then
End If
Return
End If
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 IfIf you find this was helpful please accept this as solution / press the kudos button ![]()
Cheers,
SK.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for the reply. Your change gets rid of the error for parts and assemblies, but breaks the portion for drawings. If this is run in a drawing the first model referenced is opened. The issue is, if the documentType is a part or assembly, why is illogic even looking at the If Else for drawing documentTypes? It shouldn't even be in that part of the if statement. Any other things to try? This is something simple, I just can't find a way around the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
To understand what you were doing wrong you need to understand that the custom snippets of iLogic code like ThisDoc and ThisDrawing are just taking the active document object (that the rule is being run from), and returning something back.
In the case of ThisDoc, it’s returning an object of type Document.
In the case of ThisDrawing, it’s returning an object of type DrawingDocument.
Before your code ever runs, the compiler will try to resolve those Functions. The problem is when you’re ActiveDocument is of a type that doesn’t match with the returning type, it’s like trying to fit a square peg into a round hole.
To, in the most terrible way possible, highlight what I’m talking about, look at the code below. If you were to run that on a drawing, you’d get three separate message box dialogs that would pop up with information about the document type. Everything would be fine! However, If you attempted to run that code from an Assembly level, the initial two message boxes would come up fine, but once it tried to put the Active AssemblyDocument into a DrawingDocument type, it will error out (on the third dialog).
Module hiddenModule
' ***********************************
' YOU CAN IGNORE THIS TOP BIT
' ***********************************
Public Dim ThisApplication As Object
' Don't pay attention to any of this.
' When you try to access the 'ThisApplication' from
' a level above the Main() Sub, there are permission
' issues. All I'm doing here is creating a really
' makeshift bridge...
Sub New ()
Try
ThisApplication = GetObject(, "Inventor.Application")
'MessageBox.Show("ThisApplication Set")
Catch ex As Exception
MessageBox.Show("Inventor must be running.", "Inventor.exe Error")
End Try
End Sub
' ***********************************
' PAY ATTENTION TO THE BELOW
' ***********************************
Public Function MyThisDoc () As Inventor.Document
MyThisDoc = ThisApplication.ActiveDocument
End Function
Public Function MyThisDrawing () As Inventor.DrawingDocument
MyThisDrawing = ThisApplication.ActiveDocument
End Function
End Module
Sub Main ()
Dim oDoc As Document
oDoc = MyThisDoc
MessageBox.Show(oDoc.DocumentType.ToString(), "oDoc")
MessageBox.Show(MyThisDoc.DocumentType.ToString(), "MyThisDoc")
MessageBox.Show(MyThisDrawing.DocumentType.ToString(), "MyThisDrawing")
End Sub
Soooo. Knowing all of that, it was simple to get your code working across every Document environment.
See Below:
Dim oDoc As Document
oDoc = ThisDoc.Document
' While you don't have to declare your
' string variable, technically, I still
' did out of clarity
Dim modelFullFileName As String
Select Case oDoc.DocumentType
Case = kPartDocumentObject
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
Case = kAssemblyDocumentObject
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
Case = kDrawingDocumentObject
drwquestion = _
MessageBox.Show("This is a drawing file, Do you want to open the file?", _
"Ilogic", _
MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If drwquestion = vbYes Then
modelFullFileName = ThisDoc.ModelDocument.FullFileName
ThisApplication.Documents.Open(modelFullFileName, True)
Else
MessageBox.Show("Nothing Opened", "iLogic")
End If
End Select
The biggest thing to change (besides turning your ElseIfs into a (in my own opinion) cleaner looking Select Case statement), was that the ThisDrawing was substituted for a ThisDoc. Because we’re already checking the type (in the Select Case), we don’t need to use the Drawing Specific iLogic Function of ThisDrawing to return a DrawingDocument to us.
Instead we can just use the generic Document Type.
Now. If you wanted to use DrawingDocument specific properties that aren’t available to the base Document Class, you would absolutely need to define a new DrawingDocument object, however, in your case, you’re just getting a file name which happens to be a property of the base class type.
Sorry for the long explanation. But things like this can be a mystery later down the road, and it might help you (or others) at some point in the future.
If my solution worked or helped you out, please don't forget to hit the kudos button
iLogicCode Injector: goo.gl/uTT1IB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report