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