Inventor 2014 API 新功能 (8) 装配中的连接(Joint)

在去年12月开发者大会上,我们介绍提到的是“‘Connection”,Inventor最后发布时,改成了“Joint”,但这不影响中文的含义,就是“连接”。是对装配约束的新方式。

Inventor 2014在方便用户使用方面做了不少的工作,前面的快速装配就是一例。而“连接” (Joint)功能也是一个很好的功能。 它是对装配中零件的约束关系进行管理。在用户界面有这样的菜单。 

image

产品功能的详细介绍,请参考我另外个同事Henry写的文章:
http://blog.sina.com.cn/s/blog_684860810102e4mw.html

关于API,我的同事Wayne在全球博客上写了篇介绍文章,我就拿来主义了。原文地址:
http://modthemachine.typepad.com/my_weblog/2013/04/inventor-2014-api-for-the-new-joint-feature.html

相关API方法和对象:

AssemblyJoint: 表示最终的连接对象
AssemblyJointDefinition: 连接的定义
AssemblyComponentDefinition.Joints
 (AssemblyJoints ): 装配中所有的连接
AssemblyJointTypeEnum: 连接的类型
CreateAssemblyJointDefinition: 创建连接定义

和创建特征类似,先是用CreateAssemblyJointDefinition创建 AssemblyJointDefinition,然后调用AssemblyJoints.Add增加最终的连接对象. CreateAssemblyJointDefinition参数有链接类型和两个GeometryIntent. 相信使用过工程图注释的开发者都会熟悉GeometryIntent。

以下是个附件C#工程的代码片段。附件中还有测试用的零件文档。 代码将把两个部件进行连接。 

image

选装其中一个部件,可以看到约束效果。

image

C# functions:

public void AssemblyJoint()

{

    // 创建装配文档.

    AssemblyDocument asmDoc =

(AssemblyDocument)ThisApplication.Documents.Add

      (DocumentTypeEnum.kAssemblyDocumentObject,

     ThisApplication.FileManager.GetTemplateFile

    (DocumentTypeEnum.kAssemblyDocumentObject));

 

    AssemblyComponentDefinition asmDef =

                     asmDoc.ComponentDefinition;

 

    Matrix trans =

ThisApplication.TransientGeometry.CreateMatrix();

 

    // 增加一个零件.

    ComponentOccurrence occ1 =

        asmDef.Occurrences.Add

("C:\\Inventor2014APISamples\\SamplePart.ipt",

                                         trans);

 

    // 增加另外个零件 

    trans.Cell[1, 4] = 6 * 2.54;

    ComponentOccurrence occ2 =

        asmDef.Occurrences.Add

("C:\\Inventor2014APISamples\\SamplePart.ipt",

                                         trans);

 

    // 从部件1获取一个面,获得代理面 

    Face face1 =

        (Face)GetNamedEntity(occ1, "Face1");

 

    

     // 从部件2获取一个面,获得代理面 

    Face face2 =

        (Face)GetNamedEntity(occ2, "Face2");

 

   

     // 从部件2获取一条边,获得代理边

    Edge Edge1 =

        (Edge)GetNamedEntity(occ2, "Edge1");

 

  

  // 从部件1获取一条边,获得代理边

    Edge Edge3 =

        (Edge)GetNamedEntity(occ1, "Edge3");

 

  

    // 创建代理边1的中点GeometryIntent

    GeometryIntent edge1Intent =

        asmDef.CreateGeometryIntent

    (Edge1, PointIntentEnum.kMidPointIntent);

 

      // 创建代理边3的中点GeometryIntent

    GeometryIntent edge3Intent =

        asmDef.CreateGeometryIntent

        (Edge3, PointIntentEnum.kMidPointIntent);

 

    //创建面1和面2的GeometryIntent

    GeometryIntent intentOne =

        asmDef.CreateGeometryIntent

                        (face2, edge1Intent);

    GeometryIntent intentTwo =

        asmDef.CreateGeometryIntent

                        (face1, edge3Intent);

 

    // 创建连接定义。类型为旋转模式

    AssemblyJointDefinition jointDef =

       asmDef.Joints.CreateAssemblyJointDefinition

       (AssemblyJointTypeEnum.kRotationalJointType,

                             intentOne, intentTwo);

 

    jointDef.FlipAlignmentDirection = false;

    jointDef.FlipOriginDirection = true;

    AssemblyJoint joint =

                   asmDef.Joints.Add(jointDef);

 

    //让连接可见

    joint.Visible = true;

 

    // 驱动连接

    joint.DriveSettings.StartValue = "0 deg";

    joint.DriveSettings.EndValue = "180 deg";

    joint.DriveSettings.GoToStart();

    joint.DriveSettings.PlayForward();

    joint.DriveSettings.PlayReverse();

 

}

 

 

// 找寻iMatex相关的实体 

private object GetNamedEntity

    (ComponentOccurrence Occurrence, string Name)

{

        // 在指定文档找寻 iMate  

        PartComponentDefinition partDef =

   (PartComponentDefinition)Occurrence.Definition;

 

        object resultEntity = null;

        resultEntity = null;

 

        foreach (iMateDefinition iMate

                    in partDef.iMateDefinitions)

        {

            // 按名字查找

            if (iMate.Name.ToUpper() ==

                                Name.ToUpper())

            {

             // 获取和iMate相关的几何体 

              object entity = null;

              entity = iMate.GetType().InvokeMember

                           ("Entity",

                            BindingFlags.GetProperty,

                            null, iMate, null);

 

                //创建几何体的代理实体.

                Occurrence.CreateGeometryProxy

                    (entity, out resultEntity);

                break;

            }

        }

 

        // 返回找到的实体的代理实体

        return resultEntity;

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值