如何从vb.net脚本打开Solidworks,运行宏并关闭Solidworks? [英] How to open Solidworks, run macro, and close Solidworks from vb.net script?

查看:1033
本文介绍了如何从vb.net脚本打开Solidworks,运行宏并关闭Solidworks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在solidworks中运行一个VBA宏,该宏停止工作,并且要求每次运行478次循环触发后我都要重新启动Solidworks.

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.

在循环中,我打开一个STEP文件,进行验证,然后将其另存为STL文件.似乎Solidworks在同一会话中无法打开固定数量的文件.

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.

我的计划是在Solidworks外部编写一个VB.NET脚本,该脚本可以自动地重新启动应用程序,而无需每执行X次迭代,因此我可以在没有干预的情况下处理成千上万的文件.

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控制台脚本会在达到477个故障时为我关闭并重新打开Solidworks,然后从停止的位置继续执行宏.

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

具体来说,我正在寻找执行以下操作的VB.NET代码:

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

  1. 打开Solidworks
  2. 调用现有的宏脚本(可能设置一个变量,使我可以继续处理数据的位置)
  3. 关闭Solidworks

推荐答案

1)首先,您需要打开solidworks和要处理的文件: 打开程序集文档示例(VB.NET) http://help.solidworks.com/2017/english/api/sldworksapi/open_assembly_document_example_vbnet.htm

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),您将需要 openMacro2 功能. 这是一个带有示例的链接 https://forum.solidworks.com/thread/79502

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

3),然后使用 CloseAllDocuments 方法 http://help.solidworks.com/2017/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISldWorks~CloseAllDocuments.html

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),然后使用 ExitApp 方法退出solidworks. https://help.solidworks.com/2017/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISldWorks~ExitApp.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

注意:如果安装了api模块,则将在apihelp.chm文件中找到所有需要的示例,该文件默认位于: C:\ Program Files \ SOLIDWORKS Corp \ SOLIDWORKS \ api

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

我选择了2017版,因为您没有提到您使用的版本.但是所有示例也应在更高版本上运行.如果您使用的是较早版本,则找不到openDoc7,那么请查看openDoc6或openDoc5 ...,直到找到系统上可用的编号.

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.

这篇关于如何从vb.net脚本打开Solidworks,运行宏并关闭Solidworks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆