本帖最后由 雪山飞狐_lzh 于 2012-7-17 08:09 编辑
- /// <summary>
- /// 单行文字分解
- /// </summary>
- [CommandMethod("t4")]
- public static void Test4()
- {
- var ed = SystemManager.Editor;
- var opts = new PromptEntityOptions("\n请选择文本:");
- opts.SetRejectMessage("你选择的不是文本,请重新选择!");
- opts.AddAllowedClass(typeof(DBText), false);
- var res = ed.GetEntity(opts);
- if (res.Status != PromptStatus.OK) return;
- using (var tr = new DBTransaction())
- {
- var btr =tr.OpenCurrentSpace(OpenMode.ForWrite);
- var txt = tr.GetObject<DBText>(res.ObjectId).Copy();
- var ext = txt.GeometricExtents;
- var pt = ext.MinPoint;
- var txts = new List<DBText>();
- int color = 1;
- foreach(char c in txt.TextString)
- {
- var s = c.ToString();
- var txtx =
- new DBText
- {
- TextString = s,
- TextStyleId = txt.TextStyleId,
- Height = txt.Height,
- Position = pt,
- ColorIndex = color ++
- };
- txtx.SetDatabaseDefaults();
- txts.Add(txtx);
- var width = AcUtils.GetTextExtents(txt.TextStyleId, s, txt.Height).X;
- pt += new Vector3d(width, 0, 0);
- }
- tr.AddEntity(btr, txts);
- //简单的拖动方式
- var ss = SelectionSet.FromObjectIds(txts.Select(t => t.ObjectId).ToArray());
- var ptBase = ext.MinPoint;
- var resDrag =
- ed.Drag(
- ss,
- "\n输入插入点",
- (Point3d p, ref Matrix3d m) =>
- {
- m = Matrix3d.Displacement(p - ptBase);
- return SamplerStatus.OK;
- });
- if (resDrag.Status == PromptStatus.OK)
- {
- var mat = Matrix3d.Displacement(resDrag.Value - ptBase);
- txts.ForEach(c => c.TransformBy(mat));
- }
- else
- {
- tr.Erase(txts);
- }
- }
- }
|