Inventor General

Reply
Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 11 of 19 (460 Views)

Re: SendKeys or Keystrokes Using iLogic

02-29-2012 02:21 PM in reply to: mehatfie

Annnnnnnd there's the road block.....

 

Using the methods you told me I was able to do exactly wat I needed and open the dialog box. This will work great for my simpler models.

 

Unfortunately, the dialog box pops up for the active document on screen only it seems. So with my assembly which uses various iLogic components and pushes dimensions given by a user down to each component, if I run this rule it will keep open the dialog box and supplying the information only for the assembly itself, while each component needs its seperate properties.

 

MY QUESTION IS:   Is there a way to open a component using iLogic from an assembly?

 

I attempted a few different things.

 

- I created a text parameter inside the component and used "ThisDoc.PathAndFile(False)" to get it's information. Then went to the Assembly and grabbed this parameter, attempting to launch it using "ThisDoc.Launch("path/file.ext")"  which I now realize is most likely for non-inventor documents

 

I tried this and a few other things just to see if I could figure it out by myself, but unfortunately I could not.

 

Thanks again for all your help

Mitch

 

 

Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 12 of 19 (457 Views)

Re: SendKeys or Keystrokes Using iLogic

02-29-2012 02:31 PM in reply to: mehatfie

Sorry, I've figured it out if anybody is interested and needs this later on. My users can change the file names of the documents and the links still stay intact through the "Copy Design" tool in The Vault

 

Which is why I need to get the filename directly from the component...

 

 

Format:HTML Format Version:1.0 StartHTML:     165 EndHTML:    1728 StartFragment:     314 EndFragment:    1696 StartSelection: 314 EndSelection:     314
SyntaxEditor Code Snippet

fname=Parameter("Outlet_Flange:1", "DocumentName")&".ipt"
doc=ThisApplication.Documents.Open(fname)

 

Cheers

Mitch

Employee
MjDeck
Posts: 957
Registered: ‎02-24-2009
Message 13 of 19 (458 Views)

Re: SendKeys or Keystrokes Using iLogic

02-29-2012 02:36 PM in reply to: mehatfie

You can do it with the following API code:
ThisApplication.Documents.Open(fullDocumentPathName, True)
I think that will also make it the active document.

If the document is a subassembly, you might want to open it in a specific level of detail.  To do that, add the level of detail name to the end of the path name, like this:
ThisApplication.Documents.Open("C:\Models\SubAssemblyA<LevelofDetail1>", True)



Mike Deck
Software Developer
DLS - Mechanical Design
Autodesk, Inc.

*Expert Elite*
Curtis_Waguespack
Posts: 2,773
Registered: ‎03-08-2006
Message 14 of 19 (447 Views)

Re: SendKeys or Keystrokes Using iLogic

02-29-2012 03:06 PM in reply to: mehatfie

Hi mhatfield,

 

Here's another example that demonstrates how to set an iproperty for each part in an assembly, just in case it comes in handy for your overall task.

 

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

 

 

'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document 

'kAssemblyDocumentObject = 12291 
If openDoc.DocumentType = 12291 Then

	'Iterate though the part files in the assembly
	For Each docFile In openDoc.AllReferencedDocuments
	
		'kPartDocumentObject = 12290 
		If docFile.DocumentType = 12290 Then
		
		'format  file name		
		Dim FNamePos As Long
            	FNamePos = InStrRev(docFile.FullFileName, "\", -1)	
	         
            	Dim docFName As String
		docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
			'toggle description value
			If iProperties.Value(docFName, "Project", "Description") <> "On"  Then
			'set description
			iProperties.Value(docFName, "Project", "Description") = "On"
			else if iProperties.Value(docFName, "Project", "Description") = "On" Then
			'set description
			iProperties.Value(docFName, "Project", "Description") = "Off"	
			End If			
		End If 
	Next	
	Else
	MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!")
End If 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Employee
MjDeck
Posts: 957
Registered: ‎02-24-2009
Message 15 of 19 (440 Views)

Re: SendKeys or Keystrokes Using iLogic

02-29-2012 03:18 PM in reply to: Curtis_Waguespack

Curtis,
 Instead of using the numeric constants, you can use the enum definitions by adding the type name:
If openDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject 


Also, this will work in iLogic and VB.NET code:
docFName = IO.Path.GetFileName(docFile.FullFileName)



Mike Deck
Software Developer
DLS - Mechanical Design
Autodesk, Inc.

*Expert Elite*
Curtis_Waguespack
Posts: 2,773
Registered: ‎03-08-2006
Message 16 of 19 (438 Views)

Re: SendKeys or Keystrokes Using iLogic

02-29-2012 03:24 PM in reply to: MjDeck

Thanks Mike!

 

 



  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.





Mentor
mehatfie
Posts: 163
Registered: ‎02-10-2012
Message 17 of 19 (427 Views)

Re: SendKeys or Keystrokes Using iLogic

03-01-2012 06:11 AM in reply to: Curtis_Waguespack

Thank you Mike and Curtis!

 

The active document code you provided did work with completing the task as well, and probably is a better idea, as then I know the add-in will recognize which document to open for, rather then opening prematurly for the assembly if the specific part has not opened yet.

 

That was going to be my next task Curtis, your a mind reader! Very helpful information. I've almost worked out all of the kinks in the model itself, and am moving on to the form and drawing soon. This iProperties code will definitly be used!

 

Thanks again for all your help

Mitch

 

 

*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 18 of 19 (365 Views)

Re: SendKeys or Keystrokes Using iLogic

06-11-2012 09:14 AM in reply to: Yijiang.Cai

Yijiang,

 

Why wouldn't you just use SendKeys? :catfrustrated:

 

Public Sub TestSendKeys()
SendKeys "{e}"
End Sub

 


Yijiang.Cai/Autodesk wrote:

Please create one part document first. When copying the code lines below in VBA Editor dialog and running macro, it will work fine, and this simulates to press the "E" key to create extrusion.

 

Thanks,
River

 

Option Explicit

 

Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP = &H101

 

Sub Main()
    Dim FT_hWnd As Long
    FT_hWnd = FindWindow(vbNullString, ThisApplication.Caption)

    Call PostMessage(FT_hWnd, WM_KEYDOWN, Asc("E"), 0&)
    Call PostMessage(FT_hWnd, WM_KEYUP, Asc("E"), 0&)
End Sub


 

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Valued Contributor
ACEDeSmedt
Posts: 79
Registered: ‎11-30-2008
Message 19 of 19 (220 Views)

Re: SendKeys or Keystrokes Using iLogic

02-11-2013 07:49 AM in reply to: jdkriek

I run SendKeys with the Following setup:

 

- Windows 7  bit

- Inventor 2012  bit

 

with VBA and I get the error: 70 - Permission denied.

If this is the solution, push the solution button :smileywink: (and maybe some kudos)
______________________________________________________
Autodesk Product Design Suit - Ultimate edition (Subscription)
Windows 7 (64bit) 12 Gb RAM - 2x Intel Xeon E5430

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube