Replace Model in drawings over multiple sheets

1.1k Views Asked by At

I sometimes need to create the same drawing for multiple parts.

I created a macro that, once the user creates the required drawing, will take all the rest of the parts and substitute them into the drawing, while saving the drawing as a new drawing name.

When the macro is finished, the user will have the same amount of drawings as parts, and each related drawing will have its related part within.
There will probably be dangling dimensions that need to be re-attached, however, this will be quicker than copying the drawing, and replacing the model on the views, or referencing the model on drawing startup etc.

The macro follows these steps:

  1. Open the reference drawing.
  2. Replace all views with new model.
  3. Save drawing with new name.

I found I need to close the drawing and re-open it on each loop. Otherwise multiple (invisible) SolidWorks applications open and it corrupts the reference drawing file.

Opening and closing documents tend to take time.

With

swApp.DocumentVisible False, swDocDRAWING

I found it doesn't open the drawing each time.

For single sheet drawings the macro races through and creates what I need.

For double sheet drawings (Sheet 1 and Sheet 2) I found only the views on Sheet 2 of each drawing would be updated with the new model.

If the Drawing Document is not visible, then commands that move the pointer do not work.

Like:

swModel.ActivateSheet vSheets(0)

The pointer gets stuck on the last sheet (Sheet 2). This leads to only Sheet 2 being modified for each drawing.

If I take this away, and keep the document visible, it works. However, it is slow because it is opening and closing documents.

How can I modify a Drawing without having it visible?
Or how can I move the pointer between sheets while it is invisible?

2

There are 2 best solutions below

1
On

A better way to do this and the fastest you can achieve:

  • copy the drawing file and give it a new name
  • with the new drawing closed: use ReplaceReference (from SoildWorks Document Manager library) or ReplaceReferencedDocument to replace the path of the old part with the path of the new part
  • open the drawing.
0
On

Sorry, this is late but I will still post it. It may be useful to somebody.

To change the model on which a base view is based, you need neither to select or activate the sheet or the base view.

You can access the Base View object and then use ReplaceViewModel method of DrawingDoc object.