蒹葭苍苍,白露为霜。
所谓伊人,在水一方。

Autodesk Inventor增加装配体约束API样例

这个是一个VBA样例,运行之前需要打开至少包含2个零件的装配体文件,两个零件最好包含圆孔特征。选择好两个零件的圆孔或者圆边缘。然后运行这个VBA脚本就可以添加相关约束了。

这种代码一般不会直接就拿来用,一般用在自动化装配的情况。参考用。

Public Sub InsertConstraint()
    ' Set a reference to the assembly component definintion.
    Dim oAsmCompDef As AssemblyComponentDefinition
    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    ' Set a reference to the select set.
    Dim oSelectSet As SelectSet
    Set oSelectSet = ThisApplication.ActiveDocument.SelectSet
    
    ' Validate the correct data is in the select set.
    If oSelectSet.Count  2 Then
        MsgBox "You must select the two circular edges for the insert."
        Exit Sub
    End If

    If Not TypeOf oSelectSet.Item(1) Is Edge Or Not TypeOf oSelectSet.Item(2) Is Edge Then
        MsgBox "You must select the two circular edges for the insert."
        Exit Sub
    End If

    ' Get the two edges from the select set.
    Dim oEdge1 As Edge
    Dim oEdge2 As Edge
    Set oEdge1 = oSelectSet.Item(1)
    Set oEdge2 = oSelectSet.Item(2)
 
    ' Create the insert constraint between the parts.
    Dim oInsert As InsertConstraint
    Set oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge2, True, 0)
End Sub
赞(0) 打赏
未经允许不得转载:酷居科技 » Autodesk Inventor增加装配体约束API样例

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

锦瑟无端五十弦,一弦一柱思华年

酷居科技联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏