Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


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

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

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

thread559-156219: API Opening each part file in an assembly.

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.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

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, (https://forum.solidworks.com/thread/31539) (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,

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

If anyone has some advice on this I would love to hear it at as well.
I am trying to something very similar.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close