背景:创建一个iLogic规则去保存工程图文件为pdf格式到指定的文件夹。
创建 PDF规则
WorkspacePath= ThisDoc.WorkspacePath()
WorkspacePathLength = Len(WorkspacePath)
PathOnly = ThisDoc.Path
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length-WorkspacePathLength)
PDFPath = "C:\PDFs\" & DirectoryPath
If(Not System.IO.Directory.Exists(PDFPath)) Then
System.IO.Directory.CreateDirectory(PDFPath)
End If
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & ".pdf" , True)
高级创建 PDF规则
Sub Main ()
FileName = ThisDoc.FileName(True) 'with extension
FileExtension = Right(FileName, 3)
If FileExtension = "idw" Then
Save_As_PDF
Else If FileExtension = "dwg" Then
Save_As_PDF
Else
ErrorMessage
End If
End Sub
Sub Save_As_PDF
WorkspacePath= ThisDoc.WorkspacePath()
WorkspacePathLength = Len(WorkspacePath)
PathOnly = ThisDoc.Path
DirectoryPath = Strings.Right(PathOnly, PathOnly.Length - WorkspacePathLength)
PDFPath = "C:\PDFs\" & DirectoryPath
If(Not System.IO.Directory.Exists(PDFPath)) Then
System.IO.Directory.CreateDirectory(PDFPath)
End If
ThisDoc.Document.SaveAs(PDFPath & "\" & ThisDoc.FileName(False) & (".pdf") , True)
End Sub
Sub ErrorMessage
i = MessageBox.Show("This is not a drawing file. No PDF will be
created.", "Create PDF", MessageBoxButtons.OK, MessageBoxIcon.Hand,
MessageBoxDefaultButton.Button1)
End Sub
网友评论