Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to open all sub-assemblies, and parts, run macro, and return to orginal active assembly.

Status
Not open for further replies.

JoeMcCabe

Mechanical
Nov 24, 2014
1
0
0
US
thread559-156219

I used to have this macro running but now it seems to have changed behavior.
I was using the macro, I think un-edited, as posted by handleman, date 31 May 06 at 20:10. posted immediately below:

Sub ActivateOpenFilesAndRunMyMacro()
Dim swDoc As SldWorks.ModelDoc2
Dim swAllDocs As EnumDocuments2
Dim FirstDoc As SldWorks.ModelDoc2
Dim dummy As Boolean
Dim NumDocsReturned As Long
Dim DocCount As Long
Dim i As Long
Dim sMsg As String
Dim swApp As SldWorks.SldWorks
Dim bDocWasVisible As Boolean

Set swApp = Application.SldWorks
Set swAllDocs = swApp.EnumDocuments2
Set FirstDoc = swApp.ActiveDoc

DocCount = 0
swAllDocs.Reset
swAllDocs.Next 1, swDoc, NumDocsReturned
While NumDocsReturned <> 0
bDocWasVisible = swDoc.Visible
swApp.ActivateDoc swDoc.GetPathName
'************************
'*Call your macro that works on the open, visible, active
'*document here
'************************
swDoc.Visible = bDocWasVisible
swAllDocs.Next 1, swDoc, NumDocsReturned
DocCount = DocCount + 1
Wend

swApp.ActivateDoc FirstDoc.GetPathName
End Sub

My issue is that the macro code line
swDoc.Visible = swDocWasVisible
doesn't return the parts and sub-assemblies to invisible state anymore.

I'm not sure if I had tweaked the macro I was using, but even re-writing based on this old thread, I can't get it to work again.

Let me explain what I'd like to accomplish ...
From a top level assembly, I want to open all parts and sub-assemblies, potentially several levels deep, as well as those parts included with-in all,
then run a bounding box macro which writes dimensional info to custom properties, ( (That code seems to still work fine.)
safe all the part and assembly files with the new values,
and return to the original active assembly.

Now what is happening is all the part files stay visible, and since the assemblies are quite large, I keep running out of memory to completely transverse all the way through my full assembly before Solidworks crashes

A Side note: I am running the Bounding Box macro from another module within the same macro file. And if I remember correctly, I also was having trouble with getting the revised/updated files to save with the new values, so I added a third module with a save file macro. That really slowed everything down substantially, but I think it worked otherwise.

I would like to the bounding box to run on each sub-assembly as well as the top level assembly too, and capture that data in the assembly files the same way I'm doing in the part files. I think the code from handleman did that when I was trying to set this up originally.

It all used to work, I swear. Is there a setting within Solidworks that would effect that line? Or did I do something else wrong at some point?
This project was set aside for a while and now I'd love to get back to it and make it all work. Any help would be appreciated.

Respectfully, and thankfully,
Joe
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top