iLogic Interact with dialog box and/or Help convert to VBA

iLogic Interact with dialog box and/or Help convert to VBA

J-Camper
Advisor Advisor
795 Views
2 Replies
Message 1 of 3

iLogic Interact with dialog box and/or Help convert to VBA

J-Camper
Advisor
Advisor

I am trying to interact with the edit select filters dialog box to set up a few pre-selections without manually scrolling through and checking the options I want.  I'm trying to write it in iLogic because I'm not very familiar with writing VBA macros; however, from my research so far this would work better as a VBA macro.  I have the iLogic code roughed out with the first Pre-selection option I want and some other options to return it to normal for testing purposes:

Dim CustomFilter As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingCustomFiltersCmd")
Dim EditSelectFilter As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingEditSelectFiltersCmd")
Dim SelectAll As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingSelectAllCmd")
Dim OptionsList As New List(Of String) : OptionsList.Add("Edit Selection Filters") : OptionsList.Add("Custom Filter") : OptionsList.Add("Select All")
Dim Options As String = InputListBox("Prompt", OptionsList, OptionsList.Item(2), Title := "OptionsList")

If Options = OptionsList.Item(0)
	EditSelectFilter.Execute
	'Select None to clear
	'Select Hatch box
	'Select Okay
	CustomFilter.Execute
Else If Options = OptionsList.Item(1)
	CustomFilter.Execute
Else If Options = OptionsList.Item(2)
	SelectAll.Execute
Else
	MessageBox.Show("Error", "Error")
End If

What I'm having an issue with is interacting with the "Edit Select Filter" dialog box options. 

 

I tried using SendKeys.Send("{ENTER}"), which throws an error about inventor is not handling Windows messages, And SendKeys.SendWait("{ENTER}"), which does nothing.  Both of those attempts don't fire until the DialogBox is closed.

 

If this is possible in a VBA Macro, I would like some help with the conversion from iLogic code to VBA code.

0 Likes
796 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

The problem is here is that the thread is waiting for the window to close, before it sends the keys. You could solve this by starting a new thread and send the key-strokes from that thread.

I have to note that this a work around that comes with some risks. Sending keys from an other thread is like typing stuff with out looking what is happening on your screen. you will not know for sure if the command is started but the keys are send any way. if you start sending keys and you open an other application the key-strokes are send to the other program. Therefore doing this is considered as bad practice!

I tryed to set the the filters by API and found this but it does not work for me. (maybe some onecan explain why its not working?)

 

Dim doc As DrawingDocument = ThisDoc.Document
doc.SelectionPreferences.Clear()
doc.SelectionPreferences.Add(ObjectTypeEnum.kDrawingViewsObject)

 

So i did not manage to find a better solution for you then sending keys. If you can live with the risks of blindly sending keys then here is code to do it.

 

Sub Main()
	'create a thread that start sending key-strokes
	Dim t As Threading.Thread = New Threading.Thread(AddressOf sendKeys)
	t.Start()

	Dim EditSelectFilter As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingEditSelectFiltersCmd")
	EditSelectFilter.Execute()
End Sub

Public Sub sendKeys()
	' wait/sleep till the command is started. if you dont wait 
	' probaly the first keys will be send to an undifined listener
	' i wait 1000 milisecond (1 second) you can change that to your needs
	' but keep in mind that other computers maby be slower than yours.
	' on the other hand if you wait to long an user might start doing other stuff
	' and the key strokes will not be send to your command any moer but some where else.
	Threading.Thread.Sleep(1000)
	
	'send the key-strokes
	System.Windows.Forms.SendKeys.SendWait("{ENTER}")
End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

J-Camper
Advisor
Advisor

@JelteDeJong, Thanks for Threading snippet.

 

Yeah I tried using the SelectionPreferences Object at first too, but it wasn't working.  Is there any way to set up a trigger for the second thread? Like Sleep/Wait until Boolean variable is true?  I'm not familiar with Threading, so I don't know the possibilities. 

 

Would I be able to get the second thread to more reliably trigger correctly with the Execute2 Method?  It says it wants "Synchronous As Boolean", but I didn't see any change in behavior when I switched it. 

 

As for moving forward with the current workaround, do you know how to "SendKey" of a radial Button selection?  Hatch is the 25th radial button in the filter list for "edit select filters" command.  Currently just opening the dialog box and hitting enter is the same as executing the "DrawingCustomFiltersCmd" Command.

0 Likes