使用导入的符号更新显示模型

如果在显示模型中使用了自定义符号并且想要使用修改的符号进行更新,可以打开显示模型、生成图形并使用 MAPSYMBOLIMPORTEXPORT 导入修改后的符号。有关详细信息,请参见导入符号

    不使用用户界面以批处理方式导入符号

  1. “全球行业模型选项” “生成图形”中,选择“重复使用当前图形”
  2. 打开应用了显示模型的项目,然后从空图形开始。
  3. 将 CMDDIA 和 FILEDIA 系统变量同时设置为“0”。
  4. 在命令提示下,输入 TBDMOPEN。
  5. 按照提示,输入要修改的显示模型的路径。
  6. 输入命令 TBGENERATEGRAPHIC。
  7. 输入命令 MAPSYMBOLIMPORTEXPORT。
  8. 按照提示,选择“导入”。
  9. 输入包含要导入的符号的符号文件路径。
  10. 选择导入选项,指定如何在用户界面中选择符号。
  11. 完成导入,然后输入命令 TBDMSAVE。

或者也可以通过脚本自动完成上述步骤。在命令行中,使用脚本命令加载脚本文件并等其完成。如果为不同显示模型执行多个脚本,请确保从空图形开始操作,然后再打开显示模型。否则会将先前图形的旧图层保存到新显示模型。

以下为示例脚本。可以将其另存为扩展名为 .scr 的文件。

CMDDIA 0
FILEDIA 0
_TBDMOPEN [path to your TBDM file]
_TBGENERATEGRAPHIC
_MAPSYMBOLIMPORTEXPORT _IMPORT [choose options that fit your needs]
_TBDMSAVE
使用脚本完成操作后,将变量 CMDDIA 和 FILEDIA 设置回原始值,通常为 “1”。

VBA 脚本选项

若要节省时间,可以使用 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 脚本。

  1. 在 Map 3D 命令行中,输入 VBAIDE 以打开 Microsoft VBA 窗口。

    如果尚未安装 Autodesk AutoCAD VBA Enabler,系统会显示一条消息,提醒您安装。

  2. 在“Microsoft VBA”窗口中,执行以下操作:
    1. 单击文件,然后选择“导入文件”
    2. “导入文件”对话框中,找到并选择包含脚本的 .bas 文件。
    3. 单击“打开”
    4. 在 Microsoft VBA 窗口中,单击“保存”
    5. “另存为”对话框中,指定路径和文件名,然后单击“保存”
  3. 关闭 Microsoft VBA 窗口。
  4. 在命令行中输入 VBALOAD 加载上面保存的 .dvb 文件。

    如果系统向您发出关于宏的警告,请单击“启用宏”。

  5. 在命令行中,输入 VBARUN 并选择要运行的相关宏。