使用 MAPSYMBOLIMPORTEXPORT 命令或 Microsoft VBA 脚本,可以在单个操作中导入多个符号。
对点、线或多边形要素设置样式时,使用“加载选项”可导入符号。也可以使用 MAPSYMBOLIMPORTEXPORT 命令,如下所述。
使用用户界面导入符号
可以将块作为符号导入 DWG 文件。您还可以将符号库 (*.layer)、矢量符号 (*.xml),图案填充定义 (*.pat)、线样式 (*.lin) 或光栅图像 (*.gif、*.jpg、*.bmp、*.png)导入符号库。
导入符号而不使用用户界面
CMDDIA 0 FILEDIA 0 _MAPSYMBOLIMPORTEXPORT _IMPORT "C:\data\MySymbols.dwg" _YES
若要节省时间,可以使用 Microsoft Visual Basic for Applications (VBA) 脚本一次导入多个图形的符号。以下脚本为示例。您可将其用作模板并进行必要的修改,然后另存为 .bas 文件。
Attribute VB_Name = "ImportSymbolIntoDWG"
Sub ImportSymbolIntoAllDWG()
Dim fileSystemObject, fileSystemFolder, file, fileCollection
Dim collectionOfFiles As New Collection
Dim path As String
' Define where the DWG files are located
path = "C:\Autodesk\DWGFiles"
Dim prototypeDWG As String
' Define where the symbol(s) should be imported from
prototypeDWG = "C:\Autodesk\Prototype\Prototype_GA_modified.dwg"
Dim currentSDI As Integer
currentSDI = ThisDrawing.GetVariable("SDI")
If (currentSDI = 1) Then
MsgBox "The functions works only with multiple drawings [SDI=0]"
Exit Sub
End If
'' use this to request the path
'path = ThisDrawing.Utility.GetString(1, vbCrLf & "Enter the path of the DWG files to update: ")
'prototypeDWG = ThisDrawing.Utility.GetString(1, vbCrLf & "Enter the path of the prototype DWG: ")
ThisDrawing.SetVariable "FILEDIA", 0
ThisDrawing.SetVariable "CMDDIA", 0
Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
Set fileSystemFolder = fileSystemObject.GetFolder(path)
Set fileCollection = fileSystemFolder.Files
For Each file In fileCollection
If UCase(Right(file.Name, 4)) = UCase(".dwg") Then
collectionOfFiles.Add file.path
End If
Next
For Each drawing In collectionOfFiles
Application.Documents.Open (drawing)
ThisDrawing.SendCommand "_MAPSYMBOLIMPORTEXPORT" & vbCr & "_IMPORT" & vbCr & prototypeDWG & vbCr & "_YES" & vbCr
ThisDrawing.Save
ThisDrawing.Close
Next drawing
End Sub
在示例脚本中,包含一个带有子内容“ImportSymbolIntoAllDWG()”的“ImportSymbolIntoDWG”模块。您需要修改“path”变量来指定图形所处位置的路径,然后修改“prototypeDWG”变量来指向要导入的包含符号的 DWG 文件。
若要导入多个图形的符号,请使用 VBA 脚本。
如果尚未安装 Autodesk AutoCAD VBA Enabler,系统会显示一条消息,提醒您下载。
如果系统向您发出关于宏的警告,请单击“启用宏”。