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
Solved! Go to Solution.
Solved by Owner2229. Go to Solution.
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
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
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
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
You're welcomed
Can't find what you're looking for? Ask the community or share your knowledge.