iLogic form Select filetypes to save at custom location

iLogic form Select filetypes to save at custom location

op_thorsager
Enthusiast Enthusiast
446 Views
4 Replies
Message 1 of 5

iLogic form Select filetypes to save at custom location

op_thorsager
Enthusiast
Enthusiast

Hello,

 

I am currently setting up a form which changes parameters according to values specified within an excel sheet which you select through an explorer window. 

Everything works as it should, and now i've moved on to set up the export code.

 

op_thorsager_0-1674203678458.png

In the picture above is how i want the layout to be, where you can select and deselect the filetypes you want to save. I have a snippet to save files in a specified location through explorer, however it only saves one file. Is there a way to run a true/false argument, deciding which filetypes you want to save? the process i had in mind for the final product would look like this:

Check parameters(click button to verify necessary parameters, if not in project, it will create them) -> select excel spec sheet file(it can be any excel file as long as it follows a template i've made)->select filetypes you want to save by using checkboxes -> then i want a button where it says "Select save file location and run" where you will be prompted with an explorer window, where you select the folder you want to save files to. then i want a seperate button which just says "save". After hitting save, Inventor will save a the filetypes selected to the location you specified through explorer. My initial thought would be to save a copy of the current assembly file to ensure the person using my tool only uses the initial assembly as a base which will always be a default setup. the assembly copy which the user can select or deselect whether or not they want it, will be an updated version using the imported parameter values from excel. 

 

With the PDF i want it to be a sheet file for production drawings. I am yet to make the iLogic part of the sheet setup. Is there a way to have it save a sheet file without opening the sheet? i want everything to run through the assembly without too much hassle, and i am fairly new to iLogic/VB, so i don't know what my options are on this matter. Titleblock in the sheet will also use the excel sheet, so i think it would be possible to have it save a sheetfile without opening up the actual drawing before saving to pdf.

 

Any help is appreciated - sorry for the long post.

The project is currently under NDA, so if any code is needed i will post it, but without any companyrelated information 🙂 

0 Likes
Accepted solutions (1)
447 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

A lot to digest there in your post. Can you post the various codes thst your using and where you want to start. Is the form an ilogic/ winform made in visual studio? Ilogic forms are great for simple items but become a real pain when you want to condense and streamline the operations. The ilogic form doesn't have check boxes like hour showing as it only has True false drop down. 

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 5

op_thorsager
Enthusiast
Enthusiast

Of course, the code is built with iLogic, i'm not familiar with VB yet, but i want to get started with it at some point. 

the first code here is for the excel parametric value puller (when selecting a spec sheet to load)

 

 

'Iventor File Dialog
Dim oFileDlg As Inventor.FileDialog
Dim oDocFile As Document, oDocFileName As String
'Run File Selection Code
InventorVb.Application.CreateFileDialog(oFileDlg)

'Allow Selection Of Excel Files
oFileDlg.Filter = "Excel Spec Sheet (*.xls;*.xlsx;*xlsm)|*.xls;*.xlsx;*xlsm"

'Get File Path, setting the initial path to the same folder that the model is saved In.
oFileDlg.InitialDirectory = ThisDoc.Path
oFileDlg.CancelError = True
On Error Resume Next

'Show Open File Dialog Window.
oFileDlg.ShowOpen()

If oFileDlg.FileName = "" 
	MessageBox.Show("No File Selected", "Error")

GoTo LAUNCH_FORM
End If


'declares selected file name
Dim xSpec As String = oFileDlg.FileName
'Set Filename parameter to the path.
	Parameter("Filename") = xSpec
	Parameter("Veneer:1", "VeneerDepth") = VeneerDepthBuild
	Parameter("Veneer:1", "VeneerWidth") = VeneerWidthBuild
	Parameter("Veneer:1", "VeneerHeight") = VeneerHeightBuild
	Parameter("CrossBar:1", "CrossH") = CrossHeightBuild
	Parameter("CrossBar:1", "CrossD") = CrossDepthBuild
	Parameter("CrossBar:1", "CrossW") = CrossWidthBuild
	Parameter("CrossBar:2", "CrossH") = CrossHeightBuild
	Parameter("CrossBar:2", "CrossD") = CrossDepthBuild
	Parameter("CrossBar:2", "CrossW") = CrossWidthBuild
	Parameter("CrossOffBot") = CrossOffBuild
	Parameter("CtopOffset") = CtopOffsetBuild
	GoExcel.Open(xSpec, "Driver")
VeneerHeightBuild = GoExcel.CellValue(xSpec, "Driver", "B7")
VeneerDepthBuild = GoExcel.CellValue(xSpec, "Driver", "C7")
VeneerWidthBuild = GoExcel.CellValue(xSpec, "Driver", "D7")
CrossHeightBuild = GoExcel.CellValue(xSpec, "Driver", "B6")
CrossDepthBuild = GoExcel.CellValue(xSpec, "Driver", "C6")
CrossWidthBuild = GoExcel.CellValue(xSpec, "Driver", "H12")
CrossOffBuild = GoExcel.CellValue(xSpec, "Driver", "H7")
CtopOffsetBuild = GoExcel.CellValue(xSpec, "Driver", "H8")
FirstVeneerOffset = GoExcel.CellValue(xSpec, "Driver", "-H6")
ModuleDim = GoExcel.CellValue(xSpec, "Driver", "D6")
	GoExcel.close

'ask if user wants to update dialog
question = MessageBox.Show("Update model To spec sheet?", "Gen v.3", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
	If question = vbYes Then
		Parameter.UpdateAfterChange = True
		iLogicVb.UpdateWhenDone = True
		Parameter("Filename") = xSpec
		Parameter("Veneer:1", "VeneerDepth") = VeneerDepthBuild
		Parameter("Veneer:1", "VeneerWidth") = VeneerWidthBuild
		Parameter("Veneer:1", "VeneerHeight") = VeneerHeightBuild
		Parameter("CrossBar:1", "CrossH") = CrossHeightBuild
		Parameter("CrossBar:1", "CrossD") = CrossDepthBuild
		Parameter("CrossBar:1", "CrossW") = CrossWidthBuild
		Parameter("CrossBar:2", "CrossH") = CrossHeightBuild
		Parameter("CrossBar:2", "CrossD") = CrossDepthBuild
		Parameter("CrossBar:2", "CrossW") = CrossWidthBuild
		Parameter("CrossOffBot") = -CrossOffBuild
		Parameter("CtopOffset") = CtopOffsetBuild

	Else If question = vbNo Then
		Parameter.UpdateAfterChange = False
		iLogicVb.UpdateWhenDone = False
		Parameter("Veneer:1", "VeneerDepth") = DefaultVD
		Parameter("Veneer:1", "VeneerWidth") = DefaultVW
		Parameter("Veneer:1", "VeneerHeight") = DefaultVH
		Parameter("CrossBar:1", "CrossH") = DefaultCH
		Parameter("CrossBar:1", "CrossD") = DefaultCD
		Parameter("CrossBar:1", "CrossW") = DefaultCW
		Parameter("CrossBar:2", "CrossH") = DefaultCH
		Parameter("CrossBar:2", "CrossD") = DefaultCD
		Parameter("CrossBar:2", "CrossW") = DefaultCW
	End If
	
LAUNCH_FORM:
iLogicForm.Show("Pruduct Generator")

 This code is for checking if parameters are available within the project, if not - they will be created

oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
Try
'Change value of param
Parameter("DefaultVH") = Parameter("DefaultVH")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("DefaultVH", 240, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("DefaultVW") = Parameter("DefaultVW")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("DefaultVW", 3, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("DefaultVD") = Parameter("DefaultVD")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("DefaultVD", 3, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 

Try
'Change value of param
Parameter("DefaultCH") = Parameter("DefaultCH")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("DefaultCH", 5, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("DefaultCD") = Parameter("DefaultCD")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("DefaultCD", 1.2, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("DefaultCW") = Parameter("DefaultCW")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("DefaultCW", 59.8, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("VeneerHeightBuild") = Parameter("VeneerHeightBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("VeneerHeightBuild", 240, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("VeneerWidthBuild") = Parameter("VeneerWidthBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("VeneerWidthBuild", 6, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("VeneerDepthBuild") = Parameter("VeneerDepthBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("VeneerDepthBuild", 3, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("CrossDepthBuild") = Parameter("CrossDepthBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("CrossDepthBuild", 1.2, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("CrossHeightBuild") = Parameter("CrossHeightBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("CrossHeightBuild", 4, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("CrossWidthBuild") = Parameter("CrossWidthBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("CrossWidthBuild", 59.8, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("CrossOffBuild") = Parameter("CrossOffBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("CrossOffBuild", 0.2, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("CtopOffsetBuild") = Parameter("CtopOffsetBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("CtopOffsetBuild", 0.2, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("FirstVeneerOffsetBuild") = Parameter("FirstVeneerOffsetBuild")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("FirstVeneerOffsetBuild", 1.2, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("VeneerSpacing") = Parameter("VeneerSpacing")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("VeneerSpacing", 3, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("ModuleDim") = Parameter("ModuleDim")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("ModuleDim", 6, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("CrossDist") = Parameter("CrossDist")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("CrossDist", 6, UnitsTypeEnum.kMillimeterLengthUnits)
End Try 
Try
'Change value of param
Parameter("Filename") = Parameter("Filename")
Catch
'Create Param as it doesn't exist
oParameter = oMyParameter.AddByValue("Filename", "0", UnitsTypeEnum.kTextUnits)
End Try 


 This is all i have so far. The rest of my codes are non-functioning, or doesn't do what i want it to do. i don't know if you still want it posted. 

 

This is the save 3d file code. I wanted it to create a subfolder called  "3D" where it would save the STEP/STP file, .iam and .ipt files when boxes are checked. 

Was thinking this would be possible by creating a true/false parameter, so if export step file is checked off, for example. then it will have this code run. but only once you press save in the form. as it is right now, it will try to save the file immediately. I want it to wait a bit with the file dialog, since i want to be able to have the DWG/PDF file saved in another subfolder called "2D" in the same folder as "3D" is set to be created.

oDoc = ThisDoc.Document
oPath = ThisDoc.Path
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If
oFileDlg.InitialDirectory = ThisDoc.WorkspacePath()
oFileDlg.FileName = iProperties.Value("Project", "Part Number")
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowSave()
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
'get Output target folder path
oFolder = oFileDlg And "\3D\"

'Check for the Outputs folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

MyFile = oFileDlg.FileName
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As
End If

 

Is it possible to have it create a 2d sheet with all necessary information pulled from excel, without having to open the sheet view? or would it be possible to have the sheet view assembly update without opening the .iam? ideally i just want on tab open in the filebrowser. I just haven't been able to figure out the approach to this. 

 

Edit: attatched excel file used to drive .iam parameters

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Just a quick correction.  You can actually use a checkbox within an iLogic form.  You just have to change the 'Edit Control Type' setting of that Boolean Parameter's line item, from True/False, to Check Box.

WCrihfield_0-1674483898082.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

op_thorsager
Enthusiast
Enthusiast
Accepted solution

Solved my issue - its fully functioning where it waits the save until "save" button in the bottom of my form is pressed, filetypes can be selected with checkbox as i was talking about.

 

code:

' Declare the file location and subfolder name variables

Sub Main()
Export
	If SaveAssembly Then
SaveFile
End If
	If SaveSTP Then
		STPsave
	End If
	
End Sub

Sub SaveFile
	' Save the current document to the new subfolder
	TopDoc.SaveAs(Path3D & FileNaming & ".iam", True)
End Sub
Dim Path3D As String
Dim Path2D As String
Dim TopDoc As Document

Sub STPsave
	' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oOptions.Value("ApplicationProtocolType") = 2
    ' Other options...
    'oOptions.Value("Author") = ""
    'oOptions.Value("Authorization") = ""
    'oOptions.Value("Description") = ""
    'oOptions.Value("Organization") = ""
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    Dim oData As DataMedium
    oData = ThisApplication.TransientObjects.CreateDataMedium
    oData.FileName = Path3D & FileNaming & ".stp"
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
End If
End Sub
Sub Export
Dim filePath As String
Dim subFolderName As String
TopDoc = ThisDoc.Document
' Prompt the user to select the file location
subFolderName = FileNaming
Dim FolderBrowserDialog1 As New FolderBrowserDialog
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
	filePath = FolderBrowserDialog1.SelectedPath
	' Create the subfolder
	Path3D = filePath & "\" & subFolderName & "\3D\"
	Path2D = filePath & "\" & subFolderName & "\2D\"
	
	If Not IO.Directory.Exists(filePath & "\" & subFolderName) Then
		IO.Directory.CreateDirectory(Path3D)
		IO.Directory.CreateDirectory(Path2D)
	End If
End If
End Sub
0 Likes