@Anonymous wrote:
I tried to apply your rule and it works perfectly fine for all sub assemblies. Thank you very much for this. But can this also apply to ipt files under the sub assemblies? We actually have some properties that we added to our illogic form and want it to run in all ipt files also so it can take the basic brand name, etc. is it possible to run this rule so those properties also apply to the ipt files besides just the sub assemblies? thanks in advance
I have corrected the code, It should work in all subassemblies now as well. Cheers!
Sub Bounding_Box_Main()
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
Call Bounding_Box(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub
Sub Bounding_Box(Occurrences As ComponentOccurrences, _
Level As Integer)
' Iterate through all of the occurrence in this collection. This
' represents the occurrences at the top level of an assembly.
Dim oOcc As ComponentOccurrence
Dim oCustomPropSet As PropertySet
Dim modX As Double
Dim modY As Double
Dim modZ As Double
Dim Ilgis As Double
Dim Plotis As Double
Dim Storis As Double
Dim DIMALL As String
For Each oOcc In Occurrences
'If it is an Assembly go to next Level
Set oCustomPropSet = oOcc.Definition.Document.PropertySets.Item(4)
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call Bounding_Box(oOcc.SubOccurrences, Level + 1)
ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
Debug.Print Space(Level * 3) & oOcc.Name
'Get the UserDefinedPropertySet
Set oCustomPropSet = oOcc.Definition.Document.PropertySets.Item(4)
' For X
'If CheckPropertyExists(oCustomPropSet, "ModX") Then
'oCustomPropSet.Item("ModX").Expression = modXr
'Else
' Call oCustomPropSet.Add(modXr, "ModX")
'End If
' For Y
'If CheckPropertyExists(oCustomPropSet, "ModY") Then
'oCustomPropSet.Item("ModY").Expression = modYr
'Else
'Call oCustomPropSet.Add(modYr, "ModY")
'End If
' For Z
'If CheckPropertyExists(oCustomPropSet, "ModZ") Then
'oCustomPropSet.Item("ModZ").Expression = modZr
'Else
'Call oCustomPropSet.Add(modZr, "ModZ")
'End If
'Get the ranges Model X, Model Y, Model Z
modX = (oOcc.RangeBox.MaxPoint.X + (oOcc.RangeBox.MinPoint.X) * -1) * 10
modY = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
modZ = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
'Round to 0
modXr = Round(modX, 0)
modYr = Round(modY, 0)
modZr = Round(modZ, 0)
'Create L x W x H
If modXr >= modYr And modYr >= modZr Then
Ilgis = modXr
Plotis = modYr
Storis = modZr
ElseIf modXr >= modZr And modZr >= modYr Then
Ilgis = modXr
Plotis = modZr
Storis = modYr
ElseIf modYr >= modZr And modZr >= modXr Then
Ilgis = modYr
Plotis = modZr
Storis = modXr
ElseIf modYr > modXr And modXr > modZr Then
Ilgis = modYr
Plotis = modXr
Storis = modZr
ElseIf modZr > modXr And modXr > modYr Then
Ilgis = modZr
Plotis = modXr
Storis = modYr
ElseIf modZr > modYr And modYr > modXr Then
Ilgis = modZr
Plotis = modYr
Storis = modXr
End If
sq_m = Ilgis * Plotis * 0.000001
sq_m = Round(sq_m, 3)
DIMALL = Ilgis & "x" & Plotis & "x" & Storis
'Check -> Create/Overwrite Custom Parameter.
If CheckPropertyExists(oCustomPropSet, "DIMALL") Then
oCustomPropSet.Item("DIMALL").Expression = DIMALL
Else
Call oCustomPropSet.Add(DIMALL, "DIMALL")
End If
If CheckPropertyExists(oCustomPropSet, "Ilgis") Then
oCustomPropSet.Item("Ilgis").Expression = Ilgis
Else
Call oCustomPropSet.Add(Ilgis, "Ilgis")
End If
If CheckPropertyExists(oCustomPropSet, "Plotis") Then
oCustomPropSet.Item("Plotis").Expression = Plotis
Else
Call oCustomPropSet.Add(Plotis, "Plotis")
End If
If CheckPropertyExists(oCustomPropSet, "Storis") Then
oCustomPropSet.Item("Storis").Expression = Storis
Else
Call oCustomPropSet.Add(Storis, "Storis")
End If
If CheckPropertyExists(oCustomPropSet, "sq_m") Then
oCustomPropSet.Item("sq_m").Expression = sq_m
Else
Call oCustomPropSet.Add(sq_m, "sq_m")
End If
End If
Next
End Sub
Public Function CheckPropertyExists(oProps As PropertySet, oPropName As String) As Boolean
CheckPropertyExists = False
Dim oProp As Property
For Each oProp In oProps
If oProp.Name = oPropName Then
CheckPropertyExists = True
End If
Next
End Function