0

I am trying to add a macro to interface with a plugin we recently added for Inventor that saves the file in a format specific to another program. It is not using the 'save as' interface within Inventor, but the window that pops up when it is triggered looks just like a standard 'save as'. It also has almost nothing that talks to Inventor for using within VBA. The best I can do is mimic "pushing the macro button" that the plugin uses and enter the filename/path there.

I can get VBA to essentially 'push the button' using the following code, but nothing I have tried so far will enter text into the 'save as' box that comes up. I have to believe this is a really simple thing I'm missing, but sendkeys and just about any variation I have tried won't work. I'm guessing I need to first tell it 'what' window to send the keys to? Everything I'm finding is Excel specific and the commands/syntax don't work with Inventor.

Dim OpenXMLExporter As CommandManager
Set OpenXMLExporter = ThisApplication.CommandManager

Dim OpenXMLExporterForReals As ControlDefinition
Set OpenXMLExporterForReals = OpenXMLExporter.ControlDefinitions.Item("Autodesk:InventorFlat:ExportCmdBtn")

Call OpenXMLExporterForReals.Execute

So at this point Inventor has the 'save as' dialog box of the plugin open, but I can't get it to fill a name/path, let alone click the enter button.

5
  • this might help stackoverflow.com/questions/12374592/… Commented Apr 12, 2024 at 18:23
  • another one vbaexpress.com/forum/… Commented Apr 12, 2024 at 18:25
  • stackoverflow.com/questions/51237550/… may be useful Commented Apr 12, 2024 at 18:36
  • If you already know the path and filename, then why do you need to prompt the user with a dialog? Commented Apr 12, 2024 at 20:07
  • Thanks! So it sounds like I just need to iterate thru all open windows until I find the right one, then sendkeys to that location. "New" to vba doesn't even begin to describe my level here but I get the core concept of "what/how". (I learned Fortran) @braX- this is part of a much larger automated code. It isn't prompting anything from the user, it's running thru all part files within an open assembly and kicking out the extension this plug-in creates. Getting the filenames/paths/etc is easy and already being done, just trying to add this new filetype Commented Apr 13, 2024 at 0:03

1 Answer 1

0

If the plugin uses standard SaveAs dialog, you can bypass them using CommandManager.PostPrivateEvent Method

You can prepare path and file name and the FileDialog consumes them. Method PostPrivateEvent must be called before the plugin starts export.

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "C:\Temp\01.ipt")

EDIT:

Full VBA sample

Dim dataType As PrivateEventTypeEnum
dataType = PrivateEventTypeEnum.kFileNameEvent

Dim data As Variant
data = "C:\Temp\01.ipt"

Dim cmdManager As CommandManager
Set cmdManager = ThisApplication.CommandManager

Call cmdManager.PostPrivateEvent(dataType, data)

'Run the code which displays the FileDialog
'Value "C:\Temp\01.ipt" will be passed to the dialog.
'For example:
Call ThisApplication.Documents.Add(kPartDocumentObject).Save()
Sign up to request clarification or add additional context in comments.

4 Comments

That seems FAR simpler than searching for the window, but when I try that it highlights the 'postprivateevent' portion and gives me a compile error: "Argument not optional". I had to change the last comma to an equals sign per the initial error this gave me but I'm not sure what other definition it's looking for now.
Method PostPrivateEvent requires two arguments. You need to pass both of them. More readable sample was added.
ok, 95% certain I follow this. But when I run this combined with the portion that triggers the 'save as' box (running what you wrote first) it doesn't go any further than that. I assume that means it's not 'actually' a 'save as' box and therefore this won't work? The dialog box doesn't say 'save as' in the top left like they normally do, just the name of the (vendor-supplied) macro with a custom icon. Everything is still worded as 'save as' in the bottom of the box and it looks just like a standard Windows 'save as', but it must not be?
Your last chance is to check if the FileUIEvents.OnFileSaveAsDialog event occurs. You can use EventWatcher.exe from SDK for it. If it doesn't occurs, you need to contact the vendor for support. Hypothetically you can use Addin.Automation (if the addin provides some, by default it is null) or check if it is a TranslatorAddIn, but it is not a general solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.