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":
Solved! Go to Solution.
Solved by duke. Go to Solution.
Solved by duke. Go to Solution.
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:
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
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.
@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).
@Maxim-CADman77 , I think the user would still have to pick the component location manually.
@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.
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
@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.