Open Global Form/ Form based on Current Active Document

Open Global Form/ Form based on Current Active Document

CDuPlessisTQEZQ
Enthusiast Enthusiast
259 Views
2 Replies
Message 1 of 3

Open Global Form/ Form based on Current Active Document

CDuPlessisTQEZQ
Enthusiast
Enthusiast

Good day everyone.

 

I'd like some advise/code if possible on something I'd wish to do.

I made 3x different global forms, each representing a different "Current Active Document".

 

So, let's say I have a .ipt file open, be it a saved or not saved part. When this code runs I'd like it to then open the form I made for the .ipt file type, same for .idw and .iam files.

 

Problem is, I'm no programmer. I don't trust AI to do the job, nor the answers it gives me.

 

Is something like this possible? Opening a Global form, or any .xml file stored somewhere on my computer?

 

Thank you.

 

Inventor 2025, Vault 2025

0 Likes
Accepted solutions (1)
260 Views
2 Replies
Replies (2)
Message 2 of 3

mateusz_baczewski
Advocate
Advocate
Accepted solution

Hi,

Yes, it is possible. Create a rule and paste the code below. Let me know if this is what you meant.

Sub main
	
	Dim oExcel As Object
	oExcel = CreateObject("Excel.Application")
	
	oExcel.Visible = True  
	Dim wb As Object

	
	Dim oDoc As Document = ThisDoc.Document
	
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		iLogicForm.ShowGlobal(".iam FORM")
		wb = oExcel.Workbooks.Open("C:\Temp\iam.xlsx")
	Else If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
		iLogicForm.ShowGlobal(".ipt FORM")
		wb = oExcel.Workbooks.Open("C:\Temp\ipt.xlsx")
	Else If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject
		iLogicForm.ShowGlobal(".idw FORM")
		wb = oExcel.Workbooks.Open("C:\Temp\idw.xlsx")
	End If

End Sub
If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".

Message 3 of 3

CDuPlessisTQEZQ
Enthusiast
Enthusiast

Hi there Mateus.

 

Thank you, yes it works so far.

It pops up the forms as I need them... Only question is, this Excel spreadsheet that pops up every time?
I changed the 

oExcel.Visible = True 

to false, and there is no more Excel popup, but what I see is that it defiantly does something before opening the form.
I'm curious since I'd like to know if the response can happen faster at all? 

...

I tested it now, I commented out the line of code that has the file path linked to the .xml on it and it responses faster. 

 

Thanks again Mateus for the help.
I'll leave this post here for a few more hours if anybody wants to look at it or have something to say, but this works perfectly for me as an external rule:

Sub Main

	Dim wb As Object
	Dim oDoc As Document = ThisDoc.Document
	
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		iLogicForm.ShowGlobal("PROPERTIES - ASSEMBLIES")
	Else If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
		iLogicForm.ShowGlobal("PROPERTIES - PARTS")
	Else If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject
		iLogicForm.ShowGlobal("PROPERTIES - DRAWINGS")
	End If

End Sub