- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I have this script that collects and combine the filename+description+date+revision and export it to a pdf file.
So far so good. Now sometime the user type in special characters in the description which cause the script to fail because windows not allowed special characters in the filename...
So I want to stop the scrip and show the user a message that special characters in the description are not allowed. But I can not find a method to search the description string for these illegal characters
< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
I have marked below in the code where I think the code should be inserted
SyntaxEditor Code Snippet
Sub Main() 'Get document file name ' docname = ThisDoc.FileName(False) 'Get the model which the drawing is referencing (1st view) oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName) oDesc = iProperties.Value(oModelDoc, "Project", "Description") If oDesc = "" Then MessageBox.Show("The Description iproperty cannot be empty. Go to the Part/Assembly and type a Description. NO PDF WILL BE GENERATED", "Warning") =============> INSERT THE CODE HERE
Exit Sub End If If oDesc = "" Then MessageBox.Show("The Description iproperty cannot be empty. Go to the Part/Assembly and type a Description. NO PDF WILL BE GENERATED", "Warning") Exit Sub End If ' Get the PDF translator Add-In. Dim PDFAddIn As TranslatorAddIn PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium ' Check whether the translator has 'SaveCopyAs' options If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then ' Options for drawings... 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 'get PDF target folder path oPath = "C:\Users\user\Desktop\test" 'oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" oFileName = ThisDoc.FileName(False) 'without extension oRevNum = iProperties.Value("Project", "Revision Number") oDate = DateTime.Now.ToString("_yyMMdd") If oDesc = "" Then MessageBox.Show("Warning", "Description iproperties is empty") End If If oRevNum = "-" Or oRevNum = "" Then oPathCom = oPath & "\" & oFileName & " - " & oDesc & oDate &".pdf" Else oPathCom = oPath & "\" & oFileName & "-" & oRevNum & " - " & oDesc & oDate & ".pdf" End If oDataMedium.FileName = oPathCom 'Publish document. Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) ' End Sub
Solved! Go to Solution.