iLogic - Occurrence in a specified Assembly

iLogic - Occurrence in a specified Assembly

Anonymous
Not applicable
2,198 Views
3 Replies
Message 1 of 4

iLogic - Occurrence in a specified Assembly

Anonymous
Not applicable

Hi All!

I'm trying to make an iLogic rule to fill the Part Number of every component of an assembly. I have already figured out almost everything but I got stuck with a part of it.

 

I would need to show the hierarchy of the components in the part numbers just like they are in the assembly:

 

e.g.

 

XXXX 00-00-000

     XXXX 10-00-000

          XXXX 11-00-000

               XXXX 11-10-000

                    XXXX 11-10-001

                    XXXX 11-10-002

                         XXXX 11-11-000

                              XXXX 11-11-101

                              .

                              XXXX 11-11-199

                    .

                    .

          XXXX 12-00-000

               XXXX 12-00-001

               XXXX 12-00-002

               XXXX 12-00-003

               XXXX 12-00-004

               .

               .

     XXXX 20-00-000

     XXXX 30-00-000

     XXXX 00-00-001

     XXXX 00-00-002

     .

     .

 

What I'm trying to do is the following:

 

- I store the name of the assemblies for each level (I would use 5 levels, so I have 5 variables)

 

- I would check if the "current" part or "current" assembly (I'm using a "For Each" command) is occurs on the current level/assembly (If yes => keep or +1 the level, then give a part number / If no => check the previous levels, and give a part number according to the level that contains the "current" component)

 

What I can't do and I would like to ask some help from you, is how can I check a specified Inventor Component if it contains an other component by its name?

 

I searched many forums and sites about it, but I could not figure it out. I'm trying something like this, but I can't make it work:

 

SyntaxEditor Code Snippet

Dim subass1 As AssemblyDocument
subass1 = Component.InventorComponent(Lvl1)
Dim Occur1 As Inventor.ComponentOccurrence
Dim PartExists1 As Boolean = False
For Each Occur1 In Occurrences
    If Occur1.Name = docFName Then
        PartExists1 = True
        Lvl2 = docName & ":1"
        ID2 = ID2 + 1
        ID3 = 0
        ID4 = 0
        ID5 = 0
        ID6 = 0
        Level = 2
        iProperties.Value(docFName, "Project", "Part Number") = azonosito & " " & ID1 & ID2 & "-" & ID3 & ID4 & "-" & ID5 & "0" & ID6
        Exit For
    End If
Next 


 

I attached my full code, it's not finished, since I can't solve this part of it, but maybe it helps to understand what I would like to do 🙂

 

Thank you very much in advance!!!

0 Likes
2,199 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor

http://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-729F272D-821C-4DFF-B604-8C89035D6D88

 

 

Use .AllLeafOccurrences on the assembly container and specify the optional leaf definition

 

or us the .AllReferencedOccurrences.


--------------------------------------
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 4

JaneFan
Autodesk
Autodesk

Hello @Anonymous, 

 

I read your code, but couldn't find how you get the variable named as Occurrences. 

Please try changing Occurrences in ForEach statement to: Component.InventorComponent.Parent.Occurrences, like this: 

For Each benne3 In Component.InventorComponent.Parent.Occurrences

 




Jane Fan
Inventor/Fusion QA Engineer
Message 4 of 4

Anonymous
Not applicable

@JaneFan

 

Thanks for your help, it seems that this part works now, I'm using this code:

 

SyntaxEditor Code Snippet

                    Case "1"
                        Dim alossz1 As Document
                        alossz1 = ThisApplication.Documents.ItemByName(OA1full)
                        Dim oAsmDef1 As AssemblyComponentDefinition 
                        oAsmDef1 = alossz1.ComponentDefinition
                        Dim oDoc1 As Document 
                        oDoc1 = ThisApplication.Documents.ItemByName(docFile.FullFileName)
                        Dim oOccs1 As ComponentOccurrencesEnumerator
                        oOccs1 = oAsmDef1.Occurrences.AllReferencedOccurrences(oDoc1)
                        Dim oOcc1 As ComponentOccurrence
                        Dim PartExists1 As Boolean = False
                        For Each oOcc1 In oOccs1
                            If oOcc1.Name = (docName & ":1") Then
                                
                                PartExists1 = True
                                OA2 = docName & ":1"
                                OA2full = docFile.FullFileName
                                ID2 = ID2 + 1
                                ID3 = 0
                                ID4 = 0
                                ID5 = 0
                                ID6 = 0
                                szint = 2
                                iProperties.Value(docFName, "Project", "Part Number") = azonosito & " " & ID1 & ID2 & "-" & ID3 & ID4 & "-" & ID5 & "0" & ID6
                                Exit For
                            End If
                        Next
                        If PartExists1 = False Then
                            OA2 = ""
                            OA1 = docName & ":1"
                            OA1full = docFile.FullFileName
                            ID1 = ID1 + 1
                            ID2 = 0
                            ID3 = 0
                            ID4 = 0
                            ID5 = 0
                            ID6 = 0
                            szint = 1
                            iProperties.Value(docFName, "Project", "Part Number") = azonosito & " " & ID1 & ID2 & "-" & ID3 & ID4 & "-" & ID5 & "0" & ID6
                            
                        End If

 

Unfortunately I can't work on this now, but I'll give feedback here when I'm finished.

 

Thanks a lot for your help!

0 Likes