- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok so I'm writing some code to search through all the sub assemblies, checking to see if the piece parts have a specific custom iprop & then using that in order to apply a numbering system. This would be done at the end of the project and certain parts go in the 001-099, some in 100-199 & 200-299 and so on. Any ways, the current way im trying to do it is with the first loop which counts how many parts have this custom iprop (NOT WORKING), then the second loop apply the part numbers.
Sub iPropPiecePartNumbers Dim TextStrng As String Dim Result() As String Dim PSnumber As String 'String array to string TextStrng = iProperties.Value("Project", "Project") Result = Split(TextStrng, "-") PSnumber = Result(2) Dim SkidCount As String = "000" Dim ManifoldCount As String = "100" Dim DSRCount As String = "200" Dim PipespoolCount As String = "300" Dim FlushlineCount As String = "400" Dim i As Integer = 0 Dim j As Integer = 0 Dim h As Integer = 0 Dim g As Integer = 0 Dim f As Integer = 0 Dim count1 As Integer Dim count2 As Integer Dim count3 As Integer Dim count4 As Integer Dim count5 As Integer Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all Of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'Searching through the top level assembly file in order to locate only part files If oOccurrence.DefinitionDocumentType = kPartDocumentObject Then comp = Component.InventorComponent(oOccurrence.Name) Dim doc = comp.Definition.Document On Error Resume Next Dim propset = doc.PropertySets("Inventor User Defined Properties").Item("S0Class").Value Dim prop As String = CStr(propset) Dim newname As String Trace.WriteLine("iLogic: iPropPiecePartNumbers | oOccurrence.Name: " & oOccurrence.Name) If prop = "SKID" Then i = 1 + i Trace.WriteLine("iLogic: iPropPiecePartNumbers | i: " & i) ElseIf prop = "MANIFOLD" Then j = 1 + j Trace.WriteLine("iLogic: iPropPiecePartNumbers | j: " & j) ElseIf prop = "DSR" Then h = 1 + h Trace.WriteLine("iLogic: iPropPiecePartNumbers | h: " & h) ElseIf prop = "PIPE SPOOL" Then g = 1 + g Trace.WriteLine("iLogic: iPropPiecePartNumbers | g: " & g) ElseIf prop = "FLUSHLINE" Then f = 1 + f Trace.WriteLine("iLogic: iPropPiecePartNumbers | f: " & f) End If Else End If Next Trace.WriteLine("iLogic: iPropPiecePartNumbers | i total: " & i) Trace.WriteLine("iLogic: iPropPiecePartNumbers | j total: " & j) Trace.WriteLine("iLogic: iPropPiecePartNumbers | h total: " & h) Trace.WriteLine("iLogic: iPropPiecePartNumbers | g total: " & g) Trace.WriteLine("iLogic: iPropPiecePartNumbers | f total: " & f) For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'Searching through the top level assembly file in order to locate only part files If oOccurrence.DefinitionDocumentType = kPartDocumentObject Then comp = Component.InventorComponent(oOccurrence.Name) Dim doc = comp.Definition.Document On Error Resume Next Dim propset = doc.PropertySets("Inventor User Defined Properties").Item("S0Class").Value Dim prop As String = CStr(propset) Dim newname As String If prop = "SKID" Then For count1 = 1 To i SkidCount = _ (Convert.ToInt32(New String(SkidCount)) + 1).ToString("D3") newname = "PS-" + PSnumber + "-" + SkidCount iProperties.Value(oOccurrence.Name, "Project", "Part Number") = newname 'write to component iprops On Error Resume Next iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _ iProperties.Value(oOccurrence.Name, "Project", "Part Number") Next ElseIf prop = "MANIFOLD" Then For count2 = 1 To j ManifoldCount = _ (Convert.ToInt32(New String(ManifoldCount)) + 1).ToString("D3") newname = "PS-" + PSnumber + "-" + ManifolfCount iProperties.Value(oOccurrence.Name, "Project", "Part Number") = newname 'write to component iprops On Error Resume Next iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _ iProperties.Value(oOccurrence.Name, "Project", "Part Number") Next ElseIf prop = "DSR" Then For count3 = 1 To h DSRCount = _ (Convert.ToInt32(New String(DSRCount)) + 1).ToString("D3") newname = "PS-" + PSnumber + "-" + DSRCount iProperties.Value(oOccurrence.Name, "Project", "Part Number") = newname 'write to component iprops On Error Resume Next iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _ iProperties.Value(oOccurrence.Name, "Project", "Part Number") Next ElseIf prop = "FLUSHLINE" Then For count4 = 1 To g PipespoolCount = _ (Convert.ToInt32(New String(PipespoolCount)) + 1).ToString("D3") newname = "PS-" + PSnumber + "-" + PipespoolCount iProperties.Value(oOccurrence.Name, "Project", "Part Number") = newname 'write to component iprops On Error Resume Next iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _ iProperties.Value(oOccurrence.Name, "Project", "Part Number") Next ElseIf prop = "PIPE SPOOL" Then For count5 = 1 To f FlushlineCount = _ (Convert.ToInt32(New String(FlushlineCount)) + 1).ToString("D3") newname = "PS-" + PSnumber + "-" + FlushlineCount iProperties.Value(oOccurrence.Name, "Project", "Part Number") = newname 'write to component iprops On Error Resume Next iProperties.Value(oOccurrence.Name, "Project", "Part Number") = _ iProperties.Value(oOccurrence.Name, "Project", "Part Number") Next End If Else End If Next
End Sub
Final count for i = 4 should be 1
final count for j = 8 should be 2
and so on
i for example, i should only have access to the -300 part, the other two are in a purchase drive, can not write to them & i dont want to count them anyways.
Any help is appreciated
Solved! Go to Solution.