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

Place assembly view from dialog box

jishee
Enthusiast

Place assembly view from dialog box

jishee
Enthusiast
Enthusiast

I have some iLogic written to place a view of an assembly in my drawing sheet to the scale I want. Is there a way to use a dialog box to select the assembly file I want to use rather than specify the full path in the code?

0 Likes
Reply
Accepted solutions (1)
392 Views
3 Replies
Replies (3)

jishee
Enthusiast
Enthusiast

Here is the code.

 

Dim oPartDoc As AssemblyDocument
oPartDoc = ThisApplication.Documents.Open("C:\Users\jishee\Documents\Work\Inventor_modeling\Dimensioning_Test\U001_Assembly.iam", False)

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(oPartDoc, oPoint1, 0.03125#, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle)

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

Call oPartDoc.Close(True)
0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

I added i filebrowser to select iam file to your code. Is this what you're looking for? :slightly_smiling_face:

 

Dim oDlg As Inventor.FileDialog
ThisApplication.CreateFileDialog(oDlg)
oDlg.Filter = "Inventor Assembly Files (*.iam)|*.iam"
oDlg.ShowOpen() ' to open files


If oDlg.FileName = "" Then Exit Sub

Dim oPartDoc As AssemblyDocument

oPartDoc = ThisApplication.Documents.Open(oDlg.FileName, False)

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(oPartDoc, oPoint1, 0.03125#, kFrontViewOrientation, kHiddenLineRemovedDrawingViewStyle)

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

Call oPartDoc.Close(True)
0 Likes

JhoelForshav
Mentor
Mentor

@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)
0 Likes