在Map 3D显示管理器中更改当前地图的名字
By Daniel Du
当前地图在显示管理器中默认的名字是“Default”,如果你想通过程序更改地图的名字,可以用下面的代码来实现。你需要使用Display Manager API来做。首先获取当前地图的Map ID,进而获得map对象,然后就可以为他的Name属性赋值了。注意这个方法仅适用于map 3D 2012及以前版本,在Map 3D 2013中会抛出eCreateInvalidName错误。
下面是完整实现代码:
// (C) Copyright 2012 by Autodesk
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.Gis.Map;
using Autodesk.Gis.Map.Project;
using Autodesk.Gis.Map.DisplayManagement;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(ChangeMapNameInDM.MyCommands))]
namespace ChangeMapNameInDM
{
// This class is instantiated by AutoCAD for each document when
// a command is called by the user the first time in the context
// of a given document. In other words, non static data in this class
// is implicitly per-document!
public class MyCommands
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
MapApplication app = HostMapApplicationServices.Application;
[Autodesk.AutoCAD.Runtime.CommandMethodAttribute("CHGMAPNAME")]
public void ChangeMapName()
{
try
{
string mapName = null;
PromptResult stringPromptResult = null;
bool succeeded = false;
stringPromptResult = ed.GetString("\nEnter the new Map name:");
mapName = stringPromptResult.StringResult.Trim();
if (stringPromptResult.Status == PromptStatus.OK
&& mapName.Length > 0)
{
succeeded = changeMapName(mapName);
}
else
{
ed.WriteMessage("\nERROR: Invalid Map name");
}
if (!succeeded)
{
ed.WriteMessage("\nERROR: Name change failure");
}
}
catch (System.Exception err)
{
ed.WriteMessage(err.Message);
}
}
private bool FindCurrentMapId(ref ObjectId currentMapId)
{
bool isFound = false;
// Get the project associated with the current AutoCAD document
ProjectModel project = null;
Autodesk.AutoCAD.DatabaseServices.TransactionManager TM
= app.ActiveProject.Database.TransactionManager;
project = app.ActiveProject;
try
{
using (Transaction trans = TM.StartTransaction())
{
ObjectId managerId = DisplayManager.Create(project)
.MapManagerId(project, true);
MapManager manager = trans.GetObject(managerId, OpenMode.ForRead)
as MapManager;
if (null != manager)
{
currentMapId = manager.CurrentMapId;
isFound = true;
}
trans.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception)
{
ed.WriteMessage("\nUnable to get the current Map's Object ID.");
}
return isFound;
}
public bool changeMapName(string name)
{
// Get the Object Id for the current Map
ObjectId currentMapId = new ObjectId();
string message = "";
Autodesk.AutoCAD.DatabaseServices.TransactionManager TM
= app.ActiveProject.Database.TransactionManager;
if (!FindCurrentMapId(ref currentMapId))
{
return false;
}
try
{
using (Transaction trans = TM.StartTransaction())
{
Map currentMap = (Map)trans.GetObject(currentMapId, OpenMode.ForWrite);
// Change the name
currentMap.Name = name;
trans.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
message = string.Format("\nUnable to change name, msg:{0}",
ex.Message);
ed.WriteMessage(message);
}
return true;
}
}
}
邮箱:junqilian@163.com
出处:http://junqilian.cnblogs.com
转载请保留此信息。
在Map 3D显示管理器中更改当前地图的名字相关推荐
- Linux更改显示管理器,聊聊Linux操作系统中的显示管理器及如何更换
在这篇Linux黑话解释中,你将了解 Linux 中的显示管理器.它是桌面环境的一部分吗?它的作用是什么? 什么是 Linux 中的显示管理器? 简单来说,显示管理器display manager(D ...
- 【转】聊聊Linux操作系统中的显示管理器及如何更换
转自:聊聊Linux操作系统中的显示管理器及如何更换 - linux-123 - 博客园 聊聊Linux操作系统中的显示管理器及如何更换 | <Linux就该这么学> 什么是 Linux ...
- 磁盘管理器中不显示新增的硬盘
今天给dell电脑换上了一块ssd,在磁盘管理器中居然不显示,设备管理器中可以显示出新增的硬盘设备.百思不得其解... 各种推测尝试未果后,终于找到了原因! 在存储设置中找到了新增硬盘的身影,将其从存 ...
- ArcGIS中样式管理器中的各种样式(指南针样式,色带样式等等)丢失,显示为空白的解决方案
ArcGIS中样式管理器中的各种样式(指南针样式,色带样式等等)丢失,显示为空白的解决方案 在反复更换ArcGIS版本时,很有可能出现样式管理器中的各种样式全部丢失的问题.我的10.2版本也出现过这种 ...
- 什么是 Linux 中的显示管理器?
简单来说, 显示管理器(display manager)(DM)是一个为你的 Linux 发行版提供图形登录功能的程序.它控制用户会话并管理用户认证.显示管理器会在你输入用户名和密码后,立即启动 显示 ...
- kde 桌面显示管理器_KDE文件管理器Dolphin的综合指南
kde 桌面显示管理器 自Fedora 10以来, Dolphin一直是KDE桌面的默认文件管理器.使用KDE作为桌面选项的其他发行版也将其用作默认文件管理器. 它非常强大,并提供了一些非常高级的功能 ...
- 【进阶知识】显示管理器,窗口管理器,桌面环境/桌面管理器,显示服务器
文章目录 一.显示管理器(Display Manager) 1.1 什么是 Linux 中的显示管理器? 1.2 不同的显示管理器 1.3 其他 控制台显示管理器 图形界面显示管理器 二.窗口管理器( ...
- linux桌面管理器sddm,GDM, KDM, LightDM, SDDM显示管理器的区别和安装配置
gdm3,kdm 和 lightdm 都是显示管理器. 它们提供图形化登录并处理用户身份验证. 从维基文章中: 显示管理器向用户显示登录屏幕. 当用户成功输入用户名和密码的有效组合时,会话开始. GD ...
- 在“DNS管理器”中手工增加DNS主机(A)或者别名(CNAME)记录时,出现被拒绝的错误...
问题现象: AD域控制器操作系统为Win2008R2,在"DNS管理器"中手工增加DNS主机(A)或者别名(CNAME)记录时,出现被拒绝的错误.但是将客户端加入域后,在" ...
最新文章
- cordova编译报错:Execution failed for task ':processDebugResources'
- IOS - JSON数据解析 小3种方法
- 陷阱:C++模块之间的”直接依赖“和”间接依赖“与Makefile的撰写
- activiti5第六弹 手动任务、接收任务、邮件任务
- UITextView
- Badger DAO 将在 DIGG 启动后开放三个新机枪池
- win10一直正在检查更新_win10一直存在的烦人问题,终于被彻底解决!你会选择更新么?...
- 说点你们不知道的大趋势
- clean-css 安装 使用
- 两侧列固定中间列变宽Div布局参考
- 数据库基础知识,超全!!!
- 快速求最小公倍数的四种方法
- 使用Kotlin+JetPack 从零开发自己的日记App
- 什么是SDK? {转载}
- 如何快速高效的刷Leetcode
- vmware虚拟机更改MAC地址方法
- Unity TimeLine丨A1.创建TimeLine、Animation Track,Extrapolation属性讲解
- 深入分析QQ键盘保护技术
- Android学习别“走弯路”,android开发计算器课程设计
- 三年级计算机画图工具教案,小学三年级信息技术教学设计《画图》