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 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的含义为获取用于制造当前部件的表面积,下面是官方的具体解释:

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

相关推荐
今天背单词了吗9802 分钟前
算法学习笔记:7.Dijkstra 算法——从原理到实战,涵盖 LeetCode 与考研 408 例题
java·开发语言·数据结构·笔记·算法
Eiceblue4 分钟前
使用 C# 发送电子邮件(支持普通文本、HTML 和附件)
开发语言·c#·html·visual studio
小小小小王王王9 分钟前
hello判断
开发语言·c#
苦夏木禾1 小时前
js请求避免缓存的三种方式
开发语言·javascript·缓存
超级土豆粉1 小时前
Turndown.js: 优雅地将 HTML 转换为 Markdown
开发语言·javascript·html
金增辉2 小时前
基于C#的OPCServer应用开发,引用WtOPCSvr.dll
c#
wei_shuo2 小时前
飞算 JavaAI 开发助手:深度学习驱动下的 Java 全链路智能开发新范式
java·开发语言·飞算javaai
熊猫钓鱼>_>2 小时前
用Python解锁图像处理之力:从基础到智能应用的深度探索
开发语言·图像处理·python
GO兔3 小时前
开篇:GORM入门——Go语言的ORM王者
开发语言·后端·golang·go
好开心啊没烦恼3 小时前
Python 数据分析:numpy,抽提,整数数组索引与基本索引扩展(元组传参)。听故事学知识点怎么这么容易?
开发语言·人工智能·python·数据挖掘·数据分析·numpy·pandas