.NET

.NET

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

How to control AlignmentPoint Property of a DBText Object

351 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..

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();
}
}

 

*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 2 of 3 (336 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 (300 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.