.NET

.NET

Reply
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 1 of 3 (297 Views)
Accepted Solution

How to control AlignmentPoint Property of a DBText Object

297 Views, 2 Replies
12-22-2013 07:13 AM

   Please see the attachment. My goal is create a DBText object just like the the left one, but this one is copied from another drawing, My own DBtext is the right one which was created by C# code.

 

     Everyone should be able to find subtle differences, yes, The AlignmentPoint property of the left DBText is placed in the middle, and the base point is placed in the lower left corner
     In contrast, the basis points and the AlignmentPoint of the right DBText are coincident.

 
     How to control AlignmentPoint Property of a DBText Object? I just want to creat a Dbtext just like the left one.

 
     I have tried to directly modify AlignmentPoint property, use the the follow code:
    objText.AlignmentPoint = new Point3d(0.83333333333, 1.25, 0);
     But AutoCAD will be throw a Exception that message is eNotApplicable, and the AlignmentPoint won't change as my want.

    


    Filled with hope for your help.

    thanks..

*Expert Elite*
_gile
Posts: 2,082
Registered: ‎04-29-2006
Message 2 of 3 (282 Views)

Re : How to control AlignmentPoint Property of a DBText Object

12-22-2013 08:37 AM in reply to: HelloWorlddd

Hi,

 

You have to set the DBText.Justify property to AttachmentPoint.MiddleCenter (or whatever you need) and specify the DBText.AlignmentPoint property.

 

You can try the:

 

        [CommandMethod("test")]
        public void Test()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptPointResult ppr = ed.GetPoint("\nInsertion point: ");
            if (ppr.Status != PromptStatus.OK)
                return;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBText text = new DBText();
                text.TextString = "42";
                text.Justify = AttachmentPoint.MiddleCenter;
                text.AlignmentPoint = ppr.Value;
                text.TransformBy(ed.CurrentUserCoordinateSystem);
                BlockTableRecord btr =
                    (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                btr.AppendEntity(text);
                tr.AddNewlyCreatedDBObject(text, true);
                tr.Commit();
            }
        }

 

Gilles Chanteau
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 3 of 3 (246 Views)

Re : How to control AlignmentPoint Property of a DBText Object

12-23-2013 05:54 AM in reply to: _gile

 Yes, it is,  very very thanks

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.