Is it possible to have iLogic rule create parts lists out of View Representations?
Solved! Go to Solution.
Solved by mrattray. Go to Solution.
Solved by Yijiang.Cai. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Oops, my falut. I'm not good at multi-tasking! Find it attached to this post.
By data set I mean your assembly and it's accompanying parts.
I'm working for a tank manufacturing company.
The data set is not something I can just post and I suspect is too large anyway.
This is a large assembly with many parts.
I created LOD's which I now know will not produce the BOM's I require.
I created view reps from the LOD's and am trying to get ilogic to give me a BOM that reflects only the parts in the View rep.
The code you sent is giving the same error but in lines 13 and 16 now.
Tanks as in military tanks? If that's the case, I imagine mentioning as much as you have could get you in trouble!
I have two theories as to why your having problems. Try this version, and if it doesn't work then we'll test theory two.
Hi mohan.nakka,
There seems to be some mystery characters as shown.
If you retype the word BOMStructure in both places shown it should take care of it.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Thanks Curtis,
That cleares the error message.I added this rule to an assembly file which has a view rep i created.i added this rule to fire with an event trigger "after save document".but none of the invisible components BOM structure is change to reference.Am i doing it right?Please help.
Thanks a lot
Regards,
Mohan
hi curtis,
i created a sample assembly with few parts and tried the code,it works great.where should i use this code if i have sub assemblies in a top level assembly?
I treid this rule and unfortunately does not work for me, I suspect the reason is complicated BOM set up I use.
Other guys did not complain.
Hi Mohan,
I have updated the iLogic rule to cover the assembly, which has the multiple levels of sub-assembly. Please see the code lines below –
Sub Main()
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
If oOccurrence.DefinitionDocumentType = kPartDocumentObject Then
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
If Component.Visible(oOccurrence.Name) = True Then
Component.InventorComponent(oOccurrence.Name).BOMStructure = _
BOMStructureEnum.kDefaultBOMStructure
ElseIf Component.Visible(oOccurrence.Name) = False Then
Component.InventorComponent(oOccurrence.Name).BOMStructure = _
BOMStructureEnum.kReferenceBOMStructure
End If
End If
ElseIf oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
Call ListComp(oOccurrence)
End If
Next
End Sub
Function ListComp(oOcc As ComponentOccurrence)
Dim oOcc1 As ComponentOccurrence
For Each oOcc1 In oOcc.SubOccurrences
If oOcc1.DefinitionDocumentType = kPartDocumentObject Then
If Not TypeOf oOcc1.Definition Is VirtualComponentDefinition Then
If Component.Visible(oOcc1.Name) = True Then
Component.InventorComponent(oOcc1.Name).BOMStructure = _
BOMStructureEnum.kDefaultBOMStructure
ElseIf Component.Visible(oOcc1.Name) = False Then
Component.InventorComponent(oOcc1.Name).BOMStructure = _
BOMStructureEnum.kReferenceBOMStructure
End If
End If
ElseIf oOcc1.DefinitionDocumentType = kAssemblyDocumentObject Then
Call ListComp(oOcc1)
End If
Next
End Function
Many thanks to all contributers as always... the code works well to do what it does but if you are dropping these views and parts lists onto idw's, each time you run the rule on a different view rep in the assemble it changes the occurances of the previous view rep so your data on the idw is wrong again...
i may be missing something but i am after, (the same as the original post)
Im guesing this is not possible still without using the dreaded iassemblies or splitting the original assembly into lots of sub assemblies
Have there been any improvements with this code? It works great for a single instance and drawing but reverts back to the original BOM once you work on another sheet. I am frustrated and have spent many hours looking into this issue. I am new to iLogic and do not know how to write code for it yet as I will have to learn that on my own time.
Please any advise for solving the issue with part list qty. and multiple sheets for a single assembly will be greatly appreciated!
Thank you,
In my test assembly, I have a mixture of sub-assemblies (iam) and parts (ipt). When I run this code, with the visibility of some of the subs and parts turned off, it will only set the occurance of the parts (ipts) to reference. I can't get it to change the occurance of the sub assemblies to "Reference".
Kirk, here's River's code modified to include the sub assemblies themselves in the setting of bom structures:
Sub Main() Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences Call toggle(oOccurrence) If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then Call ListComp(oOccurrence) End If Next End Sub Sub ListComp(oOcc As ComponentOccurrence) Dim oOcc1 As ComponentOccurrence For Each oOcc1 In oOcc.SubOccurrences Call toggle(oOcc1 ) If oOcc1.DefinitionDocumentType = kAssemblyDocumentObject Then Call ListComp(oOcc1) End If Next End Sub Sub toggle(oOcc As ComponentOccurrence) If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then If Component.Visible(oOccurrence.Name) = True Then Component.InventorComponent(oOccurrence.Name).BOMStructure = _ BOMStructureEnum.kDefaultBOMStructure ElseIf Component.Visible(oOccurrence.Name) = False Then Component.InventorComponent(oOccurrence.Name).BOMStructure = _ BOMStructureEnum.kReferenceBOMStructure End If End If End Sub
Disclaimer: I made this post without Inventor available to test, so the odds of me having made an error in that rule is pretty high.
Mike,
It appears that there needs to be something else added to it 'cause I get this error when I run it. Line 28 is the one I have highlighted below.
Thanks,
Kirk
MechMachine is right, there's some sloppy copy/paste there. My apologies.
Here's the revised code:
Sub Main() Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences Call toggle(oOccurrence) If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then Call ListComp(oOccurrence) End If Next End Sub Sub ListComp(oOcc As ComponentOccurrence) Dim oOcc1 As ComponentOccurrence For Each oOcc1 In oOcc.SubOccurrences Call toggle(oOcc1 ) If oOcc1.DefinitionDocumentType = kAssemblyDocumentObject Then Call ListComp(oOcc1) End If Next End Sub Sub toggle(oOcc As ComponentOccurrence) If Not TypeOf oOcc.Definition Is VirtualComponentDefinition Then If Component.Visible(oOcc.Name) = True Then Component.InventorComponent(oOcc.Name).BOMStructure = _ BOMStructureEnum.kDefaultBOMStructure ElseIf Component.Visible(oOcc.Name) = False Then Component.InventorComponent(oOcc.Name).BOMStructure = _ BOMStructureEnum.kReferenceBOMStructure End If End If End Sub
New to ilogic, if someone could give a quick noob-guide?
I go to ilogic>add rule, in the assembly,give it a name, paste Mike's text, then OK. it asks if I want to check out a "random part" (should I ?)
anyway, it gives me this error: System.ArgumentException: Feil parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ComponentOccurrence.set_BOMStructure(BOMStructureEnum )
at LmiRuleScript.ListComp(ComponentOccurrence oOcc)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
on 2016 pro, win 7
Can't find what you're looking for? Ask the community or share your knowledge.