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,我们下篇文章再见。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/4.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Kimi(月之暗面AI)模型上线,支持长文本输入分析文档内容

国产AI模型目前在市场中正趋于白热化,各大国产AI厂商百花齐放,纷纷优化升级语言模型。近日,备受瞩目的国产AI大模型“月之暗面”也不例外,它对去年10月推出的重量级模型moonshot进行了显著的升级,进一步无损扩展了上下…

(五)C++自制植物大战僵尸游戏LoadingScene的实现讲解

植物大战僵尸游戏开发教程专栏地址http://t.csdnimg.cn/xjvbb 一、类介绍 游戏启动后就会立即切换到游戏加载场景中。只有游戏资源文件加载完成后,才能进入游戏。Loadingscene类继承Cocos2d-x中的Scene父类,表明Loadingscene是一个场景类。切换到Loadi…

2024年苹果审核4.3相关问题综述

文章标签:UI、iOS、Objective-C、开发语言 苹果审核中的4.3问题是开发者关注的焦点之一,本文对此进行了综述,总结了不同情况下的处理方式和优化策略。 第一种4.3 该类问题常见于代码或UI的重复率过高,苹果会直接拒绝应用。开发…