111,126
社区成员
发帖
与我相关
我的任务
分享
// (C) Copyright 2002-2007 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[assembly: CommandClass(typeof(ChangeCase.Commands))]
namespace ChangeCase
{
/// <summary>
/// Summary description for Commands.
/// </summary>
public class Commands
{
public Commands()
{
//
// TODO: Add constructor logic here
//
}
// 将选中的字母将小写转换成大写
[CommandMethod("capital")]
static public void capital() // This method can have any name
{
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionOptions optSel = new PromptSelectionOptions();
PromptEntityOptions optEnt = new PromptEntityOptions("\n请选择文字");
optEnt.SetRejectMessage("\n您选择的对象不是文字,请重新选择!");
optEnt.AddAllowedClass(typeof(DBText), true);
optEnt.AddAllowedClass(typeof(MText), true);
PromptEntityResult resEnt = ed.GetEntity(optEnt);
if (resEnt.Status != PromptStatus.OK)
return;
ObjectId entID = resEnt.ObjectId;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = (Entity)trans.GetObject(entID, OpenMode.ForWrite);
DBText textEnt;
MText mtextEnt;
try
{
textEnt = (DBText)ent;
textEnt.TextString = textEnt.TextString.ToUpper();
}
catch
{
mtextEnt = (MText)ent;
mtextEnt.Contents = mtextEnt.Contents.ToUpper();
}
trans.Commit();
}
}
}
// 将选中的字母将大写转换成小写
[CommandMethod("lowercase")]
static public void lowercase()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionOptions optSel = new PromptSelectionOptions();
PromptEntityOptions optEnt = new PromptEntityOptions("\n请选择文字");
optEnt.SetRejectMessage("\n您选择的对象不是文字,请重新选择!");
optEnt.AddAllowedClass(typeof(DBText), true);
optEnt.AddAllowedClass(typeof(MText), true);
PromptEntityResult resEnt = ed.GetEntity(optEnt);
if (resEnt.Status != PromptStatus.OK)
return;
ObjectId entID = resEnt.ObjectId;
using(Transaction trans=db.TransactionManager.StartTransaction())
{
Entity ent = (Entity)trans.GetObject(entID, OpenMode.ForWrite);
DBText textEnt;
MText mtextEnt;
try
{
textEnt = (DBText)ent;
textEnt.TextString = textEnt.TextString.ToLower();
}
catch
{
mtextEnt = (MText)ent;
mtextEnt.Contents = mtextEnt.Contents.ToLower();
}
trans.Commit();
}
}
}
}