Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Place Sub.Assembly with Selected Position Representation iLogic/VB.NET

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ngnam1988
337 Views, 3 Replies

Place Sub.Assembly with Selected Position Representation iLogic/VB.NET

ngnam1988
Advocate
Advocate

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!

0 Likes

Place Sub.Assembly with Selected Position Representation iLogic/VB.NET

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!

Tags (2)
3 REPLIES 3
Message 2 of 4
WCrihfield
in reply to: ngnam1988

WCrihfield
Mentor
Mentor
Accepted 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

EESignature

(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

EESignature

(Not an Autodesk Employee)

Message 3 of 4
ngnam1988
in reply to: ngnam1988

ngnam1988
Advocate
Advocate

Thanks for your key! @WCrihfield 
I can do it now. Just another question: How to insert Sub.Assembly at mouse cursor?

0 Likes

Thanks for your key! @WCrihfield 
I can do it now. Just another question: How to insert Sub.Assembly at mouse cursor?

Message 4 of 4
WCrihfield
in reply to: ngnam1988

WCrihfield
Mentor
Mentor

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

EESignature

(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

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report