Opening File to Edit with vba script

Opening File to Edit with vba script

georg_hartmannV6HPW
Explorer Explorer
788 Views
3 Replies
Message 1 of 4

Opening File to Edit with vba script

georg_hartmannV6HPW
Explorer
Explorer

Hello everyone,

I am starting to lose some of my marbles.

I want to use a script in vba, that opens an inventor part and allows the user to edit the file.

 

my code is as follows:

Dim InvApp, InvDoc
Dim fso, fullPathToFile,strFileName

Sub main()
	'On Error Resume Next
    wscript.Echo(">>> FileOpener v1  <<<")

    ' Initialize Inventor
    set InvApp = CreateObject("Inventor.Application")
    InvApp.Visible = True 
    
    ' Generate absolute filepath to CAD-File 
    strFileName = Wscript.arguments(0)
    set fso = CreateObject("Scripting.FileSystemObject")
    fullPathToFile = fso.GetAbsolutePathName(strFileName)

    Set InvDoc = InvApp.Documents.open(fullPathToFile,true)

End Sub

 

 

the problem with this is, that the tabs for 3D modeling and sketch and so on are missing.

georg_hartmannV6HPW_0-1740736138733.png

 

When I open the part manually, everything is there

georg_hartmannV6HPW_1-1740736195265.png

 

i went through all documentation, that i could find, used chat gpt and my colleagues, but still i have no answer.

 

 

 

I added

    InvApp.UserInterfaceManager.ActiveDocument.Update

 

and tried

InvApp.UserInterfaceManager.ResetRibbonInterface() 
InvApp.UserInterfaceManager.Ribbons.Item("Part")
InvApp.UserInterfaceManager.Update
InvApp.UserInterfaceManager.ActivateTab("Id_Part")

 

But it only adds the tabs for 1-2 seconds and removes them afterwards.

 

Does anybody now how to set the tabs, when I open it by script??

 

Best regards

Georg

 

0 Likes
789 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @georg_hartmannV6HPW.

  • What environment are you starting this code from?
  • Are you writing this code from within the VBA Editor dialog that can be found within Inventor, on the Tools tab, after it has been installed?
    • If so, then there is no need to 'create' an instance of Inventor, because it will already be running, and you can use the 'ThisApplication' object, which will already represent the Inventor.Application object.
  • Or is it in a VBA editor of something like Excel?
  • Or is this not really VBA at all, but some other coding language?
  • Are you trying to use this code from within an iLogic rule?
  • What is "wscript" in that code example supposed to be?  (it is being used with two different capitalization states, so that may be another issue)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

georg_hartmannV6HPW
Explorer
Explorer

Hello,

 

I am starting from a console command from which i call a wsf with multiple operations so as an example:

cscript //Job:fileOpener CADInterface.wsf CAD_filepath

 

The Wscript is the command line input so the "CAD_Filepath" that is written in the commandline.

 

 

The part of the wsf is :

	</job>
	
		<job id="fileOpener">
		<reference guid="d98a091d-3a0f-4c3e-b36e-61f62068d488"/>
		<script language="VBScript" src="scripts/fileOpener.vbs"/>
		<script language="VBScript">
			main()
		</script>
	</job>

 

I start with everything closed.


 

BR

Georg

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Thank you for the additional information.  That helps a lot.  Unfortunately, I know nothing about console coding or 'VBScript', so I will likely not be able to help much in this specific case.  About all I know is that I have read that VBScript is very different than either VBA or VB.NET, and is essentially a 'lighter' coding language for smaller 'scripting' tasks, rather than for full desktop application development.  Hopefully some of the others here in the forum will look into this for you, and be able to help more.  Good luck.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes