马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- [CommandMethod("WZXG")]
- public void WZG()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- PromptSelectionOptions options = new PromptSelectionOptions();
- SelectionFilter fil = new SelectionFilter(new TypedValue[] { new TypedValue(0, "*text,mtext") });
- options.MessageForAdding = "\n选择文字:";
- OpenTextStyle.ss1 = ed.GetSelection(options, fil);
- OpenTextStyle opentextstyle = new OpenTextStyle();
- Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(opentextstyle);
- }
- public partial class OpenTextStyle : Form
- {
- public static PromptSelectionResult ss1;
- public OpenTextStyle()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- this.Hide();
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
- {
- SelectionSet ss = ss1.Value;
- if (ss1.Status != PromptStatus.OK) return;
- if (ss1.Status == PromptStatus.Cancel) return;
- ObjectIdCollection objectId1 = new ObjectIdCollection();
- ObjectIdCollection objectId2 = new ObjectIdCollection();
- using (Transaction tr1 = doc.TransactionManager.StartTransaction())
- {
- foreach (ObjectId id in ss.GetObjectIds())
- {
- Entity entity = tr.GetObject(id, OpenMode.ForRead) as Entity;
- if (entity.GetType().Name == "DBText")
- {
- objectId1.Add(id);
- }
- else if (entity.GetType().Name == "MText")
- {
- objectId2.Add(id);
- }
- }
- tr1.Commit();
- }
- using (Transaction tr2 = doc.TransactionManager.StartTransaction())
- {
- foreach (ObjectId textId in objectId1)
- {
- DBText dText = tr2.GetObject(textId, OpenMode.ForWrite) as DBText;
- using (Transaction tr3 = db.TransactionManager.StartTransaction())
- {
- TextStyleTable st = (TextStyleTable)db.TextStyleTableId.GetObject(OpenMode.ForRead);
- foreach (ObjectId td in st)
- {
- TextStyleTableRecord textR = tr.GetObject(td, OpenMode.ForRead) as TextStyleTableRecord;
- if (textR.Name == this.comboBox1.SelectedItem.ToString())
- {
- dText.TextStyleId = td;
- }
- }
- tr3.Commit();
- }
- dText.Height = Convert.ToDouble(this.textBox1.Text.ToString());
- dText.WidthFactor = Convert.ToDouble(this.textBox2.Text.ToString());
- dText.DowngradeOpen();
- }
- foreach (ObjectId textId1 in objectId2)
- {
- MText Mtext = tr2.GetObject(textId1, OpenMode.ForWrite) as MText;
- using (Transaction tr4 = db.TransactionManager.StartTransaction())
- {
- TextStyleTable st = (TextStyleTable)db.TextStyleTableId.GetObject(OpenMode.ForRead);
- foreach (ObjectId td in st)
- {
- TextStyleTableRecord textR = tr.GetObject(td, OpenMode.ForWrite) as TextStyleTableRecord;
- if (textR.Name == this.comboBox1.SelectedItem.ToString())
- {
- textR.XScale = Convert.ToDouble(this.textBox2.Text.ToString());
- Mtext.TextStyleId = td;
- textR.DowngradeOpen();
- }
- }
- tr4.Commit();
- }
- Mtext.TextHeight = Convert.ToDouble(this.textBox1.Text.ToString());
- Mtext.DowngradeOpen();
- }
- tr2.Commit();
- }
- tr.Commit();
- }
- this.Close();
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void OpenTextStyle_Load(object sender, EventArgs e)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- List<string> comString = new List<string>();
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- TextStyleTable st = (TextStyleTable)db.TextStyleTableId.GetObject(OpenMode.ForRead);
- foreach (ObjectId tId in st)
- {
- TextStyleTableRecord textR = tr.GetObject(tId, OpenMode.ForRead) as TextStyleTableRecord;
- comString.Add(textR.Name);
- }
- this.comboBox1.DataSource = comString;
- tr.Commit();
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
|