Run Rule in Another Document

Run Rule in Another Document

Anonymous
Not applicable
3,736 Views
5 Replies
Message 1 of 6

Run Rule in Another Document

Anonymous
Not applicable

Does anyone know if there's a code for running a rule in another document once it is added?

 

Currently, I have a rule in my part doc that adds a new drawing document from a custom template. I want to make it so that once the drawing document is opened, it automatically runs another rule, i.e. a rule that adds views and dimensions.

 

However I want to do this without using triggers in the drawing document. I want it so the rule is run only when the drawing document is created from the specific part doc, not just any part doc.

0 Likes
Accepted solutions (1)
3,737 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor
Accepted solution

iLogicAuto.RunExternalRule(oDoc, "RuleName")

iLogicAuto.RunRule(oDoc, "RuleName")


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 6

Anonymous
Not applicable

Appreciate it.

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

Hmm... doesn't seem to be working. I may have implemented it wrong.

 

Here is my code

 

SyntaxEditor Code Snippet

ThisApplication.RunRule(ThisApplication.Documents.Item(ThisApplication.Documents.Count), "CREATE DRAWING")

I have this code within a rule inside inventor and am using it to run another rule in a drawing document that was just added by the same rule that this code resides in.

0 Likes
Message 5 of 6

Anonymous
Not applicable
Hi Thukon,
Can you post the rule you have in your part document ?
And do you already have the code to create the specific views?
0 Likes
Message 6 of 6

Anonymous
Not applicable

Here is the code. The line for running the rule in the drawing document is the second to last line in the code. I even added a message box that says "loaded" before the runrule line so that I could give time for the drawing document to open up.

 

And yes I already have the rule in my drawing document for creating the specific views.

 

SyntaxEditor Code Snippet

'define the active document
oDoc = ThisApplication.ActiveDocument
'create a file dialog box
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If

'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
'set the file name string to use in the input box
oFileDlg.FileName = iProperties.Value("Project", "Part Number")

'work with an error created by the user backing out of the save
oFileDlg.CancelError = True
On Error Resume Next
'specify the file dialog as a save dialog (rather than a open dialog)
oFileDlg.ShowSave()

'catch an empty string in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved. You must save the file before creating a drawing", "Error")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
'save the file
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
MessageBox.Show(ThisDoc.Path & "\" & oDoc.DisplayName," ")
ThisApplication.documents.add(kDrawingDocumentObject, "C:\Users\Public\Documents\Autodesk\Inventor 2014\Templates\STSH Standard 2015.idw", True)
MessageBox.Show("Loaded")
iLogicVb.RunRule(ThisApplication.Documents.Item(ThisApplication.Documents.Count), "CREATE DRAWING")
End If

 

0 Likes