Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
JhoelForshav
in reply to: JhoelForshav

@jishee 

Here is an example if you want to be able to select ipt and ipn  aswell.

Also in this example i added code so that if the file is already open in inventor, it doesnt close it when the rule is done.

If it isn't already open however, the file gets closed like in the previous code.

 

Dim oDlg As Inventor.FileDialog
ThisApplication.CreateFileDialog(oDlg)
With oDlg
	.Filter = "Assembly File (*.iam)|*.iam" _
	& "|Part File (*.ipt)|*.ipt" _
	& "|Presentation File (*.ipn)|*.ipn" 
	.FilterIndex = 1
	.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
End With
'oDlg.Filter = "Inventor Assembly Files (*.iam)|*.iam"
oDlg.ShowOpen() ' to open files

If oDlg.FileName = "" Then Exit Sub

Dim oDoc As Document
Dim CloseWhenDone As Boolean = False
Try
oDoc = ThisApplication.Documents.ItemByName(oDlg.FileName) 'Get the document if it's already open.
Catch
oDoc = ThisApplication.Documents.Open(oDlg.FileName, False)
CloseWhenDone = True 'If document wasn't already open, close it again after view is placed.
End Try

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
	
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint1 As Point2d
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(4.5#, 6#)
	
Dim oView1 As DrawingView
oView1 = oSheet.DrawingViews.AddBaseView(oDoc, oPoint1, 0.03125#, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle)

ActiveSheet.View(oView1.Name).SetCenter(4.5, 6)

If CloseWhenDone Then oDoc.Close(True)