0% found this document useful (0 votes)
60 views2 pages

Combine 3 Semi

The document contains VBA code that loops through occurrences in a component definition to calculate the width, length, and thickness of each occurrence. It rounds these values and sets custom properties on each occurrence. It then checks the document type and imports a BOM customization file if it is an assembly, enabling structured and parts-only views.

Uploaded by

Triple Vi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

Combine 3 Semi

The document contains VBA code that loops through occurrences in a component definition to calculate the width, length, and thickness of each occurrence. It rounds these values and sets custom properties on each occurrence. It then checks the document type and imports a BOM customization file if it is an assembly, enabling structured and parts-only views.

Uploaded by

Triple Vi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

oAdoc = ThisApplication.

ActiveDocument
oAcompdef = oAdoc.ComponentDefinition

'conversion factor cm to in
oCF = 0.393701*25.4

Dim oOcc As ComponentOccurrence


For Each oOcc In oAcompdef.Occurrences.AllLeafOccurrences

oX = (oOcc.definition.RangeBox.MaxPoint.X _
- oOcc.definition.RangeBox.MinPoint.X)*oCF
oY = (oOcc.definition.RangeBox.MaxPoint.Y _
- oOcc.definition.RangeBox.MinPoint.Y)*oCF
oZ = (oOcc.definition.RangeBox.MaxPoint.Z _
- oOcc.definition.RangeBox.MinPoint.Z)*oCF

'[ get middle number


If oX > oY And oX < oZ Or oX > oZ And oX < oY Then
oMiddle = oX
GoTo Set_Width
End If

If oY > oX And oY < oZ Or oY > oZ And oY < oX Then


oMiddle = oY
GoTo Set_Width
End If

If oZ > oX And oZ < oY Or oZ > oY And oZ < oX Then


oMiddle = oZ
GoTo Set_Width
End If
']

Set_Width:
iProperties.Value(oOcc.Name, "Custom", "Width") _
= Round(oMiddle,3)

'set length
iProperties.Value(oOcc.Name, "Custom", "Length") _
= Round(MaxOfMany(oX, oY, oZ),3)

'set Thickness
iProperties.Value(oOcc.Name, "Custom", "Thickness") _
= Round(MinOfMany(oX, oY, oZ),3)

Next oOcc

Dim oDoc As AssemblyDocument

If oADoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
oDoc = oADoc
Else If oADoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject
Try
oDoc =
oADoc.ActiveSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocum
ent
Catch
MsgBox("LOD in use in drawing; Macro failed!")
End Try
Else
MsgBox("Invalid Document!")
End If

Dim oBOM As BOM


oBOM = oDoc.ComponentDefinition.BOM

oBOM.ImportBOMCustomization("D:\bom.xml")

oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False

oBOM.PartsOnlyViewEnabled = True

You might also like