How to open Solidworks, run macro, and close Solidworks from vb.net script? [closed]

风流意气都作罢 提交于 2019-12-10 18:59:54

问题


I am running a VBA Macro in solidworks that stops working and requires me to restart Solidworks after exactly 478 loop-itterations every time I run it.

Inside my loop, I open an STEP file, verify it, and then save it as an STL file. It appears as if Solidworks is struggling to open more than a fixed number of files in the same session.

My plan was to write a VB.NET script outside of Solidworks that can automatically restart the application without my intervention every X number of ittwerations, so I can process the thousands of files I have without my intervention.

VB.NET console script that closes and reopens Solidworks for me, whenever 477 itterations are reached, and then continues the macro from where it has left off.

The folders with my files are numbered, e.g.

c:\data\0\file.STEP
c:\data\1\file.STEP
c:\data\2\file.STEP
...
c:\data\20000\file.STEP

Specifically, I am looking for the VB.NET code that does the following:

  1. Open Solidworks
  2. Call an existing Macro-Script (possibly set a variable that lets me continue where I left of processing the data)
  3. Close Solidworks

回答1:


1) first you need to open solidworks and the file you want to process: Open Assembly Document Example (VB.NET) http://help.solidworks.com/2017/english/api/sldworksapi/open_assembly_document_example_vbnet.htm

2) you will need the openMacro2 function. Here is a link with an example https://forum.solidworks.com/thread/79502

3) then close all documents with the CloseAllDocuments Method http://help.solidworks.com/2017/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISldWorks~CloseAllDocuments.html

4) then exit solidworks with the ExitApp Method https://help.solidworks.com/2017/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISldWorks~ExitApp.html

note: if you installed the api module you will find all needed examples in the apihelp.chm file which is located by default in: C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\api

I took the liberty choosing version 2017 since you didn't mention the version you are using. But all examples should work on later versions too. If you are on an earlier version and you cannot find for instance openDoc7, then look at openDoc6 or openDoc5... until you find the number that is available on your system.



来源:https://stackoverflow.com/questions/57541047/how-to-open-solidworks-run-macro-and-close-solidworks-from-vb-net-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!