Author Topic: Why the TextStyleTableRecord's ObliquingAngle property has no effect on text?  (Read 2580 times)

0 Members and 1 Guest are viewing this topic.

csharpbird

  • Newt
  • Posts: 64
Code: [Select]
        [CommandMethod("Test")]
        public static void Test()
        {
            Database db=HostApplicationServices.WorkingDatabase;
            using (Transaction trans=db.TransactionManager.StartTransaction())
            {
                TextStyleTable st=(TextStyleTable)trans.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                TextStyleTableRecord str=new TextStyleTableRecord();
                str.Name = "Test";
                str.FileName = "romans";
                str.ObliquingAngle = 15 * Math.PI / 180;
                st.UpgradeOpen();
                st.Add(str);
                trans.AddNewlyCreatedDBObject(str, true);
                st.DowngradeOpen();
                DBText txt=new DBText();
                txt.TextString = "Test";
                txt.TextStyle = str.ObjectId;
                BlockTableRecord model=(BlockTableRecord)trans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                model.AppendEntity(txt);
                trans.AddNewlyCreatedDBObject(txt, true);
                trans.Commit();
            }
        }
It seems that  the TextStyleTableRecord's ObliquingAngle property has no effect on text?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Have you been able to compile that 'bird ?

DBText doesn't have a Textstyle property.

Should Textstyle  be TextStyleId
« Last Edit: December 25, 2011, 11:15:25 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

csharpbird

  • Newt
  • Posts: 64
Sorry,my code is for AutoCAD 2008.
You can  change TextStyle to TextStyleId for AutoCAD high edition.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>

'bird,
I think you are correct.
My understanding is that newing a DBText used the current style as default ... I may be wrong :)


I tried this, which to my mind should have worked in ac2012
Code: [Select]
AcadApp.SetSystemVariable("TEXTSTYLE", styleName);
I'll have a play when I get a chance
Regards
kdub

Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.GraphicsInterface;
  3. using Autodesk.AutoCAD.Runtime;
  4. using Autodesk.AutoCAD.ApplicationServices;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.Geometry;
  7. using Autodesk.AutoCAD.EditorInput;
  8. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
  9.  
  10. [assembly: CommandClass(typeof (TextStyleTableRecordProblem.MyCommands))]
  11.  
  12. namespace TextStyleTableRecordProblem
  13. {
  14.     public class MyCommands
  15.     {
  16.         [CommandMethod("Test")]
  17.         public static void Test()
  18.         {
  19.             Document doc = Application.DocumentManager.MdiActiveDocument;
  20.             Database db = doc.Database;
  21.             string styleName = "MySlopeyTextStyle";
  22.  
  23.             using (Transaction tr = db.TransactionManager.StartTransaction())
  24.             {
  25.                 TextStyleTable tsTbl =
  26.                     (TextStyleTable)
  27.                     tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
  28.  
  29.                  if (!tsTbl.Has(styleName))
  30.                  {
  31.                      Make_TextStyle(styleName, "romans", 3.5,
  32.                      1.0, 15 * Math.PI / 180);  
  33.                  }
  34.                 TextStyleTableRecord tsTblRec =
  35.                     (TextStyleTableRecord)
  36.                     tr.GetObject(tsTbl[styleName], OpenMode.ForRead);
  37.  
  38.                 BlockTableRecord model =
  39.                     (BlockTableRecord)
  40.                     tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),
  41.                                  OpenMode.ForWrite);
  42.  
  43.                 AcadApp.SetSystemVariable("TEXTSTYLE", styleName);
  44.  
  45.                 using (DBText txt = new DBText())
  46.                 {
  47.                     //txt.SetDatabaseDefaults();
  48.                     txt.TextStyleId = tsTbl[styleName];
  49.                     txt.TextString = "Test-DBTEXT";
  50.                     //txt.WidthFactor = 1.0;
  51.                     //txt.Height =
  52.                     //    Convert.ToInt32(Application.GetSystemVariable("DIMSCALE"))
  53.                     //    *3.5;
  54.                     //txt.o
  55.  
  56.                     model.AppendEntity(txt);
  57.                     tr.AddNewlyCreatedDBObject(txt, true);
  58.                 }
  59.                 tr.Commit();
  60.             }
  61.         }
  62.  
  63.  
  64.         //=============================================
  65.         public static void Make_TextStyle(string styleName, string font, double fontSize,
  66.                                           double widthFactor, double obliqueAngle)
  67.         {
  68.             Database db = Application.DocumentManager.MdiActiveDocument.Database;
  69.             ObjectId textStyleID = ObjectId.Null;
  70.  
  71.             using (Transaction tr = db.TransactionManager.StartTransaction())
  72.             {
  73.                 TextStyleTable tsTbl =
  74.                     (TextStyleTable)
  75.                     tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite, false);
  76.  
  77.                 if (!tsTbl.Has(styleName)) // make new
  78.                 {
  79.                     TextStyleTableRecord tsTblRec = new TextStyleTableRecord();
  80.  
  81.                     tsTblRec.Name = styleName;
  82.                     // Font, Not Bold, Not Italic, Characters, Pitch&Family
  83.                     tsTblRec.Font = new FontDescriptor(font, false, false, 0, 0);
  84.  
  85.                     tsTblRec.XScale = widthFactor;
  86.                     tsTblRec.Annotative = AnnotativeStates.False;
  87.  
  88.                     tsTblRec.TextSize =
  89.                         Convert.ToInt32(Application.GetSystemVariable("DIMSCALE"))*
  90.                         fontSize;
  91.                     tsTblRec.ObliquingAngle = obliqueAngle;
  92.                     tsTbl.Add(tsTblRec);
  93.  
  94.                     tr.AddNewlyCreatedDBObject(tsTblRec, true);
  95.                 }
  96.                 tr.Commit();
  97.                 tr.Dispose();
  98.             }
  99.         }
  100.     }
  101. }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

csharpbird

  • Newt
  • Posts: 64
It seems that Application.SetSystemVariable("TEXTSTYLE",...) has no effect.

fixo

  • Guest

It seems that  the TextStyleTableRecord's ObliquingAngle property has no effect on text?
Try set oblique like this
Code: [Select]
txt.SetDatabaseDefaults();
                txt.TextString = "Test";
               txt.TextStyleId = str.ObjectId;
               txt.Oblique = str.ObliquingAngle;

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
'Bird, Oleg

This works for me in ac2012

If Stephen Preston comes past, he may be able to clarify the idea I had that the current TextStyle should be the default for a new DBText ( and MText also)

Refer to my previous for using statements and the Make_TextStyle() Method.

Code - C#: [Select]
  1.         [CommandMethod("Test")]
  2.         public static void Test()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             string styleName = "MySlopeyTextStyle";
  7.  
  8.             using (Transaction tr = db.TransactionManager.StartTransaction())
  9.             {
  10.                 TextStyleTable tsTbl =
  11.                     (TextStyleTable)
  12.                     tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite);
  13.  
  14.                 if (!tsTbl.Has(styleName))
  15.                 {
  16.                     Make_TextStyle(styleName, "romans", 3.5,
  17.                                    1.0, 15*Math.PI/180);
  18.                 }
  19.                 TextStyleTableRecord tsTblRec =
  20.                     (TextStyleTableRecord)
  21.                     tr.GetObject(tsTbl[styleName], OpenMode.ForRead);
  22.  
  23.                 BlockTableRecord model =
  24.                     (BlockTableRecord)
  25.                     tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db),
  26.                                  OpenMode.ForWrite);
  27.  
  28.                 using (DBText txt = new DBText())
  29.                 {
  30.                     txt.SetDatabaseDefaults();
  31.                     txt.TextStyleId = tsTbl[styleName];
  32.                     txt.TextString = "Test-DBTEXT";
  33.                     txt.WidthFactor = tsTblRec.XScale;
  34.                     txt.Height = tsTblRec.TextSize;
  35.                     txt.Oblique = tsTblRec.ObliquingAngle;
  36.  
  37.                     model.AppendEntity(txt);
  38.                     tr.AddNewlyCreatedDBObject(txt, true);
  39.                 }
  40.                 tr.Commit();
  41.             }
  42.         }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
I have noticed and have no idea why but with multileaders, text, etc....... some properties won't stick until after it has been added to the database.