AnsweredAssumed Answered

Macro to insert BOM into sheet and link to configuration in that sheet

Question asked by Grant Kirkland on Oct 24, 2017
Latest reply on Oct 25, 2017 by Mr Omkar Deshpande

I have a macro which will insert a BOM into a sheet, and another (thanks Deepak) which renames the sheet to match the configuration name.

I would like to combine these macros.

 

Goals:

Rename sheet to configuration name

Insert BOM (top level only)

Rename BOM to <Configuration name> BOM

Link BOM to the first (or any?) drawing view on each sheet (or not linked at all? I'm not sure...)

 

I don't want the drawing views linked to a BOM, I just want the BOM on the sheet because all views on a sheet will always be linked to the BOM inserted into that sheet.

I hope some of that makes sense.

 

 

This is what I have so far:

 

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSheet As SldWorks.Sheet

Dim swModelview2 As Configuration

Dim ConfigName As String

Dim vSheets As Variant

Dim swView As SldWorks.View

Dim i As Integer

 

 

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

 

 

vSheets = swModel.GetSheetNames

For i = 1 To swModel.GetSheetCount

swModel.ActivateSheet vSheets(i - 1)

Set swSheet = swModel.GetCurrentSheet

Count = swModel.GetModelViewCount

 

 

Set swView = swModel.GetFirstView

 

 

Do While Not swView Is Nothing

ConfigName = swView.ReferencedConfiguration

Set swView = swView.GetNextView

Loop

swSheet.SetName ConfigName

 

 

'-----------------------------------------------------

    ' Select Drawing View1

    swModel.ClearSelection2 True

 

 

    boolstatus = swModel.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0#, 0#, 0#, True, 0, Nothing, swSelectOptionDefault): Debug.Assert boolstatus

    Set swView = swModel.SelectionManager.GetSelectedObject6(1, -1)

    'Set swView = swModel.GetFirstView

   

    ' Get selected drawing view

    AnchorType = swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft

    BomType = swBomType_e.swBomType_TopLevelOnly

    Configuration = ""

    TableTemplate = "C:\Vault\Templates\Standard Bom - PDM.sldbomtbt"

   

    ' Insert BOM table

    Set swBomAnn = swView.InsertBomTable2(False, 0.45, 0.28, AnchorType, swBomType_e.swBomType_TopLevelOnly, Configuration, TableTemplate)

    swModel.ClearSelection2 True

'-----------------------------------------------------

 

 

Next i

 

 

' Rebuild

swModel.EditRebuild3

' Zoom To Fit

swModel.ViewZoomtofit2

' Save

swModel.Save2 False

   

End Sub

Outcomes