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

大家好,今天要介绍模型、组件、主体的表面积相关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 double3;

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 double9;

comArr0 = 0.1677;

comArr1 = 0;

comArr2 = 0;

comArr3 = 0;

comArr4 = 0.21358;

comArr5 = 0;

comArr6 = 0;

comArr7 = 0;

comArr8 = 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: " + pmoi0 + ", Py: " + pmoi1 + ", and Pz: " + pmoi2);

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

Debug.Print("Moments of inertia: Lxx: " + vValue0 + ", Lxy: " + vValue1 + ", Lxz: " + vValue2 + ", Lyx: " + vValue3 + ", Lyy: " + vValue4 + ", Lyz: " + vValue5 + ", Lzx: " + vValue6 + ", Lzy: " + vValue7 + ", Lzz: " + vValue8);

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: " + pmoi0 + ", Py: " + pmoi1 + ", and Pz: " + pmoi2);

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

Debug.Print("Moments of inertia: Lxx: " + vValue0 + ", Lxy: " + vValue1 + ", Lxz: " + vValue2 + ", Lyx: " + vValue3 + ", Lyy: " + vValue4 + ", Lyz: " + vValue5 + ", Lzx: " + vValue6 + ", Lzy: " + vValue7 + ", Lzz: " + vValue8);

}

/// <summary>

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

/// ''' </summary>

public SldWorks swApp;

}

}

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

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

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

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

相关推荐
曹牧16 分钟前
C#:Type
开发语言·c#
小僧景贤1 小时前
嵌入式C语言 第十一篇:成长路线|嵌入式C工程师完整进阶学习路径(从零到工程级落地|含周期+实战项目)
c语言·开发语言·学习
Brilliantwxx1 小时前
【Linux】自动化构建工具 make 与 Makefile
linux·运维·服务器·开发语言·自动化
用户3721574261351 小时前
C# 如何在 Excel 中创建下拉列表:3 种常见数据源实现方式
c#
灵晔君1 小时前
【Linux】进程(四)——进程虚拟地址空间
linux·c语言·开发语言
萧瑟余晖1 小时前
Java深入解析篇十八之响应式编程
java·开发语言
看浪的路人1 小时前
第5讲:代码审查与 Bug 检测
开发语言·windows·python
netccdn1 小时前
Hough变换检测直线(Matlab)
开发语言·计算机视觉·matlab
有点。1 小时前
C++深度优先搜索(三)
开发语言·c++·深度优先
天空'之城1 小时前
C 语言工业级通用组件手写 25:简易日志系统
c语言·开发语言·日志系统·嵌入式调试·调试打印