How to control AlignmentPoint Property of a DBText Object

This widget could not be displayed.

How to control AlignmentPoint Property of a DBText Object

Anonymous
Not applicable

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

0 Likes
Reply
Accepted solutions (1)
4,253 Views
3 Replies
Replies (3)

_gile
Mentor
Mentor
Accepted solution

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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Anonymous
Not applicable

 Yes, it is,  very very thanks

0 Likes

michal_hcz
Contributor
Contributor

Hi guys, I've tried to reproduce your code for TransientManager and the result is different. Any idea why? Text is always located in 0,0,0. If I add text.Position = ppr.Value then justification doesn't work.

[CommandMethod("dbtextalign")]
public void dbtextalign()
{
	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 (Application.DocumentManager.MdiActiveDocument.LockDocument())
	using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
	{
		TransientManager tm = TransientManager.CurrentTransientManager;
		IntegerCollection intColl = new IntegerCollection();

		DBText text = new DBText();
		text.TextString = "XXXXXX";
		text.Justify = AttachmentPoint.TopCenter;
		text.AlignmentPoint = ppr.Value;
		text.TransformBy(ed.CurrentUserCoordinateSystem);

		tm.AddTransient(text, TransientDrawingMode.Highlight, 128, intColl);
		tr.Commit();
	}
}


 

0 Likes