iLogic Quick Tip: File Open Dialogue

If you’ve ever written code that needs to open or import another file, you may find this useful.

When building product configurators, I like to use XML files as a means of storing all of the parameters for a specific “build” of a product, the benefits are that I don’t have to store and manage thousands of files, for the same reason I like to use PDF’s as a snapshot of the drawings, have a look at this post to learn more.

With that pre-amble out of the way, here is the code that I use to access the “File Open” dialogue, I have commented the code and set it up in such a way that you will be able to easily set it up to open all of the Inventor native and 3rd party file types, as well as XML files, again, check out the “XML post” for more details on using this code in practice.

'iLogic code by @ClintBrown3D, https://clintbrown.co.uk/ilogic-quick-tip-file-open-dialogue 
'Create File Open Dialogue
oDoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

'3rd Party File formats:
o1 = "3rd Party Files |*.wire; *.CATpart; *.CATproduct;*.dlv3;"
o2 = "*.fusiondesign; *.igs; *.iges; *.jt; *.prt; *.obj; *.x_b; *.x_t; *.g; *.neu;"
o3 = "*.prt; *.asm; *.rvt; *.3dm; *.sat; *.smt; *.stp; *.ste; *.step; *.stpz; *.stl;"
o4 = "*.stlb; *.par; *.psm; *.asm; *.prt; *.sldprt; *.sldasm; *.model; *.session; *.exp"

'Choose the "File Type" by uncommenting one of the options below:
'For "ALL file Types" Comment out all lines in this section
'oFileDlg.Filter = "Drawing Files (*.dwg) (*.idw)|*.dwg; *.idw"
'oFileDlg.Filter = "Part Files (*.ipt)|*.ipt"
'oFileDlg.Filter = "Assembly Files (*.iam)|*.iam"
oFileDlg.Filter = "XML files (*.xml)|*.xml"
'oFileDlg.Filter = o1 & o2 & o3 & o4 ' 3rd Party Files

'Set open location using one of these 2 options below, "1)Hard coded" or "2)Project location":
'oFileDlg.InitialDirectory = "C:\TEMP\"  'Hard Coded path:
oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath

'Show File Open Dialogue
oFileDlg.DialogTitle = "Unofficial Inventor"
oFileDlg.ShowOpen()
ClintBrown3D = oFileDlg.FileName
If ClintBrown3D = "" Then : Return : End If

One thought on “iLogic Quick Tip: File Open Dialogue

Comments are closed.

Create a website or blog at WordPress.com

Up ↑