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.hqwc.cn/news/636873.html

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

相关文章

c语言中的数组

数组 数组是一种构造类型&#xff0c;是由基本类型构造而成。当我们想用一群变量来描述同一类相同的东西时候&#xff0c;比如100个年龄变量&#xff0c;我们可以这样int age1&#xff1b;int age2&#xff1b;int age3&#xff1b;……int age 100;这样即不方便书写&#xff…

【Linux开发 第九篇】磁盘分区

Linux磁盘分区 磁盘分区 Linux分区是用来组成整个文件系统的一部分 Linux采用了一种叫载入的处理方法&#xff0c;它的整个文件系统中包括了一整套的文件和目录&#xff0c;且将一个分区和一个目录联系起来&#xff0c;这时要载入的一个分区将使它的存储空间开一个目录下获得…

便携的图像背景去除工具PhotoScissors9.2版本在Windows系统的下载与安装配置

目录 前言一、PhotoScissors安装二、使用配置总结 前言 ​“ PhotoScissors是一个多功能和强大的照片编辑工具&#xff0c;专门为Windows用户寻求一个直观的解决方案&#xff0c;背景删除和图像编辑。作为专用的Windows软件&#xff0c;PhotoScissors提供了一个用户友好的平台…

Error in render: TypeError: Cannot read properties of undefined (reading‘‘)

报错内容 报错解释&#xff1a;这个错误在渲染过程中尝试读取一个未定义&#xff08;undefined&#xff09;对象的某个属性时发生了TypeError。具体来说&#xff0c;是尝试读取一个值为undefined的对象的某个属性&#xff0c;但该属性不存在&#xff0c;因此无法读取。解决过程…

【剪映专业版】15绿幕抠图:应用技巧、注意事项

视频课程&#xff1a;B站有知公开课【剪映电脑版教程】 1.绿幕抠图 背景为绿色的素材&#xff08;其他颜色也可以扣取&#xff0c;只是绿色背景更普遍、抠图效果更好&#xff09; 选择色度抠图&#xff0c;通过取色器选取背景颜色&#xff0c;调整强度实现抠图 剪映的色度抠…

三维天地低代码平台实现客户需求的快速交付与灵活定制

— 款合格的低代码平台应具备架构稳定、 产品质量高、 交付速度快、 运维简便的特点, 能快速实现业务需求到系统功能落地。 二十余年来, 北京三维天地科技股份有限公司一直专注于实验室信息化管理 领域, 旗下 SW- LIMS 已在化工、 环保、 食品、 科研等二十余个行业广泛应用,服…

机器学习和深度学习 -- 李宏毅(笔记与个人理解)Day19

Day 19 Recurrent Neural Network &#xff08;RNN 1&#xff09; md 发现我最近需要恶补一下vue的技术……服了&#xff08;因为有两个项目要交单子了&#xff09; 好吧导致我停更新两天的DL&#xff0c;我去如坐针毡啊&#xff01;今天补上 Slot Filling 将词语用向量的形式来…

【QT进阶】Qt http编程之http相关类的简单介绍

往期回顾 【QT进阶】Qt Web混合编程之实现ECharts数据交互动态修改-CSDN博客 【QT进阶】Qt http编程之http与https简单介绍-CSDN博客 【QT进阶】Qt http编程之后端API测试工具postman使用介绍-CSDN博客 【QT进阶】Qt http编程之http相关类QNetworkAccessManager与QNetworkReque…

如何设置unbuntu时间及同步时间

文章目录 时区时间同步与服务 时间同步的重要性Ubuntu系统中设置时间和同步时间方法一&#xff1a;通过图形界面设置查看当前时间设置时间和时区设置时区&#xff08;假设设置为UTC&#xff09;&#xff1a;设置本地时间&#xff08;例如&#xff0c;设置时间为2024年4月21日 1…

HTML不常用的文本标签

1.标签如下&#xff1a; 代码及相关内容 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>不常用的文…

OpenCV杂记(1):绘制OSD(cv::getTextSize, cv::putText)

1. 简述 我们使用OpenCV时&#xff0c;有时会在图像的某个位置绘制OSD信息&#xff0c;如绘制一些字符串作为指示信息。 本文将简要介绍在图像&#xff08;cv::Mat&#xff09;上绘制固定的字符串信息。 2. 使用的API &#xff08;1&#xff09;cv::getTextSize() CV_EXPORT…

网址注册流程

从选择域名到完成注册 在互联网时代&#xff0c;拥有一个独特的网址是建立个人品牌或企业形象的重要一环。然而&#xff0c;对于许多人来说&#xff0c;网址注册流程可能显得有些复杂。本文将详细介绍网址注册的全过程&#xff0c;帮助您顺利完成注册&#xff0c;拥有自己的专属…