How to search for a component in an assembly with a keyword using ilogic

How to search for a component in an assembly with a keyword using ilogic

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

How to search for a component in an assembly with a keyword using ilogic

Anonymous
Not applicable

I have an assembly which has a lot of subassemblies.

There are components with first part of the name as thier part family name.

I will be asking to replace components or suppressing based on some value.

My problem is to replce or suppress the specific component.

 

I was using

ThisDoc.Document.ComponentDefinition.Occurrences.Item(#).Name

 

to find the component and do the process. Now it has come to my notice that the occurence number changes during the time and the operation replaces or suppresses other components with ethe occurence number. Not sure why the occurence number changes.

 

Could someone help me witha code snippet to search the component using a keyword that will be first word of the component name.

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

tolgay.hickiran
Advisor
Advisor
Why don't you search from the BOM instead,

Get the top level assembly and get into the BOM.

Dim a as AssemblyDocument
a = ThisApplication.ActiveDocument


then you can reach the bom from:

a.componentdefinition.bom.bomviews.item(i).bomrows.item(j).componentdefinitions.item(1).document.displayname

where i would be your for loop starting from 1 to bomviews.count and
j would be your for loop starting from 1 to bomrows.count

It looks pretty complicated but this is your safest choice as it looks for your current bom.

Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes
Message 3 of 4

Anonymous
Not applicable

do i need to have a for loop?

 

I tried, but not sure I am doing it right.

The ones in blue does not seem right

The code returns error Public member 'bomrows' on type 'BOM' not found.

 

could you please correct it as I am not sure of it.

 

 

Dim a As AssemblyDocument
a = ThisApplication.ActiveDocument
rownumber = a.componentdefinition.bom.bomrows.count
items = a.componentdefinition.bom.bomviews.count

For i As Integer = 1 To items

    For  j As Integer = 1 To rownumber
        
        partname = a.componentdefinition.bom.bomviews.item(i).bomrows.item(j).componentdefinitions.item(1).Document.displayname
        
        If partname.Contains("part_family")  And  partname.Contains(":2") Then
            
            Active_item = partname

            exit for
        
        End If
        
    Next

    exit for
    
Next

0 Likes
Message 4 of 4

Anonymous
Not applicable

hey, I found code someone posted for someother problem, but got solution for my case.

I am no expert in coding and have not much exposure. Here it is.

 

 

 

 

Dim oAsmCompDef As AssemblyComponentDefinition
        oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
        
        'Iterate through all of the occurrences
        Dim oOccurrence As ComponentOccurrence
        
        For Each oOccurrence In oAsmCompDef.Occurrences
            Dim oName As String
            If oOccurrence.Name.contains("family name") And oOccurrence.Name.contains("instance number") Then
                oName = oOccurrence.Name
                If condition Then
                    oOccurrence.suppress
                    
                Else
                    oOccurrence.unsuppress
                End If
                            
                Exit For
            End If
            
        Next

0 Likes