geometric extents in UCS

geometric extents in UCS

Anonymous
Not applicable
1,094 Views
3 Replies
Message 1 of 4

geometric extents in UCS

Anonymous
Not applicable

I want to draw a frame around text, using GeometricExtents property works good for texts, that are not rotated compared to WCS, but i can't figure out the way to do it for rotated texts.

0 Likes
1,095 Views
3 Replies
Replies (3)
Message 2 of 4

Paulio
Advocate
Advocate

Have you tried using

Autodesk.AutoCAD.Internal.Utils.GetTextExtents

 

This gives you a point2d of the extents of the text which you can then use to figure out where to draw your frame (i.e. by adding this point onto the location of your text).

 

Kind of like this

Using trans As Transaction = db.TransactionManager.StartTransaction
                Dim mTxt As MText = trans.GetObject(oid, OpenMode.ForRead)
                Dim pext As Point2d = Autodesk.AutoCAD.Internal.Utils.GetTextExtents(db.TextStyleTableId, mTxt.Contents, 200)
                Dim pline As New Polyline
                pline.AddVertexAt(0, New Point2d(mTxt.Location.X, mTxt.Location.Y), 0, 0, 0)
                pline.AddVertexAt(1, New Point2d(mTxt.Location.X + pext.X, mTxt.Location.Y), 0, 0, 0)
                pline.AddVertexAt(2, New Point2d(mTxt.Location.X + pext.X, mTxt.Location.Y - pext.Y), 0, 0, 0)
                pline.AddVertexAt(3, New Point2d(mTxt.Location.X, mTxt.Location.Y - pext.Y), 0, 0, 0)
                pline.Closed = True

                Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim btr As BlockTableRecord = trans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                btr.AppendEntity(pline)
                trans.AddNewlyCreatedDBObject(pline, True)
                trans.Commit()
            End Using

 It seems to work ok whether in world or ucs if the angle of the text is 0. If the text itself is rotated then you'll need to transform your frame to rotate it to the same angle as the text.

 

It won't work for text that's rotated in 3d though.

 

It will also only work in 2010 as I don't think the ...Internal.Utils.GetTextExtents is available prior to that.

 

HTH

0 Likes
Message 3 of 4

Anonymous
Not applicable

thank you, i will test it and post result, i work in 2011, so it should be OK

0 Likes
Message 4 of 4

Anonymous
Not applicable

hm, the edit option has limited time, so i have to do new post, sorry

 

it works great, BUT

i modified your code slightly, because i use it for single line text and that doesn't use Location, but Position property

but this property represents the point "on the line", so for text with characters that have "underline" part, the frame is shifted a little up

0 Likes