C# Solidworks二次开发:模型中实体Entity相关操作API详解

news2025/2/7 1:49:43

大家好,今天要讲的一些API是关于实体的相关API。

在开发的过程,很多地方会涉及到实体的相关操作,比如通过实体选中节点。下面就直接开始介绍API:

(1)第一个API为Select4,这个API的含义为选中一个实体,下面是API的官方解释:

输入参数有两个,第一个为ISelectData,第二个为布尔值。

返回值只有一个,成功选中会返回true,失败会返回false。

下面是官方使用的例子:

This example shows how to get data for an offset surface.

//----------------------------------------------------------------------
// Preconditions:
// 1. Open an assembly document that contains a component that
//    has a surface offset feature.
// 2. Select the component's surface offset feature.
// 3. Open the Immediate window.
//
// Postconditions: Inspect the Immediate window.
//----------------------------------------------------------------------


using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace AnalyzeOffsetSurface_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            SelectionMgr swSelMgr = default(SelectionMgr);
            SelectData swSelData = default(SelectData);
            SurfaceOffsetFeatureData swOffset = default(SurfaceOffsetFeatureData);
            Feature swFeat = default(Feature);
            Entity swEnt = default(Entity);
            object[] vFace = null;
            int i = 0;
            bool bRet = false;
            Component2 comp = default(Component2);
            Component2 swCompFace = default(Component2);

            swModel = (ModelDoc2)swApp.ActiveDoc;
            swSelMgr = (SelectionMgr)swModel.SelectionManager;
            swSelData = (SelectData)swSelMgr.CreateSelectData();
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swOffset = (SurfaceOffsetFeatureData)swFeat.GetDefinition();
            comp = (Component2)swSelMgr.GetSelectedObjectsComponent3(1, -1);

            Debug.Print("File = " + swModel.GetPathName());
            Debug.Print("CompFeature = " + comp.Name2);
            Debug.Print("  " + swFeat.Name);
            Debug.Print("    Distance       = " + swOffset.Distance * 1000.0 + " mm");
            Debug.Print("    Flip           = " + swOffset.Flip);
            Debug.Print("    FacesCount     = " + swOffset.GetEntitiesCount());

            bRet = swOffset.AccessSelections(swModel, comp);

            swModel.ClearSelection2(true);

            vFace = (object[])swOffset.Entities;

            for (i = 0; i <= vFace.GetUpperBound(0); i++)
            {
                swEnt = (Entity)vFace[i];
 

                                Debug.Print(" Entity selected = " + swEnt.Select4(true, null));


                swCompFace = (Component2)swEnt.GetComponent();
                Debug.Print("    Component face = " + swCompFace.Name2);

            }

            swOffset.ReleaseSelectionAccess();

        }

        public SldWorks swApp;

    }
}

(2)第二个为GetType,这个API的含义为获取实体的类型,下面是API的具体解释:

方法没有输入值,返回值为这个实体的类型swSelectType_e。

下面是官方的例子:

This example shows how to get a component from an assembly feature.

//-----------------------------------------------------------------------------
// Preconditions:
// 1. Open an assembly document with at least one component.
// 2. Select a feature in a component in the FeatureManager design tree.
//
// Postconditions: Inspect the Immediate window.
//----------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace GetComponentFromFeature_CSharp.csproj
{
    partial class SolidWorksMacro
    {

        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            Feature swFeature = default(Feature);
            Entity swEntity = default(Entity);
            bool bValue = false;
            Component2 swComponent = default(Component2);

            // Get active document
            swModel = (ModelDoc2)swApp.ActiveDoc;

            // Check the document is an assembly
            if ((swModel.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY))
            {
                return;
            }

            // Get the feature
            swFeature = (Feature)((SelectionMgr)(swModel.SelectionManager)).GetSelectedObject6(1, -1);

            // Cast the feature to an entity
            swEntity = (Entity)swFeature;

            // Get type through entity interface
            Debug.Print("Entity type as defined in swSelectType_e: " + swEntity.GetType());
            Debug.Assert(swEntity.GetType() == (int)swSelectType_e.swSelBODYFEATURES);

            // Get type through feature interface
            // Feature inherits from Entity, so will actually call Entity::GetType
            Debug.Print("Entity type: " + swFeature.GetType());

            // Get the component for the entity
            swComponent = (Component2)swEntity.GetComponent();

            // Print component details
            Debug.Print(swComponent.Name2);
            Debug.Print("  " + swComponent.GetPathName());

            // Clear the selection lists
            swModel.ClearSelection2(true);

            // Select the feature through the Entity interface
            bValue = swEntity.Select4(false, null);

            // Print the type of the selected object
            Debug.Print("Selected object type as defined in swSelectType_e: " + ((SelectionMgr)(swModel.SelectionManager)).GetSelectedObjectType3(1, -1));
            Debug.Assert(((SelectionMgr)(swModel.SelectionManager)).GetSelectedObjectType3(1, -1) == (int)swSelectType_e.swSelBODYFEATURES);

            // Clear the selection lists
            swModel.ClearSelection2(true);

            // Select the feature through the Feature interface
            bValue = swFeature.Select2(false, 0);

            // Print the type of the selected object
            Debug.Print("Selected object type as defined in swSelectType_e: " + ((SelectionMgr)(swModel.SelectionManager)).GetSelectedObjectType3(1, -1));
            Debug.Assert(((SelectionMgr)(swModel.SelectionManager)).GetSelectedObjectType3(1, -1) == (int)swSelectType_e.swSelBODYFEATURES);

        }

        public SldWorks swApp;

    }
}

(3)第三个为FindAttribute,这个API的含义为查找实体上的属性,下面是API的具体解释:

参数的输入值有两个,第一个为要查找的属性,第二个为此实体上的类型实例。

今天要介绍的就是上面这三种API,本篇文章到此结束,我们下篇文章再见。

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

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

相关文章

工业物联网让“制造”变成“智造”!——青创智通

工业物联网解决方案-工业IOT-青创智通 随着科技的不断进步和工业的持续发展&#xff0c;物联网&#xff08;IoT&#xff09;技术的出现为制造业带来了前所未有的变革。工业物联网&#xff08;IIoT&#xff09;作为物联网技术在工业领域的应用&#xff0c;正在逐渐改变传统的制…

JavaScript:使用color-convert实现颜色色值转换

color-convert支持如下颜色格式的转换&#xff1a; rgb, hsl, hsv, hwb, cmyk, ansi, ansi16, hex文档 https://www.npmjs.com/package/color-converthttps://github.com/Qix-/color-convert 安装 $ npm install color-convert使用示例 import convert from color-convert…

深入理解Mesh Shader优化原理

参照AMD官网文章和GDC中其分享内容https://gpuopen.com/learn/mesh_shaders/mesh_shaders-index/总结自用&#xff0c;大佬直接原文。 一、传统顶点着色器管线与Mesh 着色器对比 具体之前也研究过可参照&#xff1a;DX12_Mesh Shaders Render 这里主要针对之前忽略的一些知识…

[BT]BUUCTF刷题第17天(4.15)

第17天&#xff08;共3题&#xff09; Web [强网杯 2019]高明的黑客 .tar.gz 是 Linux 系统下的压缩包&#xff0c;访问即可下载 打开后有3000多个php文件&#xff0c;通过题解得知需要写Python脚本找出合适的GetShell文件&#xff08;因为每个文件里都会通过system函数执行…

贵阳市人民政府副市长刘岚调研珈和科技

4月9日&#xff0c;贵阳市人民政府副市长、党组成员刘岚一行到珈和科技走访调研&#xff0c;珈和科技总经理冷伟热情接待了考察团&#xff0c;就企业算力需求与合作&#xff0c;特色产业园区建设&#xff0c;科技成果转化落地等方面进行深入交流。 贵阳市教育局局长李波&#…

Vmware 虚拟机自定义IP地址 - UbuntuServer2204

Vmware 虚拟机自定义IP地址 - UbuntuServer2204 设置网段 选择喜欢的网段&#xff0c; 例如&#xff1a; 166 自定义 IP地址 打开虚拟机&#xff0c; 输入命令查看网卡名 ip addr查看网卡配置文件 ls -al /etc/netplan/编辑网卡配置文件 sudo vim /etc/netplan/00-installe…

稀疏数组思想

稀疏数组的处理方法是&#xff1a; 1)记录数组一共有几行几列&#xff0c;有多少个不同的值 2)思想&#xff1a;把具有不同值的元素的行列及值记录在一个小规模的数组中&#xff0c;从而缩小程序的规模 例如下面原数组对应稀疏数组&#xff1a;

Git-常规用法-含解决分支版本冲突解决方法

目录 前置条件 已经创建了Gitee账号 创建一个远程仓库 Git的优点 版本控制 Git 下载 Git的使用 检查Git的是否安装成功 git的常用命令 常用流程 Git 分支 分支流程 Git 远程仓库 远程仓库流程 特殊 可能遇到的问题 前置条件 已经创建了Gitee账号 创建一个远程仓…

CTK插件框架学习-事件监听(07)

CTK插件框架学习-服务工厂(06)https://mp.csdn.net/mp_blog/creation/editor/137295686 一、简介 事件监听指当事件发生变化时所产生的通信&#xff0c;是动态的&#xff0c;对于已经发生过的事件无法监听 二、事件类型 1、框架事件 监听框架状态变化&#xff0c;因为监听…

【ARFoundation自学01】搭建AR框架,检测平面点击位置克隆物体

Unity开发ARFoundation相关应用首先安装ARFoundation包 然后设置XR 1.基础AR场景框架搭建 2.一个基本的点击克隆物体到识别的平面脚本 挂在XROrigin上 脚本AppController 脚本说明书 ## 业务逻辑 AppController 脚本旨在实现一个基本的 AR 应用程序功能&#xff1a;用户通过…

【24年物联网华为杯】赛题分析与初步计划

赛事介绍 官网链接&#xff1a;2024 年全国大学生物联网设计竞赛 (sjtu.edu.cn) 含金量&#xff1a;属于A类赛事 &#xff08;注意&#xff1a;很多搜索结果的序号是按照选入时间排列的&#xff0c;与含金量无关&#xff0c;华为杯是23年选入的&#xff09; Kimi Chat: 全国…

攻防世界09cookie

9-cookie Cookie是保存在客户端的纯文本文件。比如txt文件。所谓的客户端就是我们自己的本地电脑。当我们使用自己的电脑通过浏览器进行访问网页的时候&#xff0c;服务器就会生成一个证书并返回给我的浏览器并写入我们的本地电脑。这个证书就是cookie。一般来说cookie都是服务…

数字孪生技术在设备故障检测中的应用

数字孪生技术在设备故障检测中的应用主要体现在以下几个方面&#xff0c;数字孪生技术在设备故障检测中的应用展现了其在智能制造和工业互联网领域的重要价值&#xff0c;通过实时监测、故障预测、诊断分析和预测性维护等手段&#xff0c;显著提升了设备管理的智能化水平。北京…

CAN终端电阻

目录 概述终端电阻的作用提高抗干扰能力确保快速进入隐性状态提高信号质量 为什么选120Ω 概述 CAN总线终端电阻&#xff0c;顾名思义就是加在总线末端的电阻。此电阻虽小&#xff0c;但在CAN总线通信中却有十分重要的作用。 终端电阻的作用 CAN总线终端电阻的作用有两个&…

轻松上手MYSQL:MYSQL初识(下)

​&#x1f308; 个人主页&#xff1a;danci_ &#x1f525; 系列专栏&#xff1a;《MYSQL入门》 &#x1f4aa;&#x1f3fb; 制定明确可量化的目标&#xff0c;坚持默默的做事。 轻松上手MYSQL&#xff1a;从零开始构建你的数据库世界 &#x1f680; &#x1f680;欢迎来到My…

office竟然可以直接PDF转Word?这个“锅”请wps来背!

WPS和Office都是非常出色的办公软件&#xff0c;它们都能够满足我们日常办公的需求。然而&#xff0c;作为一款国产办公软件&#xff0c;WPS在功能集成和操作上更加符合中国人的使用习惯&#xff0c;因此很多人选择使用WPS作为他们的办公软件&#xff0c;包括我自己。 然而&…

初识微服务:重塑软件开发的未来

引言 随着信息技术的飞速发展&#xff0c;软件系统的复杂性和规模不断攀升&#xff0c;传统的单体应用架构已经难以满足现代业务的灵活性和可扩展性需求。在这样的背景下&#xff0c;微服务架构应运而生&#xff0c;成为当前软件开发领域的一大热门话题。本文将深入探讨微服务架…

LeetCode 73.矩阵置零————2024 春招冲刺百题计划

给定一个 m x n 的矩阵&#xff0c;如果一个元素为 0 &#xff0c;则将其所在行和列的所有元素都设为 0 。请使用 原地 算法。 输入&#xff1a;matrix [[1,1,1],[1,0,1],[1,1,1]] 输出&#xff1a;[[1,0,1],[0,0,0],[1,0,1]] 示例 2&#xff1a; 输入&#xff1a;matrix […

解决EasyPoi导入Excel获取不到第一列的问题

文章目录 1. 复现错误2. 分析错误2.1 导入的代码2.2 DictExcel实体类2.2 表头和标题 3. 解决问题 1. 复现错误 使用EasyPoi导入数据时&#xff0c;Excel表格如下图&#xff1a; 但在导入时&#xff0c;出现如下错误&#xff1a; name为英文名称&#xff0c;在第一列&#xff0c…

0-1 设计高质量数据可视化大屏

5 大指南塑造高阶可视化 可视化是个友好的媒介 理解数据是成为优秀媒介的关键 业务驱动下的设计策略 图扑设计的无限可能 创新思维让可视化更具价值 可视化是个友好的媒介 我们正处于一个数据泛滥的时代&#xff0c;随处可见数据的身影&#xff0c;更知其不可忽视的重要…