Anyone have a macro to link all drawing views back to a BOM that has been replaced on sheet 1.  My guys like to swap out BOM, but sometime they don't re-link the BOM after they load a new one.  I have some assemblies that are 5-12 sheets long and can be as many as 30-40 views.  Manually linking them is very tedious.


Categories: API∕Macros

Comments
Last comment By: Deepak Gupta   Mon, 11 Dec 2017 15:50:30 GMT
Re: Macro To link all views to BOM on Sheet 1

Try this.......

 

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDraw As SldWorks.DrawingDoc

Dim vSheetNames() As String

Dim swView As SldWorks.View

Dim i As Integer

Dim sName As String

 

Sub main()

sName = "Bill of Materials1"                 'Name of BOM table

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swDraw = swModel

vSheetNames = swDraw.GetSheetNames

Set swView = swDraw.GetFirstView

For i = 0 To UBound(vSheetNames)

swDraw.ActivateSheet vSheetNames(i)

Set swView = swDraw.GetFirstView

Do While Not swView Is Nothing

  swView.SetKeepLinkedToBOM True, sName

  Set swView = swView.GetNextView

Loop

Next

End Sub

By: Mr Omkar Deshpande  Fri, 04 Nov 2016 10:48:30 GMT
Re: Macro To link all views to BOM on Sheet 1

Try this one. It doesn't need to know the name of the BOM. It will automatically find it.

By: Matt Martens  Fri, 04 Nov 2016 11:38:48 GMT
Re: Macro To link all views to BOM on Sheet 1

What if you have a bom and a weldment cutlist?

By: Tony Cantrell  Fri, 04 Nov 2016 12:46:29 GMT
Re: Macro To link all views to BOM on Sheet 1

looks good however "Bill of Materials1" might not always be the correct name

By: Cad Admin  Fri, 04 Nov 2016 13:09:41 GMT
Re: Macro To link all views to BOM on Sheet 1

In my case i never have a weldment cut list and assembly BOM in the same Drawing.

By: Cad Admin  Fri, 04 Nov 2016 13:11:20 GMT
Re: Macro To link all views to BOM on Sheet 1

Deepak, I believe i adapted this macro from your work so thank you for sharing it.

 

Tony, I modified Deepak original code to traverse through the feature manager tree and find the BOM. In API a BOM and a weldment cutlist are different. The code should automatically find the name of only the BOM.

 

Now, if there are multiple BOMs in your drawing that is another story.

By: Matt Martens  Fri, 04 Nov 2016 13:12:03 GMT
Re: Macro To link all views to BOM on Sheet 1

Matt,

that one works great.

 

As a side question...how easy would it be to populate a list of all the BOMS in a drawing (if multiple) and select which to link to.

 

Matt's macro works in 95% of my application but in the other i have a parts only on the first page and the second page may contain a top level.  Depending on the situation i could want one or the other....

 

For my direct application, Matt's Fills the gap...AWESOME

By: Cad Admin  Fri, 04 Nov 2016 13:16:06 GMT
Re: Macro To link all views to BOM on Sheet 1

A user form would probably be the way to go to get a list to select from. But the easier way may be to have the user select the correct BOM in the feature tree and use code to get the name of the selected BOM. You could also have the code send up a prompt if they didn't have a BOM selected.

By: Matt Martens  Fri, 04 Nov 2016 13:22:44 GMT
Re: Macro To link all views to BOM on Sheet 1

I use the bom on sheet 1 and a cutlist when detailing weldments on following sheets.

By: Tony Cantrell  Fri, 04 Nov 2016 13:30:54 GMT
Re: Macro To link all views to BOM on Sheet 1

Tony, this macro works for both.

 

Matt, thanks for sharing, I've been searching in my old archive for this macro but then realized that it was lost with the HDD crash.

By: Deepak Gupta  Fri, 04 Nov 2016 13:02:15 GMT
Re: Macro To link all views to BOM on Sheet 1

Matt,

 

Will this update all sheets at once... or does the macro need to be run on all sheets separately...

By: Cad Admin  Fri, 04 Nov 2016 17:30:38 GMT
Re: Macro To link all views to BOM on Sheet 1

I'm not sure because I only deal in one sheet drawings and so I have never tested it on a multiple sheet drawing. Base on the code and how it traverses the drawing views I think it should do all views on all sheets.

By: Matt Martens  Fri, 04 Nov 2016 17:35:12 GMT
Re: Macro To link all views to BOM on Sheet 1

Here is updated macro to work on all sheets.

By: Deepak Gupta  Fri, 04 Nov 2016 18:07:25 GMT
Re: Macro To link all views to BOM on Sheet 1
By: Tony Cantrell  Fri, 04 Nov 2016 19:00:18 GMT
Re: Macro To link all views to BOM on Sheet 1

Thanks Deepak Gupta.

I have the same problem, but I have many Bills of Materials per Drawing, is there anyway I can run the macro on one sheet, and have me select from the BoM's available?

By: Joseph Caswell  Thu, 07 Dec 2017 14:50:09 GMT
Re: Macro To link all views to BOM on Sheet 1

Do you mean more than one BOM on one sheet?

By: Deepak Gupta  Fri, 08 Dec 2017 17:49:30 GMT
Re: Macro To link all views to BOM on Sheet 1

No. Just more than one Bill of Materials per drawing.

By: Joseph Caswell  Sat, 09 Dec 2017 12:14:37 GMT
Re: Macro To link all views to BOM on Sheet 1

Joseph Caswell wrote:

 

No. Just more than one Bill of Materials per drawing.

More than one BOM per drawing is fine but are there more than one BOM on same sheet?

By: Deepak Gupta  Sat, 09 Dec 2017 12:25:35 GMT
Re: Macro To link all views to BOM on Sheet 1

There is not.

By: Joseph Caswell  Sat, 09 Dec 2017 12:34:32 GMT
Re: Macro To link all views to BOM on Sheet 1

Then why you need to choose the BOM. The macro (the macros to do this are in bits and pieces and those need to be combined) can find the BOM on the active sheet and link views on that sheet to that BOM.

By: Deepak Gupta  Sun, 10 Dec 2017 08:29:54 GMT
Re: Macro To link all views to BOM on Sheet 1

I don't have much experience with VBA, but I'll give it a try and publish it here for anybody else that needs something like this.

 

My drawings are for an assembly that have many subassemblies and weldments and I show a full page isometric view with the Bill of Materials for each subassembly and then spend the next one or two pages detailing out that subassembly.

 

My goal is to create a form so that my team members and I can place all the views on a sheet and then select which BOM to link all of the views on that sheet to.

By: Joseph Caswell  Mon, 11 Dec 2017 13:36:27 GMT
Re: Macro To link all views to BOM on Sheet 1

This is a amalgamation of macros that others have written, but here is a macro that presents the user with a list of all BoM's (and Weldment lists) in the drawing and then assigns that BoM to all views on the active sheet.

By: Joseph Caswell  Mon, 11 Dec 2017 15:02:11 GMT
Re: Macro To link all views to BOM on Sheet 1

Joseph, thanks for sharing. Might come in handy for someone

By: Deepak Gupta  Mon, 11 Dec 2017 15:50:30 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.