2016-04-21 107 views
1

我试图创建一个将文件放入程序集的方法,并且我希望它能像在Inventor中选择放置文件时一样。Autodesk 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 

回答

2

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

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。可以使用事件来观察并查看是否放置了新的事件,然后获取它,但由于它不再是一个简单的函数,因此它使代码复杂化很多。

+0

感谢布莱恩为那段代码。它肯定有帮助,但你的答案的第二部分对我来说很有意思。因为我想在地点事件之后做一些重命名等。你能展示一个我如何获得放置物体的例子吗? –