Vb.net Autodesk Inventor将零件放置在用户定义的位置
我正在尝试创建一种将文件放置到部件中的方法,我希望它与在Inventor中选择“放置文件”时一样 文件已按其路径选择。现在它需要被放置。我知道如何将文件放置在坐标处,但我希望文件位于光标上,用户能够选择放置位置 你是如何做到这一点的?我尝试了编程帮助搜索,但我只能找到有关事件和对话框的内容Vb.net Autodesk Inventor将零件放置在用户定义的位置,vb.net,autodesk-inventor,Vb.net,Autodesk Inventor,我正在尝试创建一种将文件放置到部件中的方法,我希望它与在Inventor中选择“放置文件”时一样 文件已按其路径选择。现在它需要被放置。我知道如何将文件放置在坐标处,但我希望文件位于光标上,用户能够选择放置位置 你是如何做到这一点的?我尝试了编程帮助搜索,但我只能找到有关事件和对话框的内容 FileDialog.InsertMode() As Boolean 通常我只是原地踏步,但现在不太好 Public Function Place_and_Ground_Part(ByVal oDef As
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
当然,如何实现你想要的并不明显,但如果你知道如何实现,这是可能的。下面的代码演示如何使用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
您可能已经注意到函数没有返回任何内容。使用此方法时会出现问题,因为您执行该命令,然后将控制权移交给Inventor。可以使用事件来观察并查看是否放置了新的事件,然后获取它,但由于它不再是一个简单的函数,因此代码变得相当复杂。感谢brian提供了这段代码。这当然有帮助,但你回答的第二部分对我来说很有趣。因为我想做一些重命名等活动后的地方。你能给我看一个如何得到放置的物体的例子吗?