求救:用c#如何对cad2007将选中的文本进行大小写转换

linjiancun 2009-04-22 04:48:18
本人刚学cad二次开发,请大家教教我!~
...全文
492 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssqinxiaojing 2009-04-24
  • 打赏
  • 举报
回复
楼主人好好哦!
顶起来!
linjiancun 2009-04-23
  • 打赏
  • 举报
回复
自己解决问题:
代码如下,喜欢的人拿去用:


// (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();

}
}


}
}
xuezhanliang6886 2009-04-23
  • 打赏
  • 举报
回复
CAD?二次开发!!

高手们出来解决解决呀!帮顶啦!!
csjtxy 2009-04-23
  • 打赏
  • 举报
回复
ding
blestcc 2009-04-23
  • 打赏
  • 举报
回复
不懂cad
ssqinxiaojing 2009-04-22
  • 打赏
  • 举报
回复
up!!! Good good study,day day up!
麻子Mozart 2009-04-22
  • 打赏
  • 举报
回复
帮顶

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧