ThisDoc.Document: Which document really?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm writing a rule which concerns a ipt file but I want to run it from iam level while I'm editing a ipt file. From the ipt level it should work as well but this is not a problem.
I have external rule and I get different answer form this code depending how I run it (* hope you understand my english 😉 )
Dim oDrawingDoc As DrawingDocument Dim oPartDoc As Document Dim oBLACHA As Document Dim oSheet As sheet Dim oTitleBlock As TitleBlock Dim oTextBoxes As TextBoxes doc = ThisDoc.Document 'active? 'checking the file type Select Case doc.DocumentType Case 12290 part_type="IPT" Case 12291 part_type="IAM" Case 12292 part_type="IDW" End Select If part_type="IAM" Then MessageBox.Show("IAM", "File type") Exit Sub If part_type="IPT" Then If doc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then MessageBox.Show("IPT Sheetmetal part", "File type") 'Goto SHEET_export Else MessageBox.Show("It's IPT but not a sheetmetal part", "File type") Exit Sub End If End If If part_type="IDW" Then ' Goto IDW_export End If
If I manually run this rule it works just fine but I want to use button, I bet u know this code:
Public Sub RuniLogic(ByVal RuleName As String) Dim iLogicAuto As Object Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument If oDoc Is Nothing Then MsgBox "Missing Inventor Document" Exit Sub End If Set iLogicAuto = GetiLogicAddin(ThisApplication) If (iLogicAuto Is Nothing) Then Exit Sub iLogicAuto.RunRule oDoc, RuleName End Sub Function GetiLogicAddin(oApplication As Inventor.Application) As Object Set addIns = oApplication.ApplicationAddIns 'Find the add-in you are looking for Dim addIn As ApplicationAddIn On Error GoTo NotFound Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") If (addIn Is Nothing) Then Exit Function addIn.Activate Set GetiLogicAddin = addIn.Automation Exit Function NotFound: End Function Public Sub RuniExtLogic(ByVal RuleName As String) Dim iLogicAuto As Object Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument If oDoc Is Nothing Then MsgBox "Missing Inventor Document" Exit Sub End If Set iLogicAuto = GetiLogicAddin(ThisApplication) If (iLogicAuto Is Nothing) Then Exit Sub On Error GoTo errorline iLogicAuto.RunExternalRule oDoc, RuleName Exit Sub errorline: MsgBox "Missing External rule: " & RuleName End Sub
For me it looks like the VBA code is setting the iam file as ThisApplication.ActiveDocument instead of my edited ipt file.
What is the syntax to change this code to ThisDoc.Document?
I'm a copy/paste type of programmer please forgive me if I make a basic mistakes.
What I intend to do is export a sheetmetal part with the drawing. No matter from which level (ipt iam idw) it will be run it should do exactly the same: export sheetmetal as a DXF, find a idw file (the same folder and file name, standard) export it as DWG. From the IAM lvl when I activate (edit) ipt file it should do the same. If it will be run from IDW just refer to the file on the drawing, easy thing.
I have 3 rules and I want to connect them somehow..