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)vRadEnti;

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)vBoundEnti;

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 andSurface-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)vRadEnti;

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的含义为允许访问表面修剪功能,下面是官方具体解释:

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

相关推荐
雨落倾城夏未凉5 天前
第四章c#方法-参数数组和可选参数(16)
后端·c#
唐青枫6 天前
线程不是越多越快:C#.NET Thread 生命周期、同步与后台工作线程实战
c#·.net
唐青枫7 天前
别只会反射:C#.NET Emit 动态生成代码实战详解
c#·.net
咕白m6257 天前
.NET 环境下 Word 超链接批量提取方案
c#·.net
用户91721561902117 天前
C# 通信协议增量解析:用状态机处理半包和粘包
c#
小码编匠8 天前
C# 工控上位机必备:数据转换工具类与十个核心模块
后端·c#·.net
唐青枫10 天前
别再乱用 StartNew:C#.NET TaskFactory 任务调度实战详解
c#·.net
Artech10 天前
[MAF预定义的AIContextProvider-03]ChatHistoryMemoryProvider——赋予Agent从经验中学习的能力
ai·c#·agent·memory·maf
Scout-leaf12 天前
C#摸鱼实录——IoC与DI案例详解
c#
咕白m62512 天前
使用 C# 在 Excel 中应用多种字体样式
后端·c#