C# Solidworks二次开发:获取模型、组件、主体的表面积相关API详解

devtools/2024/10/18 18:23:14/

大家好,今天要介绍模型、组件、主体的表面积相关API。

下面是今天要介绍的API:

(1)第一个为SurfaceArea Property (IMassProperty),这个API的含义为获取此模型的表面积,下面是官方的具体解释:

其没有输入参数值,返回值为表面积。

下面是官方使用的例子:

This example shows how to get and override some mass properties of a part.

// -----------------------------------------------------------------------

// Preconditions:

// 1. Ensure the specified document exists.

// 2. Open the Immediate window.

//

// Postconditions: Inspect the Immediate window.

// ----------------------------------------------------------------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Forms;

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System.Diagnostics;

namespace MassProperty2_CSharp

{

        partial class SolidWorksMacro

        {

            private ModelDocExtension Extn;

            private MassProperty2 MyMassProp;

            private MassPropertyOverrideOptions OvProp;

            private ModelDoc2 swModelDoc;

            private double[] pmoi;

            private double[] vValue;

            private double[] value = new double[3];

            private int errors;

            private int warnings;

            private double val;

            public void Main()

            {

                swModelDoc = swApp.OpenDoc6(@"C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2019\samples\tutorial\advdrawings\98food processor.sldasm", (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);

                Extn = swModelDoc.Extension;

                // Create mass properties and override options

                MyMassProp = (MassProperty2)Extn.CreateMassProperty2();

                OvProp = (MassPropertyOverrideOptions)MyMassProp.GetOverrideOptions();

                OvProp.OverrideMass = true;

                OvProp.SetOverrideMassValue(100);

                double[] comArr = new double[9];

                comArr[0] = 0.1677;

                comArr[1] = 0;

                comArr[2] = 0;

                comArr[3] = 0;

                comArr[4] = 0.21358;

                comArr[5] = 0;

                comArr[6] = 0;

                comArr[7] = 0;

                comArr[8] = 0.34772;

                OvProp.OverrideMomentsOfInertia = true;

                OvProp.SetOverrideMomentsOfInertiaValue(0, comArr, "");

                // Use document property units (MKS)

                MyMassProp.UseSystemUnits = false;

                Debug.Print("Mass properties before override");

                Debug.Print("");

                val = MyMassProp.Mass;

                Debug.Print("Mass: " + val);

                val = MyMassProp.Volume;

                Debug.Print("Volume: " + val);

                val = MyMassProp.Density;

                Debug.Print("Density: " + val);

                val = MyMassProp.SurfaceArea;

                Debug.Print("Surface area: " + val);

                pmoi = (double[])MyMassProp.PrincipalMomentsOfInertia;

                Debug.Print("Principal moments of inertiae: Px: " + pmoi[0] + ", Py: " + pmoi[1] + ", and Pz: " + pmoi[2]);

                vValue = (double[])MyMassProp.GetMomentOfInertia(0);

                Debug.Print("Moments of inertia: Lxx: " + vValue[0] + ", Lxy: " + vValue[1] + ", Lxz: " + vValue[2] + ", Lyx: " + vValue[3] + ", Lyy: " + vValue[4] + ", Lyz: " + vValue[5] + ", Lzx: " + vValue[6] + ", Lzy: " + vValue[7] + ", Lzz: " + vValue[8]);

                MyMassProp.SetOverrideOptions(OvProp, (int)swInConfigurationOpts_e.swThisConfiguration, null);

                MyMassProp.Recalculate();

                Debug.Print("");

                Debug.Print("Mass properties after override");

                Debug.Print("");

                val = MyMassProp.Mass;

                Debug.Print("Mass: " + val);

                val = MyMassProp.Volume;

                Debug.Print("Volume: " + val);

                val = MyMassProp.Density;

                Debug.Print("Density: " + val);

                val = MyMassProp.SurfaceArea;

                Debug.Print("Surface area: " + val);

                pmoi = (double[])MyMassProp.PrincipalMomentsOfInertia;

                Debug.Print("Principal moments of inertia: Px: " + pmoi[0] + ", Py: " + pmoi[1] + ", and Pz: " + pmoi[2]);

                vValue = (double[])MyMassProp.GetMomentOfInertia(0);

                Debug.Print("Moments of inertia: Lxx: " + vValue[0] + ", Lxy: " + vValue[1] + ", Lxz: " + vValue[2] + ", Lyx: " + vValue[3] + ", Lyy: " + vValue[4] + ", Lyz: " + vValue[5] + ", Lzx: " + vValue[6] + ", Lzy: " + vValue[7] + ", Lzz: " + vValue[8]);

            }

            /// <summary>

            ///     ''' The SldWorks swApp variable is pre-assigned for you.

            ///     ''' </summary>

            public SldWorks swApp;

        }

    }

(2)第二个为SurfaceArea Property (IMassProperty2),这个API的含义为获取所选组件或主体的表面积,下面是官方的具体解释:

其没有输入参数值,返回值为表面积。

(3)第三个为SurfaceArea Property (ISustainabilityManufacturing),这个API的含义为获取用于制造当前部件的表面积,下面是官方的具体解释:

本篇文章要介绍的就是这么多,我们下篇文章再见。


http://www.ppmy.cn/devtools/14175.html

相关文章

阿斯达年代记三强争霸开服 游戏下载安装+账号注册教程一览

阿斯达年代记国际服是一款MMORPG手游&#xff0c;游戏支持自由交易是一款可以搬砖的游戏&#xff0c;游戏目前开放的4个职业&#xff0c;战士&#xff0c;弓箭手&#xff0c;祭司&#xff0c;斗士&#xff0c;其中战士是拉剑盾为主的职业&#xff0c;主T&#xff0c;由于这1款游…

Golang汇编之通过map地址找到value的值

文章目录 背景gdb调试Go程序为什么不用dlvgdb调试Go可执行程序gdb打印地址内容 go汇编快速入门常用的寄存器和用法AMD64ARM64loong64riscv64 Go汇编常用命令及含义Go汇编和x86的区别找到map的赋值指令 Go中map的内存布局gdb中查看map结构map的存储结构map的内存布局计算bmap偏移…

FTP与SMB深度对比:文件传输协议谁更胜一筹?

在数字化时代&#xff0c;文件传输已成为日常工作中不可或缺的一部分。 FTP&#xff08;文件传输协议&#xff09;和SMB&#xff08;服务器消息块&#xff09;是两种最为常见的文件传输协议。它们各自在文件传输领域拥有独特的优势和特点&#xff0c;但同时也存在一些差异。 今…

【Linux】进程优先级

&#x1f466;个人主页&#xff1a;Weraphael ✍&#x1f3fb;作者简介&#xff1a;目前正在学习c和算法 ✈️专栏&#xff1a;Linux &#x1f40b; 希望大家多多支持&#xff0c;咱一起进步&#xff01;&#x1f601; 如果文章有啥瑕疵&#xff0c;希望大佬指点一二 如果文章对…

k8s集群CD工具-ArgoCD

ArgoCD是什么 Argo CD 是 Kubernetes 的声明式 GitOps 持续交付工具。应用程序定义、配置和环境应该是声明性的和版本控制的。应用程序部署和生命周期管理应该是自动化的、可审计的且易于理解。 官方文档 CD工作流&#xff08;无ArgoCD&#xff09; 假设有一个微服务应用程序…

【服务器部署篇】Linux下Tomcat安装和配置

作者介绍&#xff1a;本人笔名姑苏老陈&#xff0c;从事JAVA开发工作十多年了&#xff0c;带过刚毕业的实习生&#xff0c;也带过技术团队。最近有个朋友的表弟&#xff0c;马上要大学毕业了&#xff0c;想从事JAVA开发工作&#xff0c;但不知道从何处入手。于是&#xff0c;产…

vue:write-excel-file页面文字转为xlsx文件

需求&#xff1a;导出弹框内容全部数据&#xff0c;通常这种前端拿到全部数据的情况下做出的导出&#xff0c;无需跟分页列表一样向接口发起请求 实现&#xff1a;点击跳转github了解write-excel-file 下面说说vue3ts项目中引入write-excel-file 1-安装引入 npm install w…

用wps自带工具给图片做标注

在wps中&#xff0c;选中wps中的图片&#xff0c;右键选择【编辑】进入图片编辑器&#xff0c;在选项卡面板右侧选择【标注】工具&#xff0c;再选择【添加文本】工具&#xff0c;即可直接在图片上输入文字&#xff0c;标注完成后选择【覆盖原图】就完成标注任务。