Place multiple parts from folder into sequential .dwg sheets

Place multiple parts from folder into sequential .dwg sheets

sbulowPFMJG
Contributor Contributor
261 Views
2 Replies
Message 1 of 3

Place multiple parts from folder into sequential .dwg sheets

sbulowPFMJG
Contributor
Contributor

Hello, 

 

For context here is my current workflow:

1) Model my assembly as several solid bodies in a part file (.ipt)

2) Make components from the solid bodies and save them in a specific folder

3) Open a .dwg (with custom iLogic rule) and place each component in its own sheet. 

              This step can take time when there are a lot of components. 

4) Run ilogic rule 

 

I'm hoping to get some help with step #3. 

Are there any ilogic functions which can place parts into drawings directly from a folder path?

 

Would it be realistic to place all the parts I need on the first sheet, then run some code to move them each to their own sheets. 

 

Any suggestions/ideas are welcome. 

 

Thanks!!

 

 

0 Likes
262 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor

Here is the VBA sample for placing views from a filepath  belonging to an assembly. It will have a few more options than you need  so  those can be removed. Learning how to rework samples is good practice and much shorter than going from scratch. 

 

Remove:

' Set the representations to use when creating the base view.
  Call oBaseViewOptions.Add("PositionalRepresentation", "MyPositionalRep")
  Call oBaseViewOptions.Add("DesignViewRepresentation", "MyDesignViewRep")

Also remove the optional argument "MyLODRep" from the document name. 

 

Remove the word Set and remove the sub... and end sub. How you get the filepath is entirely up to how your current ilogic code is set up and where you want to launch from. Can you share those for context? We should be able to piece together the workflow. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

A.Acheson
Mentor
Mentor

Here is a post that has the file selection from a folder or individual files.

Sub Main
	TestFileDialog()
End Sub
	
Dim sFiles As New List (Of String)
	
Public Sub TestFileDialog()
    ' Create a new FileDialog object.
    Dim oFileDlg As Inventor.FileDialog
     ThisApplication.CreateFileDialog(oFileDlg)

    ' Define the filter to select part and assembly files or any file.
    oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"

    ' Define the part and assembly files filter to be the default filter.
    oFileDlg.FilterIndex = 1

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

    ' Set the initial directory that will be displayed in the dialog.
    oFileDlg.InitialDirectory = "C:\Users\Enter Name Here"
	oFileDlg.MultiSelectEnabled = True
'    oFileDlg.ShowSave
	 Check = InputRadioBox("Prompt", "Process Files", "Process a Folder", Check, Title := "Choose what to Process")
	  ' Show the open dialog.  The same procedure is also used for the Save dialog.
 	
	 Dim mylist As List(Of String)
	 If Check = True Then 
		 oFileDlg.ShowOpen
		If oFileDlg.FileName = Nothing Then
	    ElseIf oFileDlg.FileName <> "" Then
			'Process the multi selected files which form a  pipe like "C\123.ipt|C\124.ipt"
			mylist = oFileDlg.FileName.Split("|").ToList
			For Each item In mylist
				sFiles.add(item.ToString)
			Next
		 End If
	 ElseIf Check = False Then
		   MessageBox.Show("Choose any file to process the folders content", "iLogic")
		   oFileDlg.ShowOpen
			Dim sPath As String
			Try	
			   sPath = IO.Path.GetDirectoryName(oFileDlg.FileName)			 
                     
                 CheckFolder(sPath)
			Catch
			End Try
	 End If

	d0 = InputListBox("Prompt", oFiles, d0, Title := "FileList", ListName := "FileList")

	For Each sFile As String In sFiles
            DrawingCreate(sFile)
	Next
	'Clear the list
	sFiles.clear
End Sub

Sub CheckFolder(sPath As String)

Dim sFiles As String() = System.IO.Directory.GetFiles(sPath) 

For Each sFile As String In sFiles 
	'Logger.Info("FilesInFolder" & sFile)
	'Get Extension
	Ext = System.IO.Path.GetExtension(sFile)
	'Target only these extensions
	If Ext = ".ipt" Or Ext = ".iam" Then
		Dim sFileName As String = System.IO.Path.GetFullPath(sFile)
		sFiles.add(sFileName)
	End If
Next
End Sub


Sub DrawingCreate(sFileName As String)
	
     MessageBox.Show("FileName: " & sFileName)

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes