Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.

Inventor Forum

Reply
Post 21 of 40

Re: iLogic set BOM via Visibility

10-24-2012 12:26 PM in reply to: d_m_fleming

Oops, my falut. I'm not good at multi-tasking! Smiley Embarassed Find it attached to this post.

By data set I mean your assembly and it's accompanying parts.

Mike (not Matt) Rattray

Post 22 of 40

Re: iLogic set BOM via Visibility

10-24-2012 12:37 PM in reply to: mrattray

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.

Post 23 of 40

Re: iLogic set BOM via Visibility

10-25-2012 05:06 AM in reply to: d_m_fleming

Tanks as in military tanks? If that's the case, I imagine mentioning as much as you have could get you in trouble! Smiley Tongue

 

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.

Mike (not Matt) Rattray

Post 24 of 40

Re: iLogic set BOM via Visibility

12-11-2012 02:51 PM in reply to: mrattray

hi,

 anyone tried the code ?still have the same error messages in line 16 and 19

Post 25 of 40

Re: iLogic set BOM via Visibility

12-11-2012 02:52 PM in reply to: mrattray

hi code doesnt work,please help

Highlighted

Re: iLogic set BOM via Visibility

12-11-2012 03:12 PM in reply to: mohan.nakka

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



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


An Inventor Improvement Idea that needs support:


Post 27 of 40

Re: iLogic set BOM via Visibility

12-11-2012 03:27 PM in reply to: Curtis_Waguespack

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

Post 28 of 40

Re: iLogic set BOM via Visibility

12-11-2012 03:42 PM in reply to: mohan.nakka

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?

Post 29 of 40

Re: iLogic set BOM via Visibility

12-12-2012 07:15 AM in reply to: mrattray

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.

Post 30 of 40

Re: iLogic set BOM via Visibility

04-23-2013 08:17 PM in reply to: Infoseeker

Why does this only work in Master LoD???

Post 31 of 40

Re: iLogic set BOM via Visibility

04-24-2013 04:55 AM in reply to: LewisLusby
It should work in any LOD. What problems are you having?
Mike (not Matt) Rattray

Post 32 of 40

Re: iLogic set BOM via Visibility

07-30-2013 02:19 AM in reply to: mohan.nakka

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

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.

Re: iLogic set BOM via Visibility

08-12-2013 03:31 AM in reply to: Yijiang.Cai

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)

 

http://forums.autodesk.com/t5/Autodesk-Inventor/View-representation-parts-list-error/m-p/3606706/hig...

 

Im guesing this is not possible still without using the dreaded iassemblies or splitting the original assembly into lots of sub assemblies

Stephen Gibson



View stephen gibson's profile on LinkedIn


Post 34 of 40

Re: iLogic set BOM via Visibility

09-11-2014 06:47 AM in reply to: stephengibson76

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,

Post 35 of 40

Re: iLogic set BOM via Visibility

08-17-2015 03:14 PM in reply to: Yijiang.Cai

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".

Post 36 of 40

Re: iLogic set BOM via Visibility

08-24-2015 05:06 PM in reply to: karthur1

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 (not Matt) Rattray

Post 37 of 40

Re: iLogic set BOM via Visibility

08-25-2015 10:07 AM in reply to: mrattray

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

 

Post 38 of 40

Re: iLogic set BOM via Visibility

08-25-2015 11:37 AM in reply to: karthur1
@karthur1 ... Just replace all of the instances 'oOccurrence' with 'oOcc' ....

This error is because oOccurrence is not declared as the error says; ie oOcc = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Item(1) does not exist anywhere within the sub

As it is within a Sub that has arguements, you can see oOcc gets passed to it which means that it will have a value that points to an occurrence object from wherever the sub gets called.
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
--------------------------------------
Justin K.
Inventor 2017
Excel 2013+ VBA
Machine Design
Post 39 of 40

Re: iLogic set BOM via Visibility

09-06-2015 07:54 AM in reply to: karthur1

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
Mike (not Matt) Rattray

Post 40 of 40

Re: iLogic set BOM via Visibility

11-04-2015 11:26 PM in reply to: mrattray

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post