Send a CTRL+TAB keystroke to iProperties dialog with iLogic

Send a CTRL+TAB keystroke to iProperties dialog with iLogic

Anonymous
Not applicable
3,845 Views
22 Replies
Message 1 of 23

Send a CTRL+TAB keystroke to iProperties dialog with iLogic

Anonymous
Not applicable

Ok I have an iLogic rule that opens the iProperties dialog for the file type that is active.  That much I got.  Now I need to send a CTRL + TAB keystroke after it is opened so that the 'Summary' tab is active when the iProperties dialog is shown.  

here is the code I got:

 

SyntaxEditor Code Snippet

Imports System.Windows.Forms

Sub Main()
    
    Dim oCommandMgr As CommandManager 
        oCommandMgr = ThisApplication.CommandManager 
    Dim oControlDef As ControlDefinition 
     oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingiPropertiesCmd")
    Call oControlDef.Execute '2(False)
    SendKeys.SendWait("^{TAB}")  '← I'm guessing that the '^' carot is supposed to be the 'CTRL key'  but all this does is just a normal 'TAB' which sets the 'Help' active 
    ThisApplication.UserInterfaceManager.DoEvents()
End Sub

Please do not reply with HOW to get the dialog to open I know how to do that I just want the Summary TAB to be the active tab when it does.  

 

 

Accepted solutions (2)
3,846 Views
22 Replies
Replies (22)
Message 2 of 23

MjDeck
Autodesk
Autodesk
Accepted solution

It seems like it's not sending the CTRL successfully. But you can use the right arrow instead:

Imports System.Windows.Forms

Sub Main()
    Dim oCommandMgr As CommandManager 
    oCommandMgr = ThisApplication.CommandManager 
    Dim oControlDef As ControlDefinition 
    oControlDef = oCommandMgr.ControlDefinitions.Item("DrawingiPropertiesCmd")

    Call oControlDef.Execute2(False)
    SendKeys.SendWait("{RIGHT}")
    ThisApplication.UserInterfaceManager.DoEvents()
End Sub

Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 23

Curtis_Waguespack
Consultant
Consultant
Accepted solution

This is useful stuff , thanks!

 

Adding to what @MjDeck provided here is rule I just created that open the iProperty dialog to the Custom tab for any parts, assemblies and drawings.

 

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

 

Imports System.Windows.Forms

Sub Main()

	doc = ThisDoc.ModelDocument
	'check file type
	If doc.DocumentType = kPartDocumentObject Then
		oCmd = "PartiPropertiesCmd"
	Else If doc.DocumentType = kAssemblyDocumentObject Then
		oCmd = "AssemblyiPropertiesCmd"
	Else If doc.DocumentType = kDrawingDocumentObject Then
		oCmd = "DrawingiPropertiesCmd"
	End If

    Dim oCommandMgr As CommandManager 
    oCommandMgr = ThisApplication.CommandManager 
    Dim oControlDef As ControlDefinition 
    oControlDef = oCommandMgr.ControlDefinitions.Item(oCmd)

    Call oControlDef.Execute2(False)
	
	'opens to Custom tab ( send "right arrow" key 4 times)
    SendKeys.Sendwait("{RIGHT 4}")
	ThisApplication.UserInterfaceManager.DoEvents()

End Sub

EESignature

Message 4 of 23

Anonymous
Not applicable

Great, but only when using in a drwing gives me an error:

 

Error in rule: ShowCustomiProperty, in document: Drawing1.dwg
De objectvariabele of With block-variabele is niet ingesteld.

 

 

 

0 Likes
Message 5 of 23

Anonymous
Not applicable

@Anonymous wrote:

Great, but only when using in a drwing gives me an error:

 

Error in rule: ShowCustomiProperty, in document: Drawing1.dwg
De objectvariabele of With block-variabele is niet ingesteld.

Thank you gentlemen for the solutions they work great.  

@Anonymous   I get the same thing with a drawing file but the part and assembly work perfectly.  I need them to go to the comment section most of the time so here is the code to open to the Comments:

 Here's the fix:

Imports System.Windows.Forms

Sub Main()

	doc = ThisDoc.Document
	'check file type
	If doc.DocumentType = kPartDocumentObject Then
		oCmd = "PartiPropertiesCmd"
	Else If doc.DocumentType = kAssemblyDocumentObject Then
		oCmd = "AssemblyiPropertiesCmd"
	Else If doc.DocumentType = kDrawingDocumentObject Then
		oCmd = "DrawingiPropertiesCmd"
	End If

    Dim oCommandMgr As CommandManager 
    oCommandMgr = ThisApplication.CommandManager 
    Dim oControlDef As ControlDefinition 
    oControlDef = oCommandMgr.ControlDefinitions.Item(oCmd)

    Call oControlDef.Execute2(False)
	
	'opens to Summary tab, Comments Box ( send "right arrow" key 4 times and "TAB" key 9 times)
    SendKeys.Sendwait("{RIGHT}{TAB 9}")
	ThisApplication.UserInterfaceManager.DoEvents()

End Sub

 

Message 6 of 23

RoyWickrama_RWEI
Advisor
Advisor

I was trying to use your code to get around to the OK button activated after entering data for comments.

I appreciate if you would help me to get the OK button at the 3rd time the Enter button is pressed (it is similar to pressing TAB key after pressing the enter button (say for two times)

 

2019-02-24 0017.png 

Sub oCheckIn()
	Dim oCommandMgr As CommandManager 
    oCommandMgr = ThisApplication.CommandManager 
'	ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)
	oControlDef = oCommandMgr.ControlDefinitions.Item("VaultCheckinTop")		'.Execute2(False)
    Call oControlDef.Execute2(False)
    SendKeys.SendWait("{RIGHT}")
    ThisApplication.UserInterfaceManager.DoEvents()
End Sub
0 Likes
Message 7 of 23

MjDeck
Autodesk
Autodesk

@RoyWickrama_RWEI , the attached text file has a modified version of your rule. It gets the TAB key to work as expected by using the SetForegroundWindow function. I tested this with a simple check-in workflow. But there's no guarantee. I don't think it will work in all situations.


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 23

RoyWickrama_RWEI
Advisor
Advisor

Thanks MjDeck.

It works fine if we don't type in any comments.

It also helped me learning to use {SHIFT} and {Enter} and the similar. I wanted this in several times.

 

In practice, we need to type in data for comments at Checkin and therefore I need to do as follows:

 

'After typing data in (or without any data types in), when the ENTER button is pressed, the cursor moves To the beginning of 2nd line awaiting for data typed in the 2nd line. But, instead of cursor shifting to the 2nd row (keeping the Checking dialog box is open yet), hitting {ENTER} button should prompt the user input to do so (using vbYes) or to mimic {TAB} and then {ENTER}} functions so that, checkin will be done.

 

	L_Comments:
	'Code for entering Comments (1st row only)
	'-----------------
	oYesNo = MessageBox.Show("Do you want to type comments in next row?", "TYPE COMMENTS IN NEXT ROW", MessageBoxButtons.YesNo)
	If oYesNo = vbYes Then GoTo L_Comments :

 Note: Usually it is only a one row of comments. But, option is available for typing comments in as many rows as required.

Advantage is that after typing comments in, pressing (2X) {ENTER} with the same finger will finish every thing up.

At work, I some times process 20, 30 or more documents in a day. This rule will make it easier the work.

Would you try helping me to get around this.

I am on the continuous learning in iLogic and moving to APT. But, being a non-programmer, a lot more to go, I believe. I love it anyway: I can't do without customization.

 

Autodesk Inventor/Vault 2019 - Professional (@ home)

Autodesk Inventor/Vault 2018 - Professional (@ work)

 

0 Likes
Message 9 of 23

MjDeck
Autodesk
Autodesk

I don't think there's a way to drive the dialog with a rule while also interacting with the dialog to type in comments. You could do that with an external EXE that talks to Inventor. But an iLogic rule is more limited.

Here's a version of the rule that will let you enter comment lines. Instead of entering them in the dialog, you type them into standard input boxes. Enter a blank line to proceed. Then the rule feeds the lines to the dialog.

There's a limitation: if you have entered comments when you checked the file out, and you enter new comments here on check-in, the check-out comments will be lost. Unless you use an external EXE that could see the existing checkin comments, I don't think there's a way around that.


Mike Deck
Software Developer
Autodesk, Inc.

Message 10 of 23

RoyWickrama_RWEI
Advisor
Advisor

Thanks for taking time to help me.

The rule is not bad, because it leaves the option to type in comments. But, at the end, the document remains checked out. I can't ask you to spend more time on this. But, if you do, I shall be most grateful to you. Anyway, take your time and take it easy (no rush at all).

0 Likes
Message 11 of 23

MjDeck
Autodesk
Autodesk

I tested it with a part. It worked for me as long as the part does not require saving. Please try saving the part first, then run the rule.


Mike Deck
Software Developer
Autodesk, Inc.

Message 12 of 23

RoyWickrama_RWEI
Advisor
Advisor

Oh, yes. You are right. Thank you Sir.

Roy Wickrama

0 Likes
Message 13 of 23

RoyWickrama_RWEI
Advisor
Advisor

It is a solution. Sorry, I have no option to accept as a solution.

 

0 Likes
Message 14 of 23

RoyWickrama_RWEI
Advisor
Advisor

Thanks. It is working.

I changed a little bit so that the document is saved (in case not saved already). Also, activated the vault pane to take a look at Checked-In status.

option explicit on
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Sub Main
	ThisDoc.Save
	CheckIn()
End Sub

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetForegroundWindow(hWnd As IntPtr) As Integer
End Function
	
Sub CheckIn()
	Dim commentLines As New List(Of String)
	Dim line As String = String.Empty
	For i As Integer = 1 To 10
		Dim prompt = String.Format("Enter comment line {0}", i)
		line = InputBox(prompt, "Enter an empty line to proceed with checkin")
		If String.IsNullOrEmpty(line) Then Exit For
		commentLines.Add(line)
	Next
	SetForegroundWindow(ThisApplication.MainFrameHWND) ' Call this so that the main Inventor window will get the TAB key.
	Dim oCommandMgr As CommandManager = ThisApplication.CommandManager 
	Dim oControlDef = oCommandMgr.ControlDefinitions.Item("VaultCheckinTop")
    Call oControlDef.Execute2(False)
	Dim allForSend As String = String.Empty
	For i As Integer = 0 To commentLines.Count - 1
		allForSend = allForSend + commentLines(i) + If(i < commentLines.Count - 1, "{ENTER}", "" )
	Next
	allForSend = allForSend + "{TAB}{ENTER}" ' Tab to the OK key and hit Enter to click it.
    SendKeys.SendWait(allForSend)
    ThisApplication.UserInterfaceManager.DoEvents()
	oSub_VaultPane()
	

	
	
End Sub


Sub oSub_VaultPane()
Dim oCurrentPaneName As String
oCurrentPaneName = ThisApplication.ActiveDocument.BrowserPanes.ActivePane.Name

If oCurrentPaneName = "Model" Then
	ThisApplication.ActiveDocument.BrowserPanes.Item("Vault").Activate
Else 
	'if anything else toggle to Model
'	ThisApplication.ActiveDocument.BrowserPanes.Item("Model").Activate
End If
End Sub
0 Likes
Message 15 of 23

RoyWickrama_RWEI
Advisor
Advisor

Hi MjDeck;

 

I am using the rule you provided.

I accidentally hit enter button without data in for the 1st line of comments. I rather like the used is forced to input data for the 1st line.

 

Could you further revised the code so that checkin will go if data typed in for Line 1 (at least).

Thanks.

0 Likes
Message 16 of 23

MjDeck
Autodesk
Autodesk

You can check for at least one comment line by adding these lines of code after the "Next" line.

If commentLines.Count = 0 Then
	MessageBox.Show("Please enter at least one comment line", "File not checked in", MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Return
End If

Mike Deck
Software Developer
Autodesk, Inc.

Message 17 of 23

RoyWickrama_RWEI
Advisor
Advisor

Thanks a lot.

That. fine. COOL.

 

0 Likes
Message 18 of 23

Mike_Y2
Advocate
Advocate

I have tweaked this to go to select the third custom Iproperty, then select the "Value" field. Does anyone know how this could be changed so that...

 

In an assembly you select a part, then it would open the Iproperties for the selected part (selecting the third custom Iproperty, then select the "Value" field)

 

Sub Main()
	doc = ThisDoc.Document
	'check file type
	If doc.DocumentType = kPartDocumentObject Then
		oCmd = "PartiPropertiesCmd"
	Else If doc.DocumentType = kAssemblyDocumentObject Then
		oCmd = "AssemblyiPropertiesCmd"
	Else If doc.DocumentType = kDrawingDocumentObject Then
		oCmd = "DrawingiPropertiesCmd"
	End If

    Dim oCommandMgr As CommandManager 
    oCommandMgr = ThisApplication.CommandManager 
    Dim oControlDef As ControlDefinition 
    oControlDef = oCommandMgr.ControlDefinitions.Item(oCmd)

    Call oControlDef.Execute2(False)
	
	'Opens Iproperties and sends "right arrow" key 4 times and "TAB" key 2 times)
	SendKeys.SendWait("{Right 4}{TAB 2}{A}{DOWN 3}{TAB 2}")
	
	ThisApplication.UserInterfaceManager.DoEvents()
End Sub

 

0 Likes
Message 19 of 23

Curtis_Waguespack
Consultant
Consultant

Hi @Mike_Y2 

 

You can give this example a try.

 

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

 

Imports System.Windows.Forms

Sub Main()


oMsg = "Select a component (press ESC to exit select)"

Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(
SelectionFilterEnum.kAssemblyOccurrenceFilter, oMsg)

oOcc.Edit

Dim oDoc As Document
oDoc = oOcc.Definition.Document

'check file type
If oDoc.DocumentType = kPartDocumentObject Then
	oCmd = "PartiPropertiesCmd"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oCmd = "AssemblyiPropertiesCmd"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oCmd = "DrawingiPropertiesCmd"
End If

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef As ControlDefinition
oControlDef = oCommandMgr.ControlDefinitions.Item(oCmd)

Call oControlDef.Execute2(False)

'Opens Iproperties and sends "right arrow" key 4 times and "TAB" key 2 times)
SendKeys.SendWait("{Right 4}{TAB 2}{A}{DOWN 3}{TAB 2}")
ThisApplication.UserInterfaceManager.DoEvents()

Try
oOcc.ExitEdit(ExitTypeEnum.kExitToPrevious)
Catch
End Try

End Sub

 

EESignature

Message 20 of 23

Mike_Y2
Advocate
Advocate

@Curtis_Waguespack Thankyou!!!!

 

I have tweaked it to add a loop. You can therefore quickly edit a custom Iproperty for several parts in an assembly...

 

Imports System.Windows.Forms

 

'https://forums.autodesk.com/t5/inventor-customization/send-a-ctrl-tab-keystroke-to-iproperties-dialo...
Sub Main()
'Get user to close any open part files
'If part files are left open and the user selects that part file in the assemble THEN...
'Inventor will swap To the part file Then open the iProperties dialog box
oUserQ1 = MessageBox.Show("Close any open part files before using this rule" _
& vbCrLf & vbCrLf & vbCrLf & " Do you want to continue?", "Realm Toolkit", _
MessageBoxButtons.YesNo)

'Exit if the user selects No
If oUserQ1 = vbNo Then
Exit Sub
End If

'Loop until user presses ESC
Do
'Select the part
Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a component (Press ESC to exit select)")

'Exit if the user presses ESC
If oOcc Is Nothing
GoTo ExitSelectLoop
End If

'Edit the selected part
oOcc.Edit

Dim oDoc As Document
oDoc = oOcc.Definition.Document

'Check file type
If oDoc.DocumentType = kPartDocumentObject Then
oCmd = "PartiPropertiesCmd"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oCmd = "AssemblyiPropertiesCmd"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oCmd = "DrawingiPropertiesCmd"
End If

Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oControlDef As ControlDefinition
oControlDef = oCommandMgr.ControlDefinitions.Item(oCmd)

Call oControlDef.Execute2(False)

'Opens Iproperties and sends "right arrow" key 4 times and "TAB" key 2 times)
SendKeys.SendWait("{Right 4}{TAB 2}{A}{DOWN}{TAB 2}")
ThisApplication.UserInterfaceManager.DoEvents()

'Exit editting the selected part
Try
oOcc.ExitEdit(ExitTypeEnum.kExitToPrevious)
Catch
End Try
Loop
ExitSelectLoop:
End Sub