C# Solidworks二次开发:访问平面、曲面相关API详解

大家好,今天要介绍的是关于平面、曲面相关的API。

下面是相关的API:

(1)第一个为ISurfacePlanarFeatureData,这个API的含义为允许访问平面表面特征,下面是官方的具体解释:

下面是官方使用的例子:

This example shows how to create a planar surface feature.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified document template exists.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates a new model document with a boss extrusion.
// 2. Creates Surface-Radiate1 and Surface-Plane1 in the FeatureManager
//    design tree.
// 3. 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 CreateSurfacePlaneFeature_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        SelectionMgr swSelMgr;
        SelectData swSelData;
        SurfaceRadiateFeatureData swRadiate;
        SurfacePlanarFeatureData swPlane;
        Feature swFeat;
        Entity swEnt;
        object[] vRadEnt;
        object[] vBoundEnt;
        Entity swRadDirEnt;
        int i;
 
        bool boolStatus;
 
        public void Main()
        {
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2015\\templates\\Part.prtdot", 0, 0, 0);
            Part = (ModelDoc2)swApp.ActiveDoc;
 
            boolStatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.0448901407839529, 0.0279954694016864, 0.00466820674117181, false, 0, null, 0);
            Part.SketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            boolStatus = Part.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
            boolStatus = Part.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
            object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0555749908365768, 0.0329075527136081, 0, 0.0478203409524033, -0.0317145296545045, 0);
            Part.ClearSelection2(true);
            Part.SketchManager.InsertSketch(true);
            Part.ShowNamedView2("*Trimetric", 8);
            Part.SketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            boolStatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 4, null, 0);
 
            object myFeature = null;
            myFeature = Part.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, 0.00254, 0.00254, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            0, 0, false);
 
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0447337592343047, 0.0328467250718631, 0.00258132540182032, false, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0556265649287866, 0.0156695101210289, 0.0025672149453726, true, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0140113588298618, -0.0317157034173761, 0.00254079743683633, true, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", 0.047780958393389, -0.00542256709667299, 0.00256078163948814, true, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "FACE", 0.0478203409524554, -0.00305747564971171, 0.000546558985774936, true, 1, null, 0);
 
            Part.InsertRadiateSurface(0.0254, false, false);
 
            swSelMgr = (SelectionMgr)Part.SelectionManager;
            swSelData = swSelMgr.CreateSelectData();
 
            boolStatus = Part.Extension.SelectByID2("Surface-Radiate1", "REFSURFACE", 0, 0, 0, false, 0, null, 0);
 
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swRadiate = (SurfaceRadiateFeatureData)swFeat.GetDefinition();
 
            // Get radiate surface data
            Debug.Print("File = " + Part.GetPathName());
            Debug.Print("  " + swFeat.Name);
            Debug.Print("    Distance: " + swRadiate.Distance * 1000.0 + " mm");
            Debug.Print("    Flip? " + swRadiate.Flip);
            Debug.Print("    Propagate to tangent faces? " + swRadiate.PropagateToTangentFaces);
 
            // Roll back to get direction reference and radiated edges
            boolStatus = swRadiate.AccessSelections(Part, null);
            swRadDirEnt = (Entity)swRadiate.DirectionReference;
            Part.ClearSelection2(true);
 
            vRadEnt = (object[])swRadiate.RadiatedEntities;
 
 
            Debug.Print("Type as defined in swSelectType_e:");
            for (i = 0; i <= swRadiate.GetRadiatedEntitiesCount() - 1; i++)
            {
                swEnt = (Entity)vRadEnt[i];
                Debug.Print("    Radiated Entity(" + i + ") = " + swEnt.GetType());
 
            }
 
            swRadiate.ReleaseSelectionAccess();
 
            Part.ClearSelection2(true);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0150796523155918, 0.0330635737250304, 0.0277193529692568, false, 1, null, 0);
    boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0556924155575302, -0.00146678127401856, 0.0280574247206573, true, 1, null, 0);
    boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.00737846281163002, -0.0317262656324715, 0.0279565971788429, true, 1, null, 0);
    boolStatus = Part.Extension.SelectByID2("", "EDGE", 0.047950275020753, 0.00971418585908168, 0.0278100659315328, true, 1, null, 0);
 
    boolStatus = Part.InsertPlanarRefSurface();
    Part.ClearSelection2(true);
 
    boolStatus = Part.Extension.SelectByID2("Surface-Plane1", "REFSURFACE", 0, 0, 0, false, 0, null, 0);
 
    // Roll back to get the planar surface bounding edges
    swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
    swPlane = (SurfacePlanarFeatureData)swFeat.GetDefinition();
 
    boolStatus = swPlane.AccessSelections(Part, null);
    vBoundEnt = (object[])swPlane.BoundingEntities;
 
    Debug.Print("Types of planar surface bounding entities as defined in swSelectType_e:");
 
    for (i = 0; i <= swPlane.GetBoundingEntitiesCount() - 1; i++) {
swEnt = (Entity)vBoundEnt[i];
Debug.Print("    Bounding entity(" + i + ") = " + swEnt.GetType());
 
    }
 
    swPlane.ReleaseSelectionAccess();
 
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
}

(2)第二个为ISurfaceRadiateFeatureData,这个API的含义为允许访问表面辐射功能,下面是官方的具体解释:

下面是官方使用的例子:

This example shows how to create a radiate surface feature.

//----------------------------------------------------------------------------
// Preconditions:
// 1. Verify that the specified document template exists.
// 2. Open an Immediate window.
//
// Postconditions:
// 1. Creates a new model document with a feature extrusion.
// 2. Creates Boss-Extrude1 and Surface-Radiate1 in the graphics area and
//    FeatureManager design tree.
// 3. 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 CreateSurfRadiateFeat_CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        ModelDoc2 Part;
        SelectionMgr swSelMgr;
        SelectData swSelData;
        SurfaceRadiateFeatureData swRadiate;
        Feature swFeat;
        Entity swEnt;
        object[] vRadEnt;
        Entity swRadDirEnt;
        int i;
 
        bool boolStatus;
 
        public void Main()
        {
            Part = (ModelDoc2)swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SOLIDWORKS 2015\\templates\\Part.prtdot", 0, 0, 0);
            Part = (ModelDoc2)swApp.ActiveDoc;
 
            boolStatus = Part.Extension.SelectByID2("Front Plane", "PLANE", -0.0448901407839529, 0.0279954694016864, 0.00466820674117181, false, 0, null, 0);
            Part.SketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            boolStatus = Part.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstToRectEntity, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, false);
            boolStatus = Part.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swSketchAddConstLineDiagonalType, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, true);
            object vSkLines = null;
            vSkLines = Part.SketchManager.CreateCornerRectangle(-0.0555749908365768, 0.0329075527136081, 0, 0.0478203409524033, -0.0317145296545045, 0);
            Part.ClearSelection2(true);
            Part.SketchManager.InsertSketch(true);
            Part.ShowNamedView2("*Trimetric", 8);
            Part.SketchManager.InsertSketch(true);
            Part.ClearSelection2(true);
            boolStatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, false, 4, null, 0);
 
            object myFeature = null;
            myFeature = Part.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, 0.00254, 0.00254, false, false, false,
            false, 0.0174532925199433, 0.0174532925199433, false, false, false, false, true, true, true,
            0, 0, false);
 
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0447337592343047, 0.0328467250718631, 0.00258132540182032, false, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0556265649287866, 0.0156695101210289, 0.0025672149453726, true, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", -0.0140113588298618, -0.0317157034173761, 0.00254079743683633, true, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "EDGE", 0.047780958393389, -0.00542256709667299, 0.00256078163948814, true, 2, null, 0);
            boolStatus = Part.Extension.SelectByID2("", "FACE", 0.0478203409524554, -0.00305747564971171, 0.000546558985774936, true, 1, null, 0);
 
            Part.InsertRadiateSurface(0.0254, false, false);
 
            swSelMgr = (SelectionMgr)Part.SelectionManager;
            swSelData = swSelMgr.CreateSelectData();
 
            boolStatus = Part.Extension.SelectByID2("Surface-Radiate1", "REFSURFACE", 0, 0, 0, false, 0, null, 0);
 
            swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1);
            swRadiate = (SurfaceRadiateFeatureData)swFeat.GetDefinition();
 
            // Get radiate surface data
            Debug.Print("File = " + Part.GetPathName());
            Debug.Print("  " + swFeat.Name);
            Debug.Print("    Distance: " + swRadiate.Distance * 1000.0 + " mm");
            Debug.Print("    Flip? " + swRadiate.Flip);
            Debug.Print("    Propagate to tangent faces? " + swRadiate.PropagateToTangentFaces);
 
            // Roll back to get direction reference and radiated edges
            boolStatus = swRadiate.AccessSelections(Part, null);
            swRadDirEnt = (Entity)swRadiate.DirectionReference;
            Part.ClearSelection2(true);
 
            vRadEnt = (object[])swRadiate.RadiatedEntities;
 
 
            Debug.Print("Type as defined in swSelectType_e:");
            for (i = 0; i <= swRadiate.GetRadiatedEntitiesCount() - 1; i++)
            {
                swEnt = (Entity)vRadEnt[i];
                Debug.Print("    Radiated Entity(" + i + ") = " + swEnt.GetType());
 
            }
 
            swRadiate.ReleaseSelectionAccess();
 
 
        }
 
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
 
        public SldWorks swApp;
 
    }
}

(3)第三个为ISurfaceTrimFeatureData,这个API的含义为允许访问表面修剪功能,下面是官方具体解释:

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

 

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

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

相关文章

美国站群服务器的配置选择要点?

美国站群服务器的配置选择要点? 随着互联网的快速发展&#xff0c;站群已经成为许多网站主和企业选择的一种有效的网络推广方式。而在搭建站群时&#xff0c;选择适合的服务器配置是至关重要的。美国作为全球互联网技术的先锋之一&#xff0c;拥有先进的服务器设施和强大的网…

【 书生·浦语大模型实战营】作业(四):XTuner 微调 LLM:1.8B、多模态、Agent

【 书生浦语大模型实战营】作业&#xff08;五&#xff09;&#xff1a;LMDeploy 量化部署 &#x1f389;AI学习星球推荐&#xff1a; GoAI的学习社区 知识星球是一个致力于提供《机器学习 | 深度学习 | CV | NLP | 大模型 | 多模态 | AIGC 》各个最新AI方向综述、论文等成体系…

golang封装调用kafka的工具包

封装一个golang调用kafka的工具包&#xff0c;包含了consumer,producer,auth,在自己的生产环境上做过验证。可以做参考作用&#xff0c;也可以直接使用。 部分代码 // Run 执行消费动作 func (cg *ConsumerGroup) Run(ctx context.Context) {defer cg.close()for {select {ca…

Linux——(关于权限常见的3个问题)

文章目录 1.修改文件或者目录的拥有者和所属组1.1chown指令1.2chgrp指令 2.常见的权限三个问题2.1对应一个目录&#xff0c;如果要进入&#xff0c;需要什么权限&#xff1f;2.2为什么我们创建的文件默认权限不是7772.2.1关于Linux下的权限掩码 2.3文件能否被删除取决于什么2.3…

Beyond Chain-of-Thought: A Survey of Chain-of-X Paradigms for LLMs论文阅读笔记(未完待续)

地址&#xff1a;https://arxiv.org/html/2404.15676v1 一些论文合集&#xff1a;https://github.com/atfortes/Awesome-LLM-Reasoning 背景 思维链 &#xff08;Chain-of-Thought&#xff0c;CoT&#xff09; 是一种被广泛采用的提示方法&#xff0c;它激发了大型语言模型 …

《HCIP-openEuler实验指导手册》2.1安装和测试Nginx

知识点 Nginx (发音为 “engine x”) 是一个开源的高性能 HTTP 和反向代理服务器&#xff0c;也是一个 IMAP/POP3/SMTP 代理服务器。由 Igor Sysoev 创建并维护&#xff0c;其设计用于处理高并发连接&#xff0c;具有高度的可扩展性和灵活性。 安装步骤 yum方式安装 dn…

读书笔记--数据管理知识体系的阅读总结感悟

最近继续研读DAMA数据管理知识体系之数据管理章节,结合自身在应用系统建设、数据治理工作实践,有所感悟并记录如下,供大家参考。数据管理工作需要技术和非技术的双重技能,由业务人员和信息技术人员相互协作,共同来承担责任,确保组织管理的数据是高质量的,主要驱动力是使…

go语言实现简单ngnix样例

目录 1、代码实现样例&#xff1a; 2、postman调用ngnix&#xff0c;转发&#xff1a; 1、代码实现样例&#xff1a; package mainimport ("bytes""encoding/json""io""log""net/http""net/http/httputil""…

Chapter 1-17. Introduction to Congestion in Storage Networks

Q: Isn’t increasing network capacity the ultimate solution to network congestion? Increasing network capacity is the solution when a lack of network capacity is the root cause of congestion. There are many more reasons for network congestion and in thos…

ruoyi-nbcio-plus基于vue3的flowable收回任务后重新进行提交表单的处理

更多ruoyi-nbcio功能请看演示系统 gitee源代码地址 前后端代码&#xff1a; https://gitee.com/nbacheng/ruoyi-nbcio 演示地址&#xff1a;RuoYi-Nbcio后台管理系统 http://218.75.87.38:9666/ 更多nbcio-boot功能请看演示系统 gitee源代码地址 后端代码&#xff1a; h…

双目视觉(双目相机)

1.时间同步 需要一个单独的硬件&#xff08;单片机&#xff09;单独给每一个相机发送触发信息&#xff0c;然后再接收返回。 2.相机选型&#xff1a; &#xff08;1&#xff09;相机的分辨率 根据对图像精度的要求来选择相机的分辨率。 &#xff08;2&#xff09;颜色 通…

Python AI库 Pandas的常见操作的扩展知识

Python AI库 Pandas的常见操作的扩展知识 本文默认读者具备以下技能&#xff1a; 熟悉python基础知识&#xff0c;vscode或其它编辑工具 熟悉表格文件的基本操作 具备自主扩展学习能力 前文中对Pandas的数据结构以及基础操作做了介绍,本文中会在前文的基础上,对常见的操作进…

selenium拉动滚动条

selenium拉动滚动条 # 导包 from selenium import webdriver from time import sleep # 获取浏览器驱动对象 driver webdriver.Edge() # 最大化浏览器 driver.maximize_window() # 隐式等待 driver.implicitly_wait(30) # 打开url url r"C:\Users\黄永生\Desktop\软件测…

计算机找不到vcruntime140_1.dll,无法继续执行代码快速解决方法

vcruntime140_1.dll是一个重要的Windows操作系统中的动态链接库&#xff08;DLL&#xff09;文件&#xff0c;它是微软Visual C Redistributable软件包的组成部分。以下是该文件的详细介绍&#xff1a; 名称含义&#xff1a;“vcruntime”代表Visual C Runtime&#xff0c;表明…

static page 项目

static page 项目 作者&#xff1a;不染心 博客地址&#xff1a;https://blog.csdn.net/qq_38234785 源码地址&#xff1a;https://mbd.pub/o/bread/ZpWVlJps 未经允许&#xff0c;不得转载 文档版本v1&#xff0c;还没写完持续更新 一、引言 1. 软件概述和背景 本软件是…

STM32f103 HAL库读保护以及解除

读保护 void Flash_EnableReadProtection(void) {FLASH_OBProgramInitTypeDef OBInit;__HAL_FLASH_PREFETCH_BUFFER_DISABLE();HAL_FLASHEx_OBGetConfig(&OBInit);if(OBInit.RDPLevel OB_RDP_LEVEL_0){OBInit.OptionType | OPTIONBYTE_RDP;OBInit.RDPLevel OB_RDP_LEVEL…

FIR滤波器——DSP学习笔记三(包含一个滤波器设计的简明案例)

​​​​​​ 背景知识 FIR滤波器的特性与优点 可精确地实现线性相位响应&#xff08;Linear phase response&#xff09;&#xff0c;无相位失真&#xff1b; 总是稳定的&#xff0c;所有极点都位于原点 线性相位FIR滤波器的性质、类型及零点位置 冲击响应满足&#xff1a;奇…

iframe父子页面通信

目录 一、 创建父页面和子页面 父页面&#xff08;parent.html&#xff09;&#xff1a; 子页面&#xff08;child.html&#xff09;&#xff1a; 二、 实现父子页面之间的通信 在父页面的 在子页面的 三、扩展&#xff1a;postMessage() 方法的语法&#xff1a; 一、 …

(学习日记)2024.05.03:UCOSIII第五十七节:User文件夹函数概览(uCOS-III->Source文件夹)第三部分

之前的章节都是针对某个或某些知识点进行的专项讲解,重点在功能和代码解释。 回到最初开始学μC/OS-III系统时,当时就定下了一个目标,不仅要读懂,还要读透,改造成更适合中国宝宝体质的使用方式。在学完野火的教程后,经过几经思考,最后决定自己锦上添花,再续上几章。 这…

【PyTorch】torch.gather() 用法

gather常被用于image做mask的操作中&#xff0c;对哪些地方进行赋值0/1 API&#xff1a; torch.gather — PyTorch 2.2 documentation torch.gather(input, dim, index, outNone) → Tensor gather()的意义&#xff1a; 顾名思义&#xff0c;聚集、集合&#xff1a;gather…