大家好,今天要讲的是关于程序工具相关的api介绍。
下面是要介绍的api:
(1)第一个为getautopartsimplification,这个api的含义为获取简化配置的指针,下面是官方具体解释:
其输入参数的类型在上一篇文章中已经介绍过了gterror_e,返回值为指向简化配置的指针。
(2)第二个为getoptions,这个api的含义为获取solidworks实用程序选项,下面是官方的具体解释:
其输入参数的类型如上所示,返回值为指向选项数组的指针。
(3)第三个为gettoolinterface,这个api的含义为获取solidworks中实用工具的指针,下面是官方的具体解释:
其输入值有两个,第一个为输入定义工具的id,如下所示:
member | description |
---|---|
gtswfindreplaceannotations | 10 |
gtswthickchk | 7 |
gtswtoolbendsequencedrawing | not used |
gtswtoolcompboms | 8 |
gtswtoolcompdocs | 0 |
gtswtoolfeatdiff | 1 |
gtswtoolfeatpaint | 6 |
gtswtoolgeomcheck | 3 |
gtswtoolgeomdiff | 2 |
gtswtoolpowerselect | 4 |
第二个输入参数为报错,如上面所示。
返回值为指向solidworks实用工具界面的指针。
下面是官方使用的例子:
this example shows how to use the solidworks utilities api to compare geometries in two part documents.
'---------------------------------------------------------------------------------
' preconditions:
' 1. add the solidworks utilities as an add-in
' (in solidworks, click tools > add-ins > solidworks utilities).
' 2. add the solidworks utilities interop assembly as a reference
' (right-click the project in project explorer, click add reference >
' browse to install_dir\api\redist > solidworks.interop.gtswutilities.dll).
' 3. verify that the specified files exist.
' 4. verify that c:\test\ exists.
' 5. open the immediate window.
'
' postconditions:
' 1. creates c:\test\report\gtreportindex.htm.
' 2. gets the face and volume comparison statuses.
' 3. examine the immediate window, graphics area, and
' c:\test\report\gtreportindex.htm.
'
' note: because the parts are used elsewhere, do not save changes.
'--------------------------------------------------------------------------------
using solidworks.interop.sldworks;
using solidworks.interop.swconst;
using solidworks.interop.gtswutilities;
using system;
using system.diagnostics;
namespace comparegeometry_csharp.csproj
{
partial class solidworksmacro
{
public void main()
{
gtcocswutilities swutil = default(gtcocswutilities);
gtcocswcomparegeometry swutilcompgeom = default(gtcocswcomparegeometry);
gterror_e longstatus = default(gterror_e);
bool baddtobinder = false;
bool boverwrite = false;
int errorcode = 0;
// get the solidworks utilities tool interface
swutil = (gtcocswutilities)swapp.getaddinobject("utilities.utilitiesapp");
// get the comparegeometry tool
swutilcompgeom = (gtcocswcomparegeometry)swutil.gettoolinterface(2, out errorcode);
if (!(errorcode == (int)gterror_e.gtnoerr))
{
debug.print("error getting compare geometry tool.");
}
// compare the volumes and faces of the specified part documents
// save the results to a file in the specified path
baddtobinder = false;
boverwrite = true;
string file1 = null;
string file2 = null;
int voldiffstatus = 0;
int facediffstatus = 0;
file1 = "c:\\users\\public\\documents\\solidworks\\solidworks 2018\\samples\\tutorial\\swutilities\\bracket_a.sldprt";
file2 = "c:\\users\\public\\documents\\solidworks\\solidworks 2018\\samples\\tutorial\\swutilities\\bracket_b.sldprt";
longstatus = (gterror_e)swutilcompgeom.comparegeometry3(file1, "", file2, "", (int)gtgdfoperationoption_e.gtgdffaceandvolumecompare, (int)gtresultoptions_e.gtresultsavereport, "c:\\test\\report", baddtobinder, boverwrite, ref voldiffstatus,
ref facediffstatus);
if (!(longstatus == gterror_e.gtnoerr))
{
debug.print("error comparing geometries.");
}
diffstatus("volume comparison", voldiffstatus);
diffstatus("face comparison", facediffstatus);
// perform any necessary clean up
longstatus = (gterror_e)swutilcompgeom.close();
}
public void diffstatus(string name, int diffcode)
{
debug.print(name);
switch (diffcode)
{
case (int)gtvoldiffstatusoptiontype_e.gtsuccess:
debug.print("succeeded");
break;
case (int)gtvoldiffstatusoptiontype_e.gtnotperformed:
debug.print("not performed");
break;
case (int)gtvoldiffstatusoptiontype_e.gtcanceled:
debug.print("canceled");
break;
case (int)gtvoldiffstatusoptiontype_e.gtfailed:
debug.print("failed");
break;
case (int)gtvoldiffstatusoptiontype_e.gtidenticalparts:
debug.print("identical parts");
break;
case (int)gtvoldiffstatusoptiontype_e.gtdifferentparts:
debug.print("different parts");
break;
case (int)gtvoldiffstatusoptiontype_e.gtnosolidbody:
debug.print("no solid body found");
break;
case (int)gtvoldiffstatusoptiontype_e.gtalreadysaved:
debug.print("already saved");
break;
}
debug.print(" ");
}
public sldworks swapp;
}
}
上面就是本篇文章要介绍的三种api,我们下篇文章再见。
发表评论