Message 1 of 2
Cost Code for Top Levels
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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