×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

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

Jobs

Macros Intermittently Not Working

Macros Intermittently Not Working

Macros Intermittently Not Working

(OP)
Hi

We've been having a bit of an issue running macros. The problem dates back to the 1st computer we had running a 64bit OS, which is a long time ago in a Windows and SolidWorks version far far away.

When it first started, it would happen at some point during the day, normally after having some large assembly open. All of our macros that we have created here stop working, SolidWorks just displays a message saying Cannot open "file path, \macro.dll"

Restarting SolidWorks would solve the problem.

Now we are running 64bit on pretty much all of our stations, and it's becoming a big problem. Restarting SolidWorks does not always fix the issue now, and it happens a lot.

I've tried re-compiling the code and that seems to fix it, but it doesn't last long.

The machines it is happening on are all decent spec, and not getting anywhere near their limits.

Any ideas?
 

RE: Macros Intermittently Not Working

Good luck!

We have run into this before when upgrading from 2008 to 2009.  All of a sudden recursives didn't work (it would grab random data and use it to return some rather interesting results) along with some other commands.  That issue and the fact that the macros all of a sudden ran 20% to 30% slower has meant we are afraid to update to later versions.  The macros had to be rewritten to get around it and no one has the time to do that every year.

The most bizzarre thing is that most of our macro crashes now occur on file handling stuff (like close or open).  

Some SolidWork VBA commands just don't work (such as anything to do with modifying the hole wizzard and some Simulation stuff).  

The only way I was able to find work arounds was to run it a lot in debug mode and find out where the code was crashing.  This can be hard because sometimes it will not crash in debug as much as in normal mode.  

Once you find out where, you can program around it (usually).

RE: Macros Intermittently Not Working

(OP)
Once the problem occurs, I can't even run the macro in debug mode (I assume that you mean hitting the play button from the edit macro command, bear with me, I don't code very often and forget how to do it in between)

If I start debugging, nothing happens. I have to hit stop.

RE: Macros Intermittently Not Working

If you're running a .dll "VSTA" or visual studio tools for applications macro from a button, it will only run once per instance of SolidWorks unless you're on SolidWorks 2011 SP 3.0 or higher.

James Spisich
Design Engineer, CSWP

RE: Macros Intermittently Not Working

If you hit F8 (F5 is run) it will go line by line.

You can also set toggles to stop it.

The F8 step by step will show you where it hangs up.

John

RE: Macros Intermittently Not Working

(OP)
I'll give that a go. I'm running SW2011SP5 BTW.

I've passed the problem on to my VAR, but they're struggling with it. I find it strange that it's not a common issue, we've been coping with it for years.

RE: Macros Intermittently Not Working

(OP)
vbproj (.dll's)

RE: Macros Intermittently Not Working

(OP)
my VAR has come back with the suggestion to change the code for the SolidWorksMacroStartup to this:

-----

Imports SolidWorks.Interop.sldworks
Imports System

Imports System.Diagnostics
Imports System.Text

Partial Class SolidWorksMacro


    Private Sub SolidWorksMacro_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

        Dim sb As New StringBuilder

        Try
            Me.swApp = Me.SolidWorksApplication
        Catch exStartup As Exception

            sb.Length = 0
            sb.AppendLine(exStartup.Message)
            sb.AppendLine()
            sb.AppendLine(exStartup.StackTrace)

            System.Diagnostics.Debug.WriteLine(sb.ToString())

            System.Windows.Forms.MessageBox.Show(sb.ToString(), "1")

        End Try

        Dim runResult As SolidWorks.RunMacroResult = RunMacro()
        If (runResult = SolidWorks.RunMacroResult.NoneSpecified) Then
            Try
                SwMacroSetup()
            Catch exSetup As Exception

                sb.Length = 0
                sb.AppendLine(exSetup.Message)
                sb.AppendLine()
                sb.AppendLine(exSetup.StackTrace)

                System.Diagnostics.Debug.WriteLine(sb.ToString())

                System.Windows.Forms.MessageBox.Show(sb.ToString(), "2")
            End Try
            main()
            Try
                SwMacroCleanup()
            Catch exCleanup As Exception

                sb.Length = 0
                sb.AppendLine(exCleanup.Message)
                sb.AppendLine()
                sb.AppendLine(exCleanup.StackTrace)

                System.Diagnostics.Debug.WriteLine(sb.ToString())

                System.Windows.Forms.MessageBox.Show(sb.ToString(), "3")
            End Try
        End If

    End Sub

    Private Sub SolidWorksMacro_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

    End Sub


End Class

-----

I don't really have the time at the moment to test it out, and I'm not experienceing the problem at the moment, but I thought I'd post the code up in case anyone else finds it useful.
 

RE: Macros Intermittently Not Working

(OP)
Well, this problem is still not solved. I've had net meetings with my VAR and left it with them, they came back with a fix, but that hasn't worked. They have offered to do another net meeting, but at this stage that's taking up more time than the problem and we're extremely busy as usual.

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!


Resources