日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

在Map 3D显示管理器中更改当前地图的名字

發(fā)布時(shí)間:2024/4/14 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在Map 3D显示管理器中更改当前地图的名字 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


By?Daniel Du

當(dāng)前地圖在顯示管理器中默認(rèn)的名字是“Default”,如果你想通過(guò)程序更改地圖的名字,可以用下面的代碼來(lái)實(shí)現(xiàn)。你需要使用Display Manager API來(lái)做。首先獲取當(dāng)前地圖的Map ID,進(jìn)而獲得map對(duì)象,然后就可以為他的Name屬性賦值了。注意這個(gè)方法僅適用于map 3D 2012及以前版本,在Map 3D 2013中會(huì)拋出eCreateInvalidName錯(cuò)誤。

?

下面是完整實(shí)現(xiàn)代碼:

// (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?
轉(zhuǎn)載請(qǐng)保留此信息。



本文轉(zhuǎn)自峻祁連. Moving to Cloud/Mobile博客園博客,原文鏈接:http://www.cnblogs.com/junqilian/archive/2012/08/13/2636165.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者

總結(jié)

以上是生活随笔為你收集整理的在Map 3D显示管理器中更改当前地图的名字的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。