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

大家好,今天要讲的是关于程序工具相关的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,我们下篇文章再见。

  • 28
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
C# SolidWorks二次开发是指使用C#编程语言来扩展和定制SolidWorks软件的功能。下面是进行C# SolidWorks二次开发的步骤: 1. 环境配置: - 首先,确保您已经安装了SolidWorks软件和Visual Studio开发环境。 - 然后,安装SolidWorks API SDK。您可以在SolidWorks安装包中找到"SolidWorks API SDK.msi"文件,并按照安装向导进行安装。 2. 创建插件Addin: - 打开Visual Studio,并创建一个新的C#项目。 - 在项目中,添加对SolidWorks API的引用。您可以在项目的引用中添加SolidWorks.Interop.sldworks和SolidWorks.Interop.swcommands等引用。 - 创建一个类,并实现SolidWorks的事件接口,例如ISwAddin或ISwAddin2。 - 实现所需的功能,例如创建自定义工具栏、菜单或按钮,并实现其相应的事件处理程序。 3. 运行和调试: - 在Visual Studio中编译和生成项目。 - 将生成的插件文件(.dll文件)复制到SolidWorks的插件目录中,一般为"C:\ProgramData\SolidWorks\SOLIDWORKS 20XX\addins"。 - 启动SolidWorks软件,您应该能够看到您创建的自定义工具栏、菜单或按钮。 - 单击按钮或执行其他操作来测试和调试您的插件功能。 通过以上步骤,您可以开始使用C#编程语言进行SolidWorks二次开发,实现自定义的功能和工具,以满足您的需求。请确保在开发过程中参考官方文档和其他相关教程,以便更好地理解和掌握C# SolidWorks二次开发的技术。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑さん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值