Placing as a base view in drawing, after selecting multiple files in windows browser.

Placing as a base view in drawing, after selecting multiple files in windows browser.

BVasquez78MGR
Participant Participant
955 Views
7 Replies
Message 1 of 8

Placing as a base view in drawing, after selecting multiple files in windows browser.

BVasquez78MGR
Participant
Participant

This code works great, but it uses the assembly model to make the views. 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports System.IO
'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 = "Inventor"
oFileDlg.ShowOpen()

 But I wanna take the other approach in which I have these two codes, one an Ilogic and the other VBA that bring the open windows browser and lets you pick part files. On the logic one, I can't select multiple files and it is missing the base placement, as the right view on the cube, scale 1/4". 

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 = "Inventor"
oFileDlg.ShowOpen()

 The VBA code selects multiple files but does not load them as base view right views on the cube and @ 1/4 scale. 

 

 

Private Sub cmdSourceAdd_Click()
Dim oFileDlg As FileDialog
' Create a new FileDialog object.
Call ThisApplication.CreateFileDialog(oFileDlg)

' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt;*.idw;*.dwg)|*.iam;*.ipt;*.idw;*.dwg|All Files (*.*)|*.*"
' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1
oFileDlg.MultiSelectEnabled = True

' Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test"

' Set the initial directory that will be displayed in the dialog.
'oFileDlg.InitialDirectory = ThisApplication.FileOptions.ProjectsPath

' Set the flag so an error will be raised if the user clicks the Cancel button.
oFileDlg.CancelError = True

' Show the open dialog. The same procedure is also used for the Save dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
oFileDlg.ShowOpen
' oFileDlg.ShowSave

' If an error was raised, the user clicked cancel, otherwise display the filename.
If Err Then
MsgBox "User cancelled out of dialog"
ElseIf Not oFileDlg.FileName = "" Then
lstSource.AddItem oFileDlg.FileName
End If
End Sub

 

I would appreciate the help very much!!! not sure how to integrate to open the base view and set it as the top or right view @ 1/4 scale for all selected files. 

 

0 Likes
Accepted solutions (1)
956 Views
7 Replies
Replies (7)
Message 2 of 8

WCrihfield
Mentor
Mentor

Hi @BVasquez78MGR.  This single line of code from the VBA portion you posted, is the only different line that allows you to select multiple files, while the file dialog is showing.

oFileDlg.MultiSelectEnabled = True

...but none of the code you posted here appears to do anything with a drawing or views.  The only line of code I see that is doing something I don't understand is this one line in the VBA code:

lstSource.AddItem oFileDlg.FileName

I assume that is a collection type variable that was declared as Public or Shared outside of that Sub routine, and has something to do with your main drawing routine?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 8

BVasquez78MGR
Participant
Participant

I need the code to do the same as the first code, but rather than going thru a model assembly, I want to open the windows browser and select several .ipts and to a specific cube view at a 1/4" scale.  Not sure how to compose it, thru Ilogic.

0 Likes
Message 4 of 8

WCrihfield
Mentor
Mentor
Accepted solution

Hi @BVasquez78MGR.  Sorry about the long delay.  Been busier at work lately than usual, so less time to contribute.  I have written some code that I think should be of interest to you in this task, if not immediately useful.

 

Drawing automation in general is one of the most complex topics, and the complexity is multiplied almost exponentially by all all the different needs/styles/products/processes/standards/companies of random folks encountered online in these forums.  So, this code could probably be customized in thousands of ways, but this should be a fairly good step in the ladder towards your goals.  I have the file dialog part out in its own separate Function, to keep the main process (creating drawing views) more clean and to the point.  And since this code may be used for a single file & view, or multiple selected files and views, I also put the view creation code out into a separate Function.  That way I don't have to have two copies of mostly the same code.

You will most likely need to edit the insertion point location, view orientation, and view style to suit your needs, and may even want to place each view on a new sheet, instead of all on the same sheet, as it is now.  But pay attention to how I am dealing with the possibility of multiple files having been selected.  When that is the case, there will be several full file names end to end in one long string, separated by the "|" character.  I am using the Split function so separate them out, so I can work with each one.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDDoc.ActiveSheet
	Dim oViews As DrawingViews = oSheet.DrawingViews
	Dim oModelFile As String = UseOpenDialog
	If oModelFile = "" Then Exit Sub
	Dim oFiles As New List(Of String)
	If oModelFile.Contains("|") Then
		oFiles.AddRange(oModelFile.Split("|"))
	End If
	If oFiles.Count = 0 Then
		CreateBaseView(oSheet, oModelFile)
	Else
		For Each oFile In oFiles
			'could create a new sheet here to put each one on
			CreateBaseView(oSheet, oFile)
		Next 'oFile
	End If
End Sub

Function UseOpenDialog() As String 'just reaturns new full file name
	Dim oFileDialog As Inventor.FileDialog = Nothing
	ThisApplication.CreateFileDialog(oFileDialog)
	oFileDialog.DialogTitle = "Browse To Folder & Specify New File Name."
	oFileDialog.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	'oFileDialog.Filter = "Autodesk Inventor Files (*.iam;*.dwg;*.idw;*.ipt;*.ipn;*.ide) | *.iam;*.dwg;*.idw;*.ipt;*.ipn;*.ide | All files (*.*)|*.*"
	oFileDialog.Filter = "Inventor Files (*.ipt;*.iam;*.ipn)|*.ipt;*.iam;*.ipn" '(model type files only)
	'oFileDialog.FileName = ThisDoc.FileName(False)
	oFileDialog.MultiSelectEnabled = True
	oFileDialog.OptionsEnabled = False
	oFileDialog.InsertMode = False
	oFileDialog.CancelError = True
	Try
		oFileDialog.ShowOpen
		Return oFileDialog.FileName
	Catch
		Return ""
	End Try
End Function

Function CreateBaseView(oSheet As Sheet, oModel As String) As DrawingView
	If IsNothing(oSheet) Or String.IsNullOrEmpty(oModel) Then Return Nothing
	If Not System.IO.File.Exists(oModel) Then Return Nothing
	Dim oModelDoc As Document
	Try
		oModelDoc = ThisApplication.Documents.ItemByName(oModelv)
	Catch
		oModelDoc = ThisApplication.Documents.Open(oModel, False)
	End Try
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oP2D As Point2d = oTG.CreatePoint2d(3, 3)
	Dim oScale As Double = 0.25
	Dim oOrient As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kFrontViewOrientation
	Dim oVStyle As DrawingViewStyleEnum = DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle
	Dim oView As DrawingView = oSheet.DrawingViews.AddBaseView(oModelDoc, oP2D, oScale, oOrient, oVStyle)
	Return oView
End Function

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

BVasquez78MGR
Participant
Participant

You are awsome, Sir. that works great... THXS

0 Likes
Message 6 of 8

jnewon
Advocate
Advocate

@WCrihfield 

This is a great piece of code! I like how it works. Thanks for the contribution.

I would like to make a copy of this code and modify it to add a view based on a selection from the drawing model browser instead of selecting from open dialog. But I don't know how to get the selected file (ipt/iam) from the browser into ilogic. Is this possible?

 

jnewon_0-1683905405792.png

 

Thanks

John

 

0 Likes
Message 7 of 8

WCrihfield
Mentor
Mentor

Hi @jnewon.  You are welcome to copy and modify that code all you want.  But I do not think selecting a model from the browser tree of an already open drawing will work here.  First of all, we can sometimes select browser nodes in the model browser by code and get something meaningful from them, but not always.  And there is no selection filter for regular BrowserNode type objects that we can use in the Pick function either, just one for custom browser nodes.  Sometimes we can navigate the model browser tree by code, but it can be fairly difficult.  If it is being shown in the model browser of the drawing you have open, then the drawing is referencing that model file, and you may be able to get that model file from the DrawingDocument.AllReferencedDocuments collection.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 8

jnewon
Advocate
Advocate

@WCrihfield 

Thanks for the reply.

It seems odd that information can't be gotten. I say that because you can select the part (right click) and open the file location and it opens the folder and highlights the part. The info is there. Is there a way via a macro (VBA) to achieve?

 

I only ask to streamline a workflow. I typically have to open the part then return to the idw and place base view. Since the part I opened was last active the base view will be the part I want. I want to skip the whole opening the part and back to the idw. If this make any sense.

 

I think it would be nice to have an option to "place view" right under the "open file location" when you right click on the part. Maybe I will put it in the idea forum.

 

 

jnewon_1-1683919648909.png

 

 

Thanks

John

0 Likes