Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ILogic help needed!

41 REPLIES 41
SOLVED
Reply
Message 1 of 42
Infoseeker
5083 Views, 41 Replies

ILogic help needed!

Is it possible to have iLogic rule create parts lists out of View Representations?

 

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

41 REPLIES 41
Message 21 of 42
mrattray
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

Message 22 of 42
d_m_fleming
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.

Message 23 of 42
mrattray
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

Message 24 of 42
mohan.nakka
in reply to: mrattray

hi,

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

Message 25 of 42
mohan.nakka
in reply to: mrattray

hi code doesnt work,please help

Message 26 of 42

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.

 

Autodesk Inventor iLogic Code error.png

 

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 27 of 42

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

Message 28 of 42
mohan.nakka
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?

Message 29 of 42
Infoseeker
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.

Message 30 of 42
LewisLusby
in reply to: Infoseeker

Why does this only work in Master LoD???

Message 31 of 42
mrattray
in reply to: LewisLusby

It should work in any LOD. What problems are you having?
Mike (not Matt) Rattray

Message 32 of 42
Yijiang.Cai
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.
Email: River-Yijiang.Cai@autodesk.com
Message 33 of 42

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


Message 34 of 42

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,

Message 35 of 42
karthur1
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".

Message 36 of 42
mrattray
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

Message 37 of 42
karthur1
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

 

2015-08-25_1205.png

Message 38 of 42
MechMachineMan
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 '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 39 of 42
mrattray
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

Message 40 of 42
terje.antonsen
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report