【问题标题】:Autodesk Inventor place part at user defined positionAutodesk Inventor 将零件放置在用户定义的位置
【发布时间】:2016-08-14 12:52:58
【问题描述】:

我正在尝试创建一种将文件放置到装配中的方法,我希望它就像您在 Inventor 中选择放置文件时一样。

文件是由它的路径选择的。现在需要放置它。我知道如何将文件放置在坐标处,但我希望文件位于光标上,并且用户能够选择放置它的位置。

你是如何做到这一点的?我尝试了编程帮助搜索,但我只能找到有关事件和对话框的内容。

FileDialog.InsertMode() As Boolean

通常我只是放置和接地,但现在不太好..

Public Function Place_and_Ground_Part(ByVal oDef As AssemblyComponentDefinition,
                                   ByVal path As String) As ComponentOccurrence

    ' Set a reference to the assembly component definintion.
    ' This assumes an assembly document is open.

    ' Set a reference to the transient geometry object.
    Dim oTG As TransientGeometry
    oTG = oInvApp.TransientGeometry

    ' Create a matrix.  A new matrix is initialized with an identity matrix.
    Dim oMatrix As Matrix
    oMatrix = oTG.CreateMatrix

    ' Set the translation portion of the matrix so the part will be positioned
    ' at (3,2,1).
    oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))

    ' Add the occurrence.
    Dim oOcc As ComponentOccurrence
    oOcc = oDef.Occurrences.Add(path, oMatrix)

    ' Make sure the master part is grounded
    oOcc.Grounded = True
    Return oOcc

End Function

【问题讨论】:

    标签: vb.net autodesk-inventor


    【解决方案1】:

    如何实现你想要的当然不是很明显,但如果你知道怎么做,它是可能的。下面的代码演示了如何使用 PostPrivateEvent 方法将要插入的文件的文件名发布到 Inventor 的内部队列中。接下来,它获取并运行 Place 组件,就像用户启动命令一样。该命令首先检查文件名是否在专用队列上,如果是,则使用该文件名并跳过对话步骤。这使得用户能够拖动和定位事件。

    Public Function Place_and_Ground_Part(ByVal invApp As Application,
                                          ByVal path As String) As ComponentOccurrence
    
        ' Post the filename to the private event queue.
        invApp.CommandManager.PostPrivateEvent(Inventor.PrivateEventTypeEnum.kFileNameEvent, filename)
    
        ' Get the control definition for the Place Component command.
        Dim ctrlDef As Inventor.ControlDefinition
        ctrlDef = invApp.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd")
    
        ' Execute the command.
        ctrlDef.Execute()
    
        Return Nothing
    End Function
    

    您可能已经注意到该函数返回 Nothing。这是使用这种方法的一个问题,因为您执行了命令,然后将控制权交给了 Inventor。可以使用事件来观察并查看是否放置了新的事件然后获取它,但它使代码变得相当复杂,因为它不再是一个简单的函数。

    【讨论】:

    • 感谢 brian 的那段代码。它肯定有帮助,但你答案的第二部分对我来说很有趣。因为我想在地点事件之后做一些重命名等。您能否展示我如何获取放置的对象的示例?
    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 2010-10-26
    • 2016-12-19
    • 2011-01-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 2019-04-10
    相关资源
    最近更新 更多