如果在显示模型中使用了自定义符号并且想要使用修改的符号进行更新,可以打开显示模型、生成图形并使用 MAPSYMBOLIMPORTEXPORT 导入修改后的符号。有关详细信息,请参见导入符号。
不使用用户界面以批处理方式导入符号
或者也可以通过脚本自动完成上述步骤。在命令行中,使用脚本命令加载脚本文件并等其完成。如果为不同显示模型执行多个脚本,请确保从空图形开始操作,然后再打开显示模型。否则会将先前图形的旧图层保存到新显示模型。
以下为示例脚本。可以将其另存为扩展名为 .scr 的文件。
CMDDIA 0 FILEDIA 0 _TBDMOPEN [path to your TBDM file] _TBGENERATEGRAPHIC _MAPSYMBOLIMPORTEXPORT _IMPORT [choose options that fit your needs] _TBDMSAVE使用脚本完成操作后,将变量 CMDDIA 和 FILEDIA 设置回原始值,通常为 “1”。
若要节省时间,可以使用 Microsoft Visual Basic for Applications (VBA) 脚本一次导入多个显示模型的符号。以下脚本为示例。您可将其用作模板并进行必要的修改,然后另存为 .bas 文件。
Attribute VB_Name = "ImportSymbolInto_IM_DM" Sub ImportSymbolIntoDisplayModel() Dim prototypeDWG, templateDWT As String Dim FileDia, CmdDia As Integer Dim displayModelArray(0 To 2) As String 'TODO: Adapt to the number of Display Models to update ' TODO - Adapt to your settings ' Define the path to the Display Models for updating the symbol(s) ' When adding or removing Display Models, please adapt also the size of displayModelArray ' and the loop over all Display Models displayModelArray(0) = "C:\TEST\DM1\DM1.tbdm" displayModelArray(1) = " C:\TEST\DM2\DM2.tbdm" displayModelArray(2) = " C:\TEST\DM3\DM3.tbdm" ' Attention !!! ' Only use the "Generic Graphic" - Application option: Reuse current drawings ' We need the same drawing for all operations ! ' TODO - Adapt to your settings ' Define where the symbol(s) should be imported from prototypeDWG = "C:\temp\symbol_modified.dwg " ' TODO - Adapt to your settings ' Define the template file to be used when open a new DWG templateDWT = "c:\temp\Template\map2d.dwt" 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 FileDia = ThisDrawing.GetVariable("FILEDIA") CmdDia = ThisDrawing.GetVariable("CMDDIA") ThisDrawing.SetVariable "FILEDIA", 0 ThisDrawing.SetVariable "CMDDIA", 0 ' Loop all Display Models For inti = 0 To 2 ' Open an empty drawing Application.Documents.Open (templateDWT) ' Open the Display Model ThisDrawing.SendCommand "_TBDMOPEN" & vbCr & displayModelArray(inti) & vbCr ThisDrawing.SendCommand "_TBGENERATEGRAPHIC" & vbCr ' Import the symbol and apply changes to the layers ThisDrawing.SendCommand "_MAPSYMBOLIMPORTEXPORT" & vbCr & "_IMPORT" & vbCr & prototypeDWG & vbCr & "_YES" & vbCr ' Save the changes of the layers to the Display Model ThisDrawing.SendCommand "_TBDMSAVE" & vbCr ' Do not save the drawing ThisDrawing.Close (False) Next ' Reset the system variables ThisDrawing.SetVariable "FILEDIA", FileDia ThisDrawing.SetVariable "CMDDIA", CmdDia End Sub
在示例脚本中,包含一个带有子内容“ImportSymbolIntoDisplayModel ()”的“ImportSymbolInto_IM_DM”模块。您需要调整显示模型的数量以及 DWT 和 .tbdm 文件的路径。
若要导入显示模型的符号,请使用 VBA 脚本。
如果尚未安装 Autodesk AutoCAD VBA Enabler,系统会显示一条消息,提醒您安装。
如果系统向您发出关于宏的警告,请单击“启用宏”。