1

我正在尝试创建一种将文件放置到装配中的方法,并且我希望它就像您在 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
4

1 回答 1

2

如何完成你想要的当然不是很明显,但如果你知道怎么做,它是可能的。下面的代码演示了如何使用 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。可以使用事件来观察并查看是否放置了新的事件,然后获取它,但它使代码变得相当复杂,因为它不再是一个简单的函数。

于 2016-04-26T02:02:07.640 回答