.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to control AlignmentPoint Property of a DBText Object

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
HelloWorlddd
3823 Views, 3 Replies

How to control AlignmentPoint Property of a DBText Object

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

3 REPLIES 3
Message 2 of 4
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4
HelloWorlddd
in reply to: _gile

 Yes, it is,  very very thanks

Message 4 of 4
michal_hcz
in reply to: HelloWorlddd

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


 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost