当前位置: 代码网 > it编程>编程语言>Asp.net > C# Solidworks二次开发:程序工具界面和选项相关API详解

C# Solidworks二次开发:程序工具界面和选项相关API详解

2024年07月28日 Asp.net 我要评论
​大家好,今天要讲的是关于程序工具相关的API介绍。下面是要介绍的API:(1)第一个为GetAutoPartSimplification,这个API的含义为获取简化配置的指针,下面是官方具体解释:其输入参数的类型在上一篇文章中已经介绍过了gtError_e,返回值为指向简化配置的指针。(2)第二个为GetOptions,这个API的含义为获取solidworks实用程序选项,下面是官方的具体解释:其输入参数的类型如上所示,返回值为指向选项数组的指针。(3)第三个为GetT

大家好,今天要讲的是关于程序工具相关的api介绍。

下面是要介绍的api:

(1)第一个为getautopartsimplification,这个api的含义为获取简化配置的指针,下面是官方具体解释:

其输入参数的类型在上一篇文章中已经介绍过了gterror_e,返回值为指向简化配置的指针。

(2)第二个为getoptions,这个api的含义为获取solidworks实用程序选项,下面是官方的具体解释:

其输入参数的类型如上所示,返回值为指向选项数组的指针。

(3)第三个为gettoolinterface,这个api的含义为获取solidworks中实用工具的指针,下面是官方的具体解释:

其输入值有两个,第一个为输入定义工具的id,如下所示:

memberdescription
gtswfindreplaceannotations

10

gtswthickchk7
gtswtoolbendsequencedrawingnot used
gtswtoolcompboms8
gtswtoolcompdocs0
gtswtoolfeatdiff1
gtswtoolfeatpaint6
gtswtoolgeomcheck3
gtswtoolgeomdiff2
gtswtoolpowerselect4

第二个输入参数为报错,如上面所示。

返回值为指向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,我们下篇文章再见。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com