Hi all, and thanks for taking the time to consider my question. I need to open large assemblies that contain toolbox components. I am running a standard licence of solidworks which doesn't include toolbox. An error is caused ever ytime solidworks tries to open one of these toolbox components, see attached image. The end result is that I need to press escape many many times to clear these errors while the assembly opens. It's eating up large chunks of my day.
Does anyone know (a) of a way to clear these toolbox errors ,or (B) whether the Solidworks API can be used to handle these errors and automatically clear them? The macro would need to be running while the assembly is being opened. Is this even possible?
Thanks all, any help is much appreciated.
Brian
SolidworksApi macros
Hello Unspecified,
Try using ISldWorks::OpenDoc6 with the "swOpenDocOptions_Silent" option passed in the Options argument. I haven't tested it in your situation but this option does prevent error messages and warnings from appearing, so it might do the trick. Here's an example of how the VBA code would look with an assembly called "Assem1.SLDASM" that's located on your C:\.
swApp.OpenDoc6 "C:\Assem1.SLDASM", swDocASSEMBLY, swOpenDocOptions_Silent, Empty, Empty, Empty
If you need to cycle through all files in a directory then you'll want to use the Dir() function.
Keith
Video Tutorials for the SolidWorks API
Good stuff thanks Keith. I'm gonna look into this and see if I can get it to work. Thanks again.
B
Hi again Keith, it's me, Unspecified Unspecified
So, I followed your suggestion and used OpenDoc6. Just what I needed, thanks! Google led me to the ready made example here, so I'm in business. I do have a few additional queries, if you'll excuse my straying from the original question.
What I'd like the macro at link I posted to do, is prompt the user to select a file rather than have the file path written into the code. Do you by chance have any idea how to do that? In Excel VBA I'd do something like what is posted here, however this doesn't work with the solidwork API.
Another aside; I'm also interested in shifting the active search directory (i.e. the one that SW searches when opening parts) to the location of the user selected file to ensure it loads the correct files. I'm trying to implement what's described here, but I am not clear on what this page is telling me to do. My current flawed interpretation is below, but I don't have a clear understanding of what the code is doing or how to implement the "declaration" and "usage" sections described. I'll need to take those tutorials I saw somewhere, but in the meantime, I'd love to hear your thoughts.
As you can likely tell, I have limited experience with VBA in excel and this is my first crack at the solidworks API.
Brian
-------------------------------------------------------------------------------------------------------------------------------------------------------
Function SetCurrentWorkingDirectory(ByVal CurrentWorkingDirectory As String) As Boolean
End Function
--------------------------------------------------------------------------------------------------------------------------------------------------------
Sub test()
Dim instance As ISldWorks
Dim CurrentWorkingDirectory As String
Dim value As Boolean
CurrentWorkingDirectory = "A:\"
value = instance.SetCurrentWorkingDirectory(CurrentWorkingDirectory)
End Sub
--------------------------------------------------------------------------------------------------------------------------------------------------------
Hello Unspecified,
To prompt the user for a file, use ISldWorks::GetOpenFileName. That will create a native SolidWorks open dialog.
Here's how to change the working directory to A:\
=======
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
swApp.SetCurrentWorkingDirectory "A:\"
End Sub
=======
All I can say is, I think you would really benefit from our free tutorials!
Keith
Learn the SolidWorks API