Cost Code for Top Levels

Cost Code for Top Levels

JamesMeBoi
Enthusiast Enthusiast
253 Views
1 Reply
Message 1 of 2

Cost Code for Top Levels

JamesMeBoi
Enthusiast
Enthusiast

Here is some code that I got from the forum, is there anyone who knows how to make it desifer between and .IPT and .IAM, I am running into an issue when I give parts a cost, and then run the code in an assembly it will update the assemblies cost it will update by adding the two together and I end up with double the cost of the assembly.

 

 

 

Sub Main
    '- - - - - - - - - - - sum the custom iProperty - - - - - - - - - -
    'clear the custom property in the assembly
    iProperties.Value("Project", "estimated cost") = 0
    'set a reference to the assembly component definintion.
    'This assumes an assembly document is open.
    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    'Iterate through all of the occurrences
    Dim oOccurrence As ComponentOccurrence
    For Each oOccurrence In oAsmCompDef.Occurrences
        
        Call ProcessAllChildren(oOccurrence)
    
    Next
    
    MessageBox.Show("Setting Estimated cost for top level assembly to: " & "$" & sumNumber, "Estimated cost")
    iProperties.Value("Project", "estimated cost") = Round (sumNumber,2)

End Sub

'Global 
Private sumNumber As Double = 0

Public Sub ProcessAllChildren(ByRef oOccurrence As ComponentOccurrence) 

      If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
        'property in the parts
        yNumber = iProperties.Value(oOccurrence.Name, "Project", "estimated cost")
		lnumber = iProperties.Value(oOccurrence.Name, "Custom", "Labor Cost")
        'MessageBox.Show("yNumber =  " & yNumber, oOccurrence.Name)
        sumNumber = sumNumber + yNumber + lnumber
        'MessageBox.Show("sumNumber =  " & sumNumber,"Running Total")
    Else
        'MessageBox.Show("This is a VirtualComponentDefinition",  oOccurrence.Name)
    End If

    Dim oCompOcc As ComponentOccurrence
    Dim oComponentSubOccurrences As ComponentOccurrences
'    
    For Each oCompOcc In oOccurrence.SubOccurrences
        
        If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
           oComponentSubOccurrences = oCompOcc.SubOccurrences
           
           If Not oComponentSubOccurrences Is Nothing Then
            If oComponentSubOccurrences.Count > 0 Then
                ProcessAllChildren(oCompOcc)
            End If
           End If
        Else
            ProcessAllChildren(oCompOcc)
        End If
        
     Next

End Sub

 

 

254 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor
 If oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
  MessageBox.Show("Is an assembly","Document check")
Elseif oOccurrence.DefinitionDocumentType =kPartDocumentObject Then

MessageBox.Show("Is a part","Document check")
End If

 

Above is the if statements for detecting document type, the sub routine is actually using the assembly filter already to loop through sub assemblies. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes