Solidworks二次开发遍历

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Solidworks二次开发—06—在装配体中添加配合

分类:devil-box about2005-04-07 10:38 1514人阅读评论(3) 收藏举报distanceinputfunctionalignmentobjectassembly

Solidworks二次开发—06—在装配体中添加配合

折腾了三天终于完成了计划中的功能模块。在一个装配体中自动判断插入合适的零件,并添加配合。

在前面几篇文章中我已经基本上说明了如何得到零部件的数据信息、如何插入零部件、如何得到已经选择的特征等。

下面只介绍怎样进行配合

在做配合时,需要经常选择到零件的面、线等,这是一个问题,还有就是介绍一下addmate2函数的使用:一般进行配合我们按照下面的次序来进行:

1-ModelDoc.ClearSelection2 ‘取消所有选择

2-选择需要配合的实体(entity)

3-使用AddMate2函数进行配合

4-再次使用 ModelDoc.ClearSelection2 ‘取消所有选择

主要的问题在于如何选择合适的面:

由于面的命名没有什么规律,很多时候是程序自动来命名的,这样,不方便使用selectbyID来选择,我也不想使用坐标值来选择一个面,那样做更加糟糕。

在得到一个组件(component)或者一个特征(feature)时,我们有getfaces、getfirstface、getnextface 等方法,我们可以使用这些方法遍历一个组件或特征等的各个面,来达到选择面的目的,看下面程序:

此函数接受两个参数,第一个是一个component对象,第二个用来标识选择类型:0表示圆柱面,1表示平

面。此函数运行完成后将选择指定组件的指定类型的一个面。需要注意的是我们需要在判断面类型时候需

要转换到surface对象。而且选择需要定义一个entity对象,用来select4,达到选择的目的。可能这个过程

有些复杂,大家按照这个顺序多测试几次,就明白了它的工作原理。

上面的函数写的并不好,是我从我的工程中截取的一段。

下面介绍一下addmate2函数:

Syntax (OLE Automation) OLE语法:

pMateObjOut = AssemblyDoc.AddMate2 ( mateTypeFromEnum, alignFromEnum, flip, distance, distAbsUpperLimit, distAbsLowerLimit, gearRatioNumerator, gearRatioDenominator, angle, angleAbsUpperLimit, angleAbsLowerLimit, errorStatus )

参数:

Input:(long) mateTypeFromEnum Type of mate as defined in swMateType_e配合类型

Input:(long) alignFromEnum Type of alignment as defined in swMateAlign_e对齐选项

Input:(VARIANT_BOOL) flip TRUE to flip the component, FALSE otherwise是否翻转

Input:(double) distance Distance value to use with distance or limit mates距离

Input:(double) distAbsUpperLimit Absolute maximum distance value (see Remarks)距离限制max Input:(double) distAbsLowerLimit Absolute minimum distance value (see Remarks)距离限制min Input:(double) gearRatioNumerator Gear ratio numerator value for gear mates齿轮配合分子值Input:(double) gearRatioDenominator Gear ratio denominator value for gear mates齿轮配合分母值Input:(double) angle Angle value to use with angle mates角度

Input:(double) angleAbsUpperLimit Absolute maximum angle value角度限制max Input:(double) angleAbsLowerLimit Absolute minimum angle value角度限制min Output:(long) errorStatus Success or error as defined by swAddMateError_e错误报告

Return:(LPMATE2) pMateObjOut Pointer to the Mate2 object返回指向配合的指针Remarks

To specify a distance mate without limits, set the distAbsUpperLimit and distAbsLowerLimit arguments

equal to the distance argument's value.

指定一个没有限制的距离,设定距离限制的最大、最小值和距离值相等

If mateTypeFromEnum is swMateDISTANCE or swMateANGLE when the mate is applied to the closest

position that meets the mate condition specified by distance or angle, then setting flip to TRUE moves the

assembly to the other possible mate position.

如果是距离或角度配合,配合将从符合条件的最近端进行配合,我们可以设定flip为true,改变配合至另

一个合适的位置

相关文档
最新文档