Hi MegaJerk (love the handle, btw)
Thank you for your help!
I realize now that I may have backed myself into a corner here, but I am way too far down this road to re-structure the whole thing now to use external rules. If I knew all that I know now when I began this project, I may have found a way to have it all run at the top assembly level, but I was a total novice.
My assembly contains a part file called Config.ipt, which is basically the parameter calculator for all the parameters used by all of the other parts in the assembly. I did things this way because Inventor does not let you link component parameters to assembly parameters in an assembly where that component is used: the old cyclic dependency. So that is why I have all the parts in the assembly linked to the parameters in the Config part.
This config part has just one rule, which calls a form, which has all the input fields for all these parameters. On that form is a button which I want to fire a BOM collector rule which is (and has to be) in the parent assembly file.
I have a workaround, which was to just have the BOM Collector rule in the assembly use a separate form, but it would be much better if I could fire that rule from the button on the main form.
Here is the top assembly and all the rules which control constraints and component selection... The rule 'Startup' is what fires from the iTrigger and runs the rule with the main form in the Config part.
[cid:image004.jpg@01CE8F78.27D23C60]
Here is the Config part, with the main parameter calculator rule. The rule Run.Collect.BOM is where I was trying to run an external txt rule, but it gives the error about having to be in an assembly... so frustrating!
[cid:image005.png@01CE8F76.7DABB140]
Here is the main form, with the button at the bottom I want to run the rule in the assembly
[cid:image008.jpg@01CE8F78.27D23C60]
I understand most of what you are saying about the document relationships, but I still cant believe with all its other functionality that there is no way to do this! Why does a subcomponent need to know anything about its containing document in order to have it run a rule in an assembly file, which will always be open and at a specified, hard-coded path when the rule is run?
I know this is a lot to understand without actually having the files, but any other suggestions??
I am sure you have better things to do, but I would be happy to send files if you wanted to look
Thanks a bunch!
James
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Author:
MegaJerk (Mentor)
Date:
08-02-2013 11:34 AM
I believe that there isn't a snippet for this due to the design philosophies that surround the document relationships produced by Inventor. Basically, not only is it wise for the user to keep his models designed from the top down, but it is also the inherent way that Inventor associates things internally. An Assembly has occurrences, and those occurrences are the representations of Documents as viewed from within your initial Assembly. A Document that is an occurrence inside of another Document has no direct knowledge of what it's inside of!
Now, you can of course 'create' that knowledge, but there are some gotchas involved due to the nature of the beast.
A few things to remember.
1) If you are editing a component that is inside of an open assembly, and you are editing the component by way of double clicking on it from said Assembly, your active document is the Assembly Document, and no whatever you're editing.
2) You can not Save an Active Document if you are currently editing a document that is an occurrence of the Active Document.
3) Rules that have been created on a document that has not been saved, will not be visible to any other document.
This may seem a bit over the top, but because of the multiple ways that you can open files in Inventor, it is necessary to do a little work before we get into the running of the rules.
The following code will allow you to run a rule in a document not associated with the open document, but you will have to, of course, do a little work to correct the paths to the file as well as the name of the rule.
Dim myDoc As Document
myDoc = ThisApplication.ActiveDocument
Dim myEdit As Document
myEdit = ThisApplication.ActiveEditDocument
Dim addIns As ApplicationAddIns
addIns = ThisApplication.ApplicationAddIns
Dim addIn As ApplicationAddIn
addIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
Dim iLogic As Object
iLogic = addIn.Automation
Dim oDoc As Document
If myDoc Is myEdit Then
oDoc = ThisApplication.Documents.Open("C:\MegaFolder\Jerk.iam", False)
Else
oDoc = myDoc
If oDoc.Dirty = True Then
MessageBox.Show("Please save the parent document before running!")
oDoc = Nothing
Return
End If
End If
Try Call iLogic.RunRule(oDoc, "RULE_TEST_NAME")
Catch
MessageBox.Show("Unable to run the rule", "RunRule Error")
Finally oDoc = Nothing
End Try
Pretty round-about huh?
External rules seem to have been created to alleviate this problem, but because they do not always apply (or are not always appropriate), typically a change in design is the way to go at that point, again, due to the relationships of Documents.
Because I do not know what it is you're making, the following may not apply to you, however, I would suggest looking at your design to see if it's possible to change how you're gathering / passing data that is meaningful to said design.
[Description: cid:image8e4647.jpg@9776527f.9c6f431a]
James Nordgren
Mechanical Engineer
Research & Development
Email: jnordgren@deltastar.com
Delta Star Inc.
3550 Mayflower Drive
Lynchburg
Virginia 24501
Tel: 434 845-0921
Web:
www.deltastar.com