Saving New Part to Specified Folder

Saving New Part to Specified Folder

gbaker7NQNF
Participant Participant
386 Views
3 Replies
Message 1 of 4

Saving New Part to Specified Folder

gbaker7NQNF
Participant
Participant

I've written this code to automatically generate parts using a spreadsheet and a parameterized model. So far it has been working well. The only problem is that parts are saved to the same folder as the model. I would like to be able to select a save folder for the new parts, similar to how the .xlxs is selected at the beginning. A small handful of people will be using this for different purposes, so unfortunately I cant send everything to a set folder.

 

I'm new to iLogic and honestly, coding in general (This script is a Frankenstein's monster of whatever I could find online, I'm not even completely sure what everything means...) Any help would be greatly appreciated!  

 

 

 

Dim fd As OpenFileDialog = New OpenFileDialog()
Dim strFileName As String

fd.Title = "Select File For Data"
fd.Filter = "All Files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True

If fd.ShowDialog() = DialogResult.OK Then strFileName = fd.FileName

GoExcel.Open(strFileName,"Acrylic Cutting Schedule")

If strFileName = fd.FileName
	MessageBox.Show("Excel data successfully imported!")

Else 
	MessageBox.Show("Excel data import FAILED. Check File.")

End If


Dim sFilePath As String= ThisDoc.Path & "\"
Dim sNewName As String
Dim doc As Document = ThisDoc.Document
Dim xDoc As Document

For i = 14 To qty
	
 sNewName = GoExcel.CellValue("B" & i)
 doc.SaveAs(sFilePath & sNewName & ".ipt", True)
 xDoc = ThisApplication.Documents.Open(sFilePath & sNewName & ".ipt")
 Dim oPars As UserParameters = xDoc.ComponentDefinition.Parameters.UserParameters
 oPars.Item("width").Expression = "isolate(" & GoExcel.CellValue("D" & i) & ";in;in)"
 oPars.Item("height").Expression = "isolate(" & GoExcel.CellValue("I" & i) & ";in;in)"
 oPars.Item("thk").Expression = "isolate(" & GoExcel.CellValue("C" & i) & ";in;in)"
 xDoc.Save
 xDoc.Close(True)

Next i

GoExcel.Close
iLogicVb.UpdateWhenDone = True

 

 

0 Likes
Accepted solutions (1)
387 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Here is a handy post I found  to launch the folder dialogue for windows. You will need a different dialogue box specifically for folders.

 

A quick test of the sub routine to see the results

Sub Main
	AbsolutePathOfDialogBoxes()
End Sub
Private Sub AbsolutePathOfDialogBoxes()
  
    Dim dlgFolder = New FolderBrowserDialog
	dlgFolder.ShowDialog
    'Dim dlgOpenFile = New OpenFileDialog
    'Dim dlgSaveFile = New SaveFileDialog
    Dim absolutePath As String
    '/*-----------------------------------*/'
    absolutePath = dlgFolder.SelectedPath
    'absolutePath = dlgOpenFile.FileName
    'absolutePath = dlgSaveFile.FileName
    '/*-----------------------------------*/'
	MessageBox.Show(absolutePath, "absolutePath")

End Sub

Here is what you will need

Dim dlgFolder = New FolderBrowserDialog

'Set Root Path from where to start from
dlgFolder.SelectedPath = "C:\Temp"

dlgFolder.ShowDialog

Dim absolutePath As String = dlgFolder.SelectedPath

MessageBox.Show(absolutePath, "absolutePath")

 

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 4

gbaker7NQNF
Participant
Participant

Thanks! That worked Great! I have one other question while I'm here. I've been trying to figure out a way to loop the part generation until the end of the list in Excel. Currently I need to tell it how long to go, but that leaves room for user error which I would like to avoid.

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

If you  use the GoExcel.CellValues function you can return the values in a list Then you can either put that into a multivalue parameter in the document or directly to an arraylist. Once you make the row number larger than you need the arraylist will skip the blank cells and return only values. Then you can retrieve the count and your loop is then flexible. 

Storage Object (Arraylist)

Dim List As New ArrayList
List = GoExcel.CellValues("LinkedParameters.xlsx", "Sheet1", "A2", "A20")
MessageBox.Show(List.Count, "Title")

 Storage Object (MultiValue Parameter)

MultiValue.List("d0") = GoExcel.CellValues("LinkedParameters.xlsx", "Sheet1", "A2", "A20")
MessageBox.Show(MultiValue.List("d0").Count, "Title")
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes