Dears,
I'm working on Bolts Sub.Assembly with some Position Representation. Please help me the iLogic/VB.NET Code that can place the Bolts Sub.Assembly into working Assembly with selection Position Representation.
I'm using VB.NET Code to insert Bolts Sub.Assembly but its always place the "Master"
Dim oPathFilename As String = "G:\Workspace\" & oFilename
mInventorApp.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPathFilename)
mInventorApp.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute()
Thank you very much!
Solved! Go to Solution.
Dears,
I'm working on Bolts Sub.Assembly with some Position Representation. Please help me the iLogic/VB.NET Code that can place the Bolts Sub.Assembly into working Assembly with selection Position Representation.
I'm using VB.NET Code to insert Bolts Sub.Assembly but its always place the "Master"
Dim oPathFilename As String = "G:\Workspace\" & oFilename
mInventorApp.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPathFilename)
mInventorApp.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute()
Thank you very much!
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @ngnam1988. In order for you to be able to specify which PositionalRepresentation you want the component to be using when you place the component into the assembly, you will most likely have to use the Inventor API code route to do so. Below is a link to the online help page for the method you would need to use. To get to this method by API code, it is under the following: AssemblyDocument.ComponentDefinition.Occurrences.AddWithOptions(). You can read what it has to say about using that method, and there is link to a VBA sample, but it includes the use of a NameValueMap, which you would have to create, then add the specified name / value pairs into it, and use it when you call the method to run.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @ngnam1988. In order for you to be able to specify which PositionalRepresentation you want the component to be using when you place the component into the assembly, you will most likely have to use the Inventor API code route to do so. Below is a link to the online help page for the method you would need to use. To get to this method by API code, it is under the following: AssemblyDocument.ComponentDefinition.Occurrences.AddWithOptions(). You can read what it has to say about using that method, and there is link to a VBA sample, but it includes the use of a NameValueMap, which you would have to create, then add the specified name / value pairs into it, and use it when you call the method to run.
Wesley Crihfield
(Not an Autodesk Employee)
Thanks for your key! @WCrihfield
I can do it now. Just another question: How to insert Sub.Assembly at mouse cursor?
Thanks for your key! @WCrihfield
I can do it now. Just another question: How to insert Sub.Assembly at mouse cursor?
Hi @ngnam1988. Placing the component at your mouse cursor is a whole other complex matter, that would need to involve multiple layers of events and a mode change. If placing the component at your mouse cursor is super important, then executing the command, and using the normal manual user interface tools is likely you best route. I don't think I have tried placing an assembly component at the position of my mouse pointer by code before, because we already have a built-in tool for doing it that way. Plus the mouse position routine just returns a Point objects, and the AddWithOptions wants a Matrix to dictate the position of the component.
Below is a quick example of how to get the mouse position.
Class ThisRule
Dim oIntEv As InteractionEvents
Dim oMouseEv As MouseEvents
Dim oMousePosition As Inventor.Point
Sub Main
oIntEv = ThisApplication.CommandManager.CreateInteractionEvents
oMouseEv = oIntEv.MouseEvents
AddHandler oMouseEv.OnMouseClick, AddressOf oMouseEv_OnMouseClick
Logger.Info("Just added the OnMouseClick event handler.")
oIntEv.Start
'now use that oMousePosition variable as you may need
End Sub
Sub oMouseEv_OnMouseClick(oMBtn As MouseButtonEnum, oShiftState As ShiftStateEnum, oMPos As Inventor.Point, oViewPos As Point2d, oView As Inventor.View)
MsgBox("Model Position = " & oMPos.X & " cm x " & oMPos.Y & " cm (from model origin)" & vbCrLf & _
"View Position = " & oViewPos.X & " x " & oViewPos.Y & " (from top left corner of view)", , "MOUSE POSITION")
oMousePosition = oMPos 'sets it to the 'common' variable outside of this routine
RemoveHandler oMouseEv.OnMouseClick, AddressOf oMouseEv_OnMouseClick
Logger.Info("Just removed the OnMouseClick event handler.")
End Sub
End Class
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @ngnam1988. Placing the component at your mouse cursor is a whole other complex matter, that would need to involve multiple layers of events and a mode change. If placing the component at your mouse cursor is super important, then executing the command, and using the normal manual user interface tools is likely you best route. I don't think I have tried placing an assembly component at the position of my mouse pointer by code before, because we already have a built-in tool for doing it that way. Plus the mouse position routine just returns a Point objects, and the AddWithOptions wants a Matrix to dictate the position of the component.
Below is a quick example of how to get the mouse position.
Class ThisRule
Dim oIntEv As InteractionEvents
Dim oMouseEv As MouseEvents
Dim oMousePosition As Inventor.Point
Sub Main
oIntEv = ThisApplication.CommandManager.CreateInteractionEvents
oMouseEv = oIntEv.MouseEvents
AddHandler oMouseEv.OnMouseClick, AddressOf oMouseEv_OnMouseClick
Logger.Info("Just added the OnMouseClick event handler.")
oIntEv.Start
'now use that oMousePosition variable as you may need
End Sub
Sub oMouseEv_OnMouseClick(oMBtn As MouseButtonEnum, oShiftState As ShiftStateEnum, oMPos As Inventor.Point, oViewPos As Point2d, oView As Inventor.View)
MsgBox("Model Position = " & oMPos.X & " cm x " & oMPos.Y & " cm (from model origin)" & vbCrLf & _
"View Position = " & oViewPos.X & " x " & oViewPos.Y & " (from top left corner of view)", , "MOUSE POSITION")
oMousePosition = oMPos 'sets it to the 'common' variable outside of this routine
RemoveHandler oMouseEv.OnMouseClick, AddressOf oMouseEv_OnMouseClick
Logger.Info("Just removed the OnMouseClick event handler.")
End Sub
End Class
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.