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 - Count specific part in pattern

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
1213 Views, 6 Replies

iLogic - Count specific part in pattern

Hi,

 

I try to count a specific part in iam rectangular pattern

Here's my idea of code:

 

i = 0
oCaisson40 = ThisApplication.Documents.ItemByName(oPath40)
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Pattern-A")
oElement = oPattern.OccurrencePatternElements.Item(oCaisson40)
oComp = oPattern.Occurrences.Item(1)
For Each oComp In oPattern
i = i+1
Next
oNomDernierCaisson1 = i

Thanks for your help

 

6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

ok i try with an another code if anyone can help me

 

i = 0
oCaisson40 = ThisApplication.Documents.ItemByName(oPath40)
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Pattern-1")

Dim oOccs40 As ComponentOccurrencesEnumerator
oOccs40 = oAsmCompDef.Occurrences.AllReferencedOccurrences(oCaisson40)
Dim oOcc40 As ComponentOccurrence

For Each oOcc40 In oPattern.Occurrences
If oOcc40.Name = oOccs40 Then
i = i+1
Else
End If
Next



oNomDernierCaisson1 = i
Message 3 of 7
Owner2229
in reply to: Anonymous

Hi, try this one below. Fill in the Occurence name you're searching for and run it.

It will go throught the assembly and all sub-assemblies.

 

Sub Main()
    oName = "MySearchedPartName" 'Without extension
    Dim oDoc As Document = ThisApplication.ActiveDocument
    SubAsm(oDoc.ComponentDefinition.Occurrences)
    MsgBox(oCount)
End Sub

Private oName As String
Private oCount As Integer

Sub SubAsm(oOccs As ComponentOccurrences)
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oOccs
        Dim OcName As String = oOcc.Name
        OcName = Left(OcName, InStrRev(OcName, ":", -1) - 1)
        If OcName = oName Then oCount = oCount + 1
        Dim oDoc As Document = oOcc.Definition.Document
        If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            SubAsm(oDoc.ComponentDefinition.Occurrences)
        End If
    Next
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 4 of 7
Anonymous
in reply to: Owner2229

Thanks Mike,

 

your code count all specific part in all the assembly,

my problem is to count specific part in only one specific pattern named "Pattern-A"

 

have you an idea to do this ?

 

thanks

Message 5 of 7
Owner2229
in reply to: Anonymous

Here you go:

 

Sub Main()
    oName = "MySearchedPartName" 'Without extension
    Dim oDoc As Document = ThisApplication.ActiveDocument
    Dim OPS As OccurrencePatternElements = oDoc.ComponentDefinition.OccurrencePatterns.Item("Pattern-1").OccurrencePatternElements
    Dim OP As OccurrencePatternElement
    For Each OP In OPS
        SubAsm(OP.Occurrences)
    Next
    MsgBox(oCount)
End Sub

Private oName As String
Private oCount As Integer

Sub SubAsm(oOccs As ComponentOccurrencesEnumerator)
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oOccs
        Dim OcName As String = oOcc.Name
        OcName = Left(OcName, InStrRev(OcName, ":", -1) - 1)
        If OcName = oName Then oCount = oCount + 1
    Next
End Sub 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 7
Anonymous
in reply to: Owner2229

Thanks a lot Mike

Your code is what I need

 

Yan

Message 7 of 7
Owner2229
in reply to: Anonymous

You're welcomed Smiley Happy

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

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

Post to forums  

Autodesk Design & Make Report