Author Topic: Change cell text width  (Read 569 times)

0 Members and 1 Guest are viewing this topic.

Offline fixo

  • Full Member
  • ***
  • Posts: 135
  • Karma: +4/-0
  • Gender: Male
    • prefered language: C
    • Prog expertise: Good
    • View Profile
Change cell text width
« on: July 04, 2012, 03:31:21 PM »
Code: [Select]
        [CommandMethod("CellTextWidth","ctw", CommandFlags.Modal)]
        public static void setCellTextWidth()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptEntityOptions opts = new PromptEntityOptions("\nSelect the table:");
            opts.SetRejectMessage("\nMust be the table only...");
            opts.AddAllowedClass(typeof(Table), true);
            PromptEntityResult res = ed.GetEntity(opts);
            if (res.Status != PromptStatus.OK) return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBObject obj = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as DBObject;
                Table tbl = obj as Table;
                if (tbl == null) return;
                int row = 2;
                int colm =1;
                tbl.UpgradeOpen();
                AcadTable actbl = tbl.AcadObject as AcadTable;
                actbl.SetCellValueFromText(row, colm, "{\\W0.5;Text Width = 0.5}", AcParseOption.acPreserveMtextFormat);
                actbl.SetText(row + 1, colm + 1, "Text Width = 0.5");
                tr.Commit();
            }
        }

~'J'~