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

大家好,今天要讲的一些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.mzph.cn/news/811739.shtml

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

相关文章

微信小程序中调取小程序实现报错:提示 开发版小程序已过期,请在开发者工具中重新扫码的 解决方案

出现的问题&#xff1a; 解决方法&#xff1a; 将envVersion: develop,开发版切换为正式版 envVersion: release,wx.navigateToMiniProgram({appId:res.data.appId,path: res.data.prePayTn,extraData: {foo: bar,miniProgramOrgId:res.data.miniProgramOrgId,orderId: res.d…

css设置文字撑满盒子

效果如上&#xff1a; <div style"width: 250px;background-color:red;text-align-last:justify;word-break: keep-all;">为中国崛起而读书</div>

Objective-C网络请求开发的高效实现方法与技巧

前言 在移动应用开发中&#xff0c;网络请求是一项至关重要的技术。Objective-C作为iOS平台的主要开发语言之一&#xff0c;拥有丰富的网络请求开发工具和技术。本文将介绍如何利用Objective-C语言实现高效的网络请求&#xff0c;以及一些实用的技巧和方法。 1.Objective-C技…

以太坊源码阅读01

正所谓区块链&#xff0c;怎能不熟悉区块的数据结构呢&#xff1f;区块的结构体被保存在core/types/block.go文件中&#xff0c;下面是我截取出来的&#xff1a; type Block struct {header *Headeruncles []*Headertransactions Transactionswithdrawals Withdr…

干货分享|TensorFlow构建神经网络

MNIST数据集前面章节已经多次遇到过&#xff0c;这里直接引用&#xff0c;并使用TensorFlow构建神经网络模型进行训练。下面举例说明如何构建简单的神经网络并训练。 【例15-33】 TensorFlow构建神经网络训练MNIST数据集。 输入如下代码&#xff1a; # 构建简单模型&#xf…

蓝桥杯单片机超声波示例通常涉及使用超声波模块进行测距。下面是一个基于51单片机的超声波测距示例代码:

蓝桥杯单片机超声波示例通常涉及使用超声波模块进行测距。下面是一个基于51单片机的超声波测距示例代码&#xff1a; #include <reg52.h> #include <intrins.h>sbit Trig P1^0; // 定义超声波发送引脚 sbit Echo P1^1; // 定义超声波接收引脚unsigned int Tim…

进程线程的关系

举个例子 滑稽老师吃100只鸡 如何加快滑稽老师吃鸡的效率&#xff1f;&#xff1f; 有一个方案&#xff0c;搞两个房间&#xff0c;两个滑稽老师 一个滑稽吃50只鸡&#xff0c;速度一定会大幅度增加 多进程的方案 创建新的进程 就需要申请更多的资源&#xff08;房间和…

Python编写一个抽奖小程序,新手入门案例,简单易上手!

“ 本篇文章将以简明易懂的方式引导小白通过Python编写一个简单的抽奖小程序&#xff0c;无需太多的编程经验。通过本文&#xff0c;将学习如何使用Python内置的随机模块实现随机抽奖&#xff0c;以及如何利用列表等基本数据结构来管理和操作参与抽奖的人员名单。无论你是Pytho…

贪心算法:柠檬水找零

题目链接&#xff1a;860. 柠檬水找零 - 力扣&#xff08;LeetCode&#xff09; 收的钱只能是5、10、20美元&#xff0c;分类讨论&#xff1a;收5美元无需找零&#xff1b;收10美元找零5元&#xff1b;收20美元找零15美元。其中对于找零15美元的方案有两种&#xff0c;此处涉及…

mysqlySQL中启用慢查询日志并设置阈值

要在MySQL中启用慢查询日志并设置阈值&#xff0c;可以按照以下步骤进行&#xff1a; 编辑MySQL配置文件&#xff1a;打开MySQL的配置文件&#xff08;通常是my.cnf或my.ini&#xff09;&#xff0c;在[mysqld]部分添加或修改以下行来启用慢查询日志并设置阈值&#xff1a; s…

一种基于镜像指示位办法的RingBuffer实现,解决Mirror和2的幂个数限制

简介 在嵌入式开发中&#xff0c;经常有需要用到RingBuffer的概念&#xff0c;在RingBuffer中经常遇到一个Buffer满和Buffer空的判断的问题&#xff0c;一般的做法是留一个单位的buffer不用&#xff0c;这样做最省事&#xff0c;但是当RingBuffer单位是一个结构体时&#xff0…

设计模式-外观模式(Facade)

1. 概念 外观模式&#xff08;Facade Pattern&#xff09;是一种结构型设计模式&#xff0c;它提供了一个统一的接口&#xff0c;用于访问子系统中的一群接口。外观模式的主要目的是隐藏系统的复杂性&#xff0c;通过定义一个高层级的接口&#xff0c;使得子系统更容易被使用。…

房屋鉴定研究院报告系统

一、项目背景与意义 随着城市化进程的加速和房地产市场的蓬勃发展&#xff0c;房屋安全问题日益受到社会各界的广泛关注。房屋鉴定作为确保房屋安全的重要手段&#xff0c;对于保障人民群众生命财产安全、维护社会稳定具有重要意义。然而&#xff0c;传统的房屋鉴定方式存在诸…

webpack-loader的使用

引入css后执行打包命令 "build": "npx webpack --config wk.config.js"发现报错&#xff1a; webpack默认只能处理js其他的像css,图片都需要借助loader来处理 css-loader loader可以用于对模块的源代码进行转换&#xff0c;可以把css看成一个模块&…

AWS被误扣费了,怎么解决?

有时在使用aws时&#xff0c;可能会无意中被AWS扣费&#xff0c;对于如何处理这个问题&#xff0c;作为aws的合作伙伴&#xff0c;接下来由九河云进行讲解&#xff1a; &#xff08;1&#xff09;审查账单&#xff1a;首先&#xff0c;您需要仔细审查AWS账单&#xff0c;了解具…

并发学习27--多线程 Tomcat 线程池

Tomcat连接器的线程池 socketProcessor也是个线程 Executor处理线程是按照JDK线程池方法处理&#xff0c;优先选用核心线程&#xff0c;再用救急线程&#xff0c;再去阻塞队列&#xff0c;最后采用拒绝策略。 Tomcat线程池与ThreadExecutorPool的区别 Tomcat中的配置 Tomcat …

kafka快速入门+应用

Kafka, 构建TB级异步消息系统 1.快速入门 1.1 阻塞队列 在生产线程 和 消费线程 之间起到了 &#xff0c; 缓冲作用&#xff0c;即避免CPU 资源被浪费掉 BlockingQueue 解决 线程通信 的问题阻塞方法 put 、 take生产者、消费者 模式 生产者&#xff1a;产生数据的线程…

登录加载动画

实现登录中 … 三个点的loading动画 <template><div><el-input type"password" placeholder"请填写密码" autocomplete"new-password"v-model"password" keyup.enter.native"login" show-password clearable…

Word中图表题注样式自动编号

需求 在写论文的时候&#xff0c;希望图表题注是下面的样子&#xff0c;其中图号表示为&#xff1a;章的编号-本章中图的序号&#xff0c;而且都是小写数字。 网上找的方法大多是使用 “插入题注” 来插入&#xff0c;此时章的编号是大写的&#xff0c;如“图一-1”。然后再通…

后台权限控制及动态路由

需求 后台系统需要能实现不同的用户权限可以看到不同的功能。 用户只能使用他的权限所允许使用的功能。 功能设计 之前在我的SpringSecurity的课程中就介绍过RBAC权限模型。没有学习过的可以去看下 RBAC权限模型 。这里我们就是在RBAC权限模型的基础上去实现这个功能。 表分…