Does anyone know what the code for prompting a user to select which sheets to export as DXF's might entail? I think an input box with a populated radio group would be the best option here. Maybe a for loop adding 1 To ThisDoc.Document.Sheets.Count to a msgbox variable? Ideally it would remember This choice for the next time as well. Help appreciated, Thanks!
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
Hi,
Since you mentioned ThisDoc, I assume you are playing with iLogic.
I've written an article on this:
http://adndevblog.typepad.com/manufacturing/2014/07/list-sheet-names-in-ilogic-form.html
Cheers,
I appologize for the late reply. I have been on another project and have not had time to work on this. I never thought of launching a rule from a form. That seems like an effecient way to solve the problem. I will see what I can do to modify my existing code. I am thinking that only way to do this would be through check boxes in a form (attached). The main problem here being that a parameter would be required for each sheet, and the number of parameters would vary. This would mean a loop to remove all "sheet_#" boolean parameters would have to run, and then a loop to add back the new ones. Then the main problem would be coming up with code to update the form with the added/removed parameters. I am not sure if the later is even possible 😞
Here is my existing code, which is fairly basic but requires a lot of error handling and redirecting in order to be user friendly...
Dim oPath As String oPath = ThisDoc.Path Dim oFileName As String oFileName = ThisDoc.FileName(False) Dim oForProduction As String oForProduction = oPath & ("\_FOR PRODUCTION") 'PDF TARGET PATH Dim oPurchaseParts As String oPurchaseParts = oPath & ("\_PURCHASE PARTS") 'DXF TARGET PATH Dim PDFAddIn As TranslatorAddIn oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") Dim DXFAddIn As TranslatorAddIn oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium Dim oPDFName As String oPDFName = "\" & oFileName & (" ") & Left(DateString,2) & "." & Mid(DateString,4,2) & "." & Right(DateString,2) & ".pdf" Dim oDXFName As String oDXFName = "\" & oFileName & (" ") & Left(DateString,2) & "." & Mid(DateString,4,2) & "." & Right(DateString,2) & ".dxf" Dim MyArrayList As New ArrayList For Each s In ThisDoc.Document.Sheets MyArrayList.Add(s.Name) Next MultiValue.List("dxf_out") = MyArrayList If oFileName IsNot "" Then '[ _.PDF_ PDF_Start: oPDFExport = MessageBox.Show("Export " & oFileName & " to .pdf?", "Export To PDF", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) If oPDFExport = vbYes Then If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 2 'oOptions.Value("Custom_End_Sheet") = 4 End If If Not System.IO.Directory.Exists(oForProduction) Then oFolderCreate = MessageBox.Show("Could not locate \_FOR PRODUCTION\ folder in this project." & vbLf & vbLf & "Create folder?", "Folder Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFolderCreate = vbYes Then System.IO.Directory.CreateDirectory(oForProduction) oDataMedium.FileName = oForProduction & oPDFName oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Else oOverride = MessageBox.Show("\_FOR PRODUCTION\ unavailable." & vbLf & vbLf & "Continue export anyways?", "Confirm Export", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oOverride = vbYes Then If System.IO.File.Exists(ThisDoc.WorkspacePath() & oPDFName) Then oFileCheck = MessageBox.Show(ThisDoc.WorkspacePath() & oPDFName & " already exists." & vbLf & vbLf & "Do you want to replace it?", "Confirm Save As", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFileCheck = vbYes Then oDataMedium.FileName = ThisDoc.WorkspacePath() & oPDFName oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Else MessageBox.Show("No .pdf files created." & vbLf & "Returning...", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto PDF_Start End If Else oDataMedium.FileName = ThisDoc.WorkspacePath() & oPDFName oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End If Else MessageBox.Show("No .pdf files created." & vbLf & "Returning...", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto PDF_Start End If End If Else If System.IO.File.Exists(oForProduction & oPDFName) Then oFileCheck = MessageBox.Show(oForProduction & oPDFName & " already exists." & vbLf & vbLf & "Do you want to replace it?", "Confirm Save As", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFileCheck = vbYes Then oDataMedium.FileName = oForProduction & oPDFName oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Else MessageBox.Show("No .pdf files created." & vbLf & "Returning...", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto PDF_Start End If Else oDataMedium.FileName = oForProduction & oPDFName oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End If End If ElseIf oPDFExport = vbNo Then MessageBox.Show("No .pdf files created.", "PDF Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else MessageBox.Show("No files created.", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto iLogicEnd End If '] '[ _.DXF_ DXF_Start: oDXFExport = MessageBox.Show("Export " & oFileName & " to .dxf?", "Export To DXF", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If oDXFExport = vbYes Then If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then Dim oDXFConfig As String oDXFConfig = "G:\FSH_Engineering\ENGINEERING DRAWINGS\_UTILITY\dxf_export_config.ini" oOptions.Value("Export_Acad_IniFile") = DXFConfig End If If Not System.IO.Directory.Exists(oPurchaseParts) Then oFolderCreate = MessageBox.Show("Could not locate \_PURCHASE PARTS\ folder in this project." & vbLf & vbLf & "Create folder?", "Folder Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFolderCreate = vbYes Then System.IO.Directory.CreateDirectory(oPurchaseParts) oDataMedium.FileName = oPurchaseParts & oDXFName oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Else oOverride = MessageBox.Show("\_PURCHASE PARTS\ unavailable." & vbLf & vbLf & "Continue export anyways?", "Confirm Export", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oOverride = vbYes Then If System.IO.File.Exists(ThisDoc.WorkspacePath() & oDXFName) Then oFileCheck = MessageBox.Show(ThisDoc.WorkspacePath() & oDXFName & " already exists." & vbLf & vbLf & "Do you want to replace it?", "Confirm Save As", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFileCheck = vbYes Then oDataMedium.FileName = ThisDoc.WorkspacePath() & oDXFName oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Else MessageBox.Show("No .dxf files created." & vbLf & "Returning...", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto DXF_Start End If Else oDataMedium.FileName = ThisDoc.WorkspacePath() & oDXFName oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End If Else MessageBox.Show("No .dxf files created." & vbLf & "Returning...", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto DXF_Start End If End If Else If System.IO.File.Exists(oPurchaseParts & oDXFName) Then oFileCheck = MessageBox.Show(oPurchaseParts & oDXFName & " already exists." & vbLf & vbLf & "Do you want to replace it?", "Confirm Save As", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFileCheck = vbYes Then oDataMedium.FileName = oPurchaseParts & oDXFName Call oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Else MessageBox.Show("No .dxf files created." & vbLf & "Returning...", "Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Goto DXF_Start End If Else oDataMedium.FileName = oPurchaseParts & oDXFName Call oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End If End If Else MessageBox.Show("No .dxf files created.", "DXF Export Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If '] Else MessageBox.Show("Save drawing before export.", "Failed To Export", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If iLogicEnd:
Try this one just change path where you want to save
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Define the drawing
DimoDrawingAsDrawingDocument
oDrawing = ThisDoc.Document
DimoSheetAsSheet
DimlPosAsLong
DimrPosAsLong
DimsLenAsLong
DimsSheetNameAsString
DimsSheetNumberAsInteger
'step through each drawing sheet
DimResponseAsMsgboxResult
ForEachoSheetInoDrawing.Sheets
Response = MsgBox("Yes = Save or No = Continue to next Sheet?", MsgBoxStyle.YesNo, "Question")
'''TRY
IfResponse = MsgBoxResult.YesThen
'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos- 1)
'find the sheet numbe
sSheetNumber = Right(oSheet.Name, sLen-lPos)
EndIf
ActiveSheet = ThisDrawing.Sheet(oSheet.Name)
IfResponse = MsgBoxResult.YesThen
'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos- 1)
'find the sheet numbe
sSheetNumber = Right(oSheet.Name, sLen-lPos)
ActiveSheet = ThisDrawing.Sheet(oSheet.Name)
'get DXF target folder path
oFolder = "N:\"
'Set the DXF target file name
oDataMedium.FileName = oFolder&"\"&sSheetName&sSheetNumber&".dxf"
MessageBox.Show("DXF SAVED TO: "&oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
'Publish document
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
EndIf
'For
Next
Is there no way of combining multiple boolean response variables into one message box? I'm sure it's possible with a VB form, but my visual basic skills are poor. I have not been able to find a way to build an iLogic form from iLogic though, all of the information i've found so far has indicated iLogic forms are limited to manually adding parameters and rules.
I don't think iLogic provides that, but as you said, it's possible in other custom forms, like in a .NET form.
You could either create a separate .NET module and use that from iLogic, or just do the whole thing in a .NET AddIn.