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

这篇具有很好参考价值的文章主要介绍了C# Solidworks二次开发:程序工具界面和选项相关API详解。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

下面是要介绍的API:

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

C# Solidworks二次开发:程序工具界面和选项相关API详解,Solidworks二次开发,c#,java,前端,开发语言

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

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

C# Solidworks二次开发:程序工具界面和选项相关API详解,Solidworks二次开发,c#,java,前端,开发语言

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

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

C# Solidworks二次开发:程序工具界面和选项相关API详解,Solidworks二次开发,c#,java,前端,开发语言

其输入值有两个,第一个为输入定义工具的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,我们下篇文章再见。文章来源地址https://www.toymoban.com/news/detail-854846.html

到了这里,关于C# Solidworks二次开发:程序工具界面和选项相关API详解的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • C# Solidworks二次开发:创建距离配合以及移动组件API详解

    今天要讲的文章是关于如何创建距离配合和移动组件的API详解。 (1)创建配合API,CreateMate() 这个API的解释是根据指定的特性数据对象来创建配合,也就可以理解为输入什么样的特征对象就可以创建出什么配合,这个API的输入参数类型为object,返回的参数类型为Feature。 而输

    2024年02月09日
    浏览(44)
  • C# Solidworks二次开发:自动创建虚拟零件及使用注意事项

    今天要讲的是关于在solidworks中如何自动创建虚拟零件的功能,也就是solidworks中插入新零件这个功能。 实现这个功能需要使用的API如下所示: InsertNewVirtualPart(swFaceOrPlane1, out swcomp2); 其中这个方法中使用到了两个参数。 第一个参数:为一个平面,或是一个基准平面。 第二

    2024年02月15日
    浏览(47)
  • Python SolidWorks 二次开发---Python如何连接SolidWorks

    用Python来进行SolidWorks的二次开发其实是有点非主流的,因为Python本身的特性导致程序运行的效率会比VBA等SolidWorks原生支持的二次开发软件运行效率降低50%以上,用Python仅仅是因为语法简单,实现起来快捷,且所开发的功能仅供个人提高效率使用。这里记录一些开发过程,如

    2024年02月11日
    浏览(30)
  • SOLIDWORKS二次开发——拓展设计能力与定制化解决方案

    SOLIDWORKS是一款广泛应用于机械设计行业的三维CAD软件,它提供了丰富的功能和工具,满足了企业的基本设计需求。然而,有时候标准软件的功能无法满足特定的要求,这就需要进行二次开发来扩展SOLIDWORKS的功能,制定定制化的解决方案。   1. 什么是SOLIDWORKS二次开发? SOLI

    2024年02月07日
    浏览(41)
  • 如何利用chatGPT/GPT4高效学习Solidworks二次开发

    要不我们来试试它? 先用这个试试,据说这个比较方便,直接是在对应的文件中进行对话。 安装后,直接在左侧建立一个你熟悉的后缀格式。我就用main.cs吧 按Ctrl+K和它进行对话。 看看它的结果: 哇靠,写的水平可以呀。我假装看不懂。让他给我在上面加一些注释吧。 这时它

    2024年02月08日
    浏览(48)
  • 小程序 微信开发者工具没有 云开发 选项(已解决)

    好久没登小程序,进去都看不到云开发选项,在网上都没有看到解决办法。下面贴图告诉大家 1.首先进入网页-微信公众平台。在小程序功能模块中找到APPID,  2.然后打开微信开发者工具,像我一样的,没有云开发选项 ,进入不了云开发控制台   3.点击左上角第一个按钮-项

    2024年02月16日
    浏览(31)
  • 测试工具Jmeter:界面介绍、核心选项说明、核心选项用途

    本文章主要介绍Jmeter的界面布局,以及各个选项的功能和它们的用途。 JMeter基本原理是建立一个线程池,多线程运行取样器产生大量负载,在运行过程中通过断言来验证结果的正确性,通过监听器来记录测试结果。 当我们打开Jmeter,首先映入眼帘的是以下界面: Jmeter主界面

    2024年02月03日
    浏览(33)
  • Java、Python、C++和C#的界面开发框架和工具的重新介绍

    好的,以下是Java、Python、C++和C#的界面开发框架和工具的重新介绍: Java界面开发: Swing: 是Java提供的一个基于组件的GUI工具包,可以创建跨平台的图形用户界面。它提供了丰富的组件和布局管理器,使得界面开发相对简单。Swing是Java AWT的继承者,支持更多的功能和外观。

    2024年02月02日
    浏览(31)
  • .NET / C# 开发 Ubuntu Desktop 跨平台图形界面桌面程序 Avalonia - Visual Studio 安装/创建/运行指南 (一)

    Avalonia 是一个开源的跨平台应用程序框架,用于构建桌面应用程序。它使用 C# 和 XAML 进行开发,可以在 Windows、macOS、iOS、Android 及 Linux 等多个平台上运行。Avalonia 项目地址:https://github.com/AvaloniaUI/Avalonia 本文快速介绍如何入门使用 Avalonia 编写和执行 Ubuntu Desktop 图形界面桌面

    2024年02月01日
    浏览(49)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包