Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macros Intermittently Not Working

Status
Not open for further replies.

SteveJJH

Mechanical
Feb 5, 2009
109
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?
 
Replies continue below

Recommended for you

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).
 
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.
 
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
 
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
 
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.
 
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor