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: 

Use command manager to supplement user input in "Place iLogic Component"

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
duke
713 Views, 11 Replies

Use command manager to supplement user input in "Place iLogic Component"

I have written code that runs the "Place iLogic Component" method. It works great in initiating the process, but still requires the user to press "OK" on the form, and then to place the component in the assembly. I want to use iLogic and the command manager to supplement the user input and place the component. What code can I add to do this?

 

This is my current rule:

fileName = RuleArguments("fileName")

If fileName = Nothing
	MsgBox("Failed to initiate the 'Place iLogic Component' method." _
	& " No file path was provided.", , "ERROR")
Else
	If System.IO.File.Exists(fileName) = False
		MsgBox("The designated file was not found.", , "ERROR")
	Else
		Dim cmdManager As CommandManager
		cmdManager = ThisApplication.CommandManager

		'Loads the filename of the component to be added to the assembly.
		cmdManager.PostPrivateEvent(kFileNameEvent, fileName)

		'Set the control definition to place an iLogic component.
		Dim oControlDef As ControlDefinition
		oControlDef = cmdManager.ControlDefinitions.Item("iLogic.PlaceComponent")

		'Execute the command
		oControlDef.Execute()

 

This is the form that I need code to supplement the user input and press "OK":

duke_0-1687446943725.png

 

Labels (1)
11 REPLIES 11
Message 2 of 12
Curtis_Waguespack
in reply to: duke

Hi @duke 

 

I don't have the time to look at the moment, but if you can tab to the ok button in the form, then you can likely use SendKeys to tab to the button and press it programatically.

 

see example:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/send-a-ctrl-tab-keystroke-to-iproper...

 

Note too that you will probably want to use Execute2, with False

 

oControlDef.Execute()

 

oControlDef.Execute2(False)

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

Message 3 of 12
duke
in reply to: Curtis_Waguespack

You cannot tab to the OK button on the form. My hope is to be able to figure out the control definition that will allow me to reference the button, or to be able to reference the form somehow.

Message 4 of 12
duke
in reply to: duke

I figured it out. I was able to reference the form and click the OK button.

Message 5 of 12
Frederick_Law
in reply to: duke

How?

Message 6 of 12
Maxim-CADman77
in reply to: duke

@duke 
Will you, please, share with community your successful method of clicking OK button on "Place iLogic Component" form?
It is not of much sense to mark the message as a solution if other can't get any info from it (solution marks are are highlighter but your point followers to nowhere).

I also would like to know your further workflow ... whether you expect user to point the new component location manually (I hope there is a way to do it programmatically).

Message 7 of 12
Maxim-CADman77
in reply to: duke

I kindly hope @MjDeck can clarify this subject.

Message 8 of 12
MjDeck
in reply to: duke

@Maxim-CADman77 , I think the user would still have to pick the component location manually.


Mike Deck
Software Developer
Autodesk, Inc.

Message 9 of 12
duke
in reply to: MjDeck

@Maxim-CADman77 and @MjDeck, This is correct. I was able to create logic that clicked the button as I had intended, but the user was still required to place the component manually. This limitation was a roadblock for my intended workflow, so I ended up taking a different approach. I recreated the "Add iLogic Component" functionality so that I could add and place unique components without requiring any user input. The resulting code is quite complicated, so I don't recommend attempting it.
Message 10 of 12
Maxim-CADman77
in reply to: duke

@duke thank you for clarification,

 

I also finished with creating my own version of the command ... yet I still would like to know your way of pressing the OK (just as common knowledge of coding technologies).

I can do it with AutoIt ... yet this way is definitely not something reliable enough.

Message 11 of 12
duke
in reply to: Maxim-CADman77

I apologize to those who may have been interested in my solution that I did not post it earlier. After I solved the problem I encountered a subsequent roadblock, and directed all of my attention to solving that issue.

 

Below is the code that I used to click the button on the form. You can see that I make use of a timer function to allow the form to load completely before proceeding, then I reference the form and activate the accept button. When the code is finished the user still must place the component manually. This lessens the appeal of this particular rule, but the functionality is still useful in other applications.

 

'Uses the command manager to execute the 'Place iLogic Component' command
'on a predefined file name.

fileName = RuleArguments("fileName")

If fileName = Nothing
	MsgBox("Failed to initiate the 'Place iLogic Component' method." _
	& " No file path was provided.", , "ERROR")
Else
	If System.IO.File.Exists(fileName) = False
		MsgBox("The designated file was not found.", , "ERROR")
	Else
		Dim cmdManager As CommandManager
		cmdManager = ThisApplication.CommandManager

		'Loads the filename of the component to be added to the assembly.
		cmdManager.PostPrivateEvent(kFileNameEvent, fileName)

		'Set the control definition to place an iLogic component.
		Dim oControlDef As ControlDefinition
		oControlDef = cmdManager.ControlDefinitions.Item("iLogic.PlaceComponent")
		
		'Execute the command
		oControlDef.Execute()
		
		'Use a timer to delay before closing the form. A glitch occurs without it
		Timer1 = Now.Second
		Timer2 = Now.Second
		Do While Timer2 - Timer1 < 0.5
			Timer2 = Now.Second
		Loop
		
		'Reference the active form, which is the component parameter pop-up
		Dim oForm As System.Windows.Forms.Form
		oForm = System.Windows.Forms.Form.ActiveForm
		
		'Click the OK button on the form to accept all parameters as is and proceed
		'to placing the component.
		oForm.AcceptButton.PerformClick		
		
	End If
End If

 

Message 12 of 12
Maxim-CADman77
in reply to: duke

@duke 
Thanks a lot for sharing! ... I wish I knew this technics before.

I believe I can suggest adding some protection like:

 

Do
	actDlg = System.Windows.Forms.Form.ActiveForm
	Threading.Thread.Sleep(500)
Loop While Not actDlg.Text = "Place iLogic Component" 

 

 

I wonder if it possible use same technics to finally place the iLogic component by API

... something like ... wait Inventor's main window became active and then emulate pressing Enter and then Esc?


My attempt was:

 

Threading.Thread.Sleep(100)

actDlg = Nothing

Do
	actDlg = System.Windows.Forms.Form.ActiveForm
	' logger.info(actDlg.Text)
	Threading.Thread.Sleep(1999)

Loop While Not (actDlg Is Nothing Or actDlg.Text.StartsWith("Autodesk Inventor")) ' Object reference not set to an instance of an object.

SendKeys.SendWait("{Enter}")

Threading.Thread.Sleep(200)

SendKeys.SendWait("{Esc}")

 

But I got "Object reference not set to an instance of an object."

 

PS:
Just in case: half-second delay of vb code execution can be done with single line like: 

 

Threading.Thread.Sleep(500)

 

 

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

Post to forums  

Autodesk Design & Make Report