几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2007-01-11, 04:43 PM   #1
face
初级会员
 
注册日期: 07-01
帖子: 2
精华: 0
现金: 10 标准币
资产: 10 标准币
face 向着好的方向发展
默认 Tessellate a Body Example (C#)

Tessellate a Body Example (C#)

This example shows how to tessellate a body.



'--------------------------------------------------

'

' Preconditions: Part is open and contains a body.

'

' Postconditions: Body is tessellated.

'

'--------------------------------------------------



using System;



using SldWorks;



namespace ConsoleApplication1

{



class Class1

{



/// <summary>

/// Main entry point for the application

/// </summary>

[STAThread]

static void Main(string[] args)

{



// Connect to SolidWorks

SldWorks.SldWorks swApp = new SldWorks.SldWorksClass();



// Get the active document

SldWorks.ModelDoc2 swModel = swApp.IActiveDoc2;



// Get the document title

String title = swModel.GetTitle();



// Cast down to a part

SldWorks.PartDoc swPart = (SldWorks.PartDoc)swModel;



// Variant is returned, which can be dealt with as an object

// Variant represents an array of references

System.Object vBodies;

System.Array aBodies;



// Get bodies

vBodies = swPart.GetBodies2((int)SwConst.swBodyType_e.swAllBodies, false);



// Cast to an array of bodies

aBodies = (System.Array)vBodies;

int iNumBodies = aBodies.Length;

int iNumSolidBodies = 0;

int iNumSheetBodies = 0;



// Loop through array

SldWorks.Body2 swBody;

for (int b = 0; b < iNumBodies; b++)

{



// Get a body and apply cast

swBody = (SldWorks.Body2)aBodies.GetValue(b);



// Now call a method on a body

int nBodyType = swBody.GetType();



if (nBodyType == (int)SwConst.swBodyType_e.swSheetBody)

{

iNumSheetBodies++;

}

if (nBodyType == (int)SwConst.swBodyType_e.swSolidBody)

{

iNumSolidBodies++;



SldWorks.Face2 swFace = null;

SldWorks.Tessellation swTessellation = null;

bool bResult = false;



// Pass in null so the whole body will be tessellated

swTessellation = (Tessellation)swBody.GetTessellation(null);





//

// Set up the Tessellation object

// Required data

swTessellation.NeedFaceFacetMap = true;

swTessellation.NeedVertexParams = true;

swTessellation.NeedVertexNormal = true;



// How to handle matches across common edges

swTessellation.MatchType = (int)SwConst.swTesselationMatchType_e.swTesselationMatchFacetTopology;



// Do it

bResult = swTessellation.Tessellate();



// Get the number of vertices and facets

int iNumVertices = swTessellation.GetVertexCount();

int iNumFacets = swTessellation.GetFacetCount();



// Now get the facet data per face

int[] aFacetIds;

int iNumFacetIds;

int[] aFinIds;

int[] aVertexIds;

double[] aVertexCoords1;

double[] aVertexCoords2;





//

// Add sketch for this body

// Speed things up

swModel.SetAddToDB(true);

swModel.SetDisplayWhenAdded(false);



// Insert sketch

swModel.Insert3DSketch2(false);





// Loop over faces

swFace = (Face2)swBody.GetFirstFace();



while (swFace != null)

{

aFacetIds = (int[])swTessellation.GetFaceFacets(swFace);



iNumFacetIds = aFacetIds.Length;



for (int iFacetIdIdx = 0; iFacetIdIdx < iNumFacetIds; iFacetIdIdx++)

{

aFinIds = (int[])swTessellation.GetFacetFins(aFacetIds[iFacetIdIdx]);



// There should always be three fins per facet

for (int iFinIdx= 0; iFinIdx < 3; iFinIdx++)

{



aVertexIds = (int[])swTessellation.GetFinVertices(aFinIds[iFinIdx]);



// Should always be two vertices per fin

aVertexCoords1 = (double[])swTessellation.GetVertexPoint(aVertexIds[0]);

aVertexCoords2 = (double[])swTessellation.GetVertexPoint(aVertexIds[1]);



// Create a line

swModel.CreateLine2(aVertexCoords1[0], aVertexCoords1[1], aVertexCoords1[2], aVertexCoords2[0], aVertexCoords2[1], aVertexCoords2[2]);

}

}



swFace = (Face2)swFace.GetNextFace();

}

// Close sketch

swModel.Insert3DSketch2(true);



// Clear selection for next pass

swModel.ClearSelection2(true);



// Restore settings

swModel.SetAddToDB (false);

swModel.SetDisplayWhenAdded(true);

}

}

return;

}

}

}
face离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
How to set the tolerance parameters of Tessellate face? huangyhg SolidWorks二次开发 1 2006-12-11 12:43 PM
How to set the parameters of Tessellate face? huangyhg SolidWorks二次开发 0 2006-12-07 04:14 PM


所有的时间均为北京时间。 现在的时间是 10:31 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多