Author Topic: Fun with MText  (Read 9794 times)

0 Members and 1 Guest are viewing this topic.

MaksimS

  • Guest
Fun with MText
« on: April 13, 2007, 10:32:10 AM »
I recently noticed very strange behaviour of MText in ACAD2007 (please correct me if this is not a bug, since I don't use MText type on regular basis):

1) create MText object
2) Contents = "100"+"m\U+00B2" (square meters)
3) Attachment = AttachmentPoint.MiddleCenter
4) TextHeight = 1
5) Location = some Point3D value...
6) append MText object to the BlockTable and commit Transaction

Now, newly created MText object gets displayed in ModelSpace, but... when I try to manually move/copy/rotate it using it's only grip (AttachmentPoint.MiddleCenter on given Location) ACAD somehow switches to the object selection mode (?!?)

What am I doing wrong here? :-)

Regards,
Maksim Sestic
« Last Edit: April 13, 2007, 10:33:36 AM by MaksimS »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun with MText
« Reply #1 on: April 13, 2007, 10:51:41 AM »
I'm off to bed, so I probably won't be involved in your answer, but you really should post enough code for people to see what you are doing ... or better still enough code to demonstrate the problem by example when the code is run.

Trust me, you stand a better chance of getting a satisfactory answer if you do.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MaksimS

  • Guest
Re: Fun with MText
« Reply #2 on: April 13, 2007, 11:01:13 AM »
I know, I know :-) Alas, this little thingy involves couple of classes in my code and I can't fully post it, what I wrote was the "essence" of the problem :-) It should be easy for anyone to reproduce described behavior. It looks like a bug to me, but it's also possible that I'm missing something important regarding MText objects in general (?)

The code should look like:

Dim txt As New MText
txt.Contents = "100m\U+00B2"
txt.Attachment = AttachmentPoint.MiddleCenter
txt.TextHeight = 1
txt.Location = some Point3D value...
then just append it to the BT (model space), add it to the running Transaction and commit it.

Actually there's no problem with creating MText per se, the problem is manually modifying created (database resident) MText using it's grip.

Regards,
Maksim Sestic


I'm off to bed, so I probably won't be involved in your answer, but you really should post enough code for people to see what you are doing ... or better still enough code to demonstrate the problem by example when the code is run.

Trust me, you stand a better chance of getting a satisfactory answer if you do.

« Last Edit: April 13, 2007, 11:11:25 AM by MaksimS »

Draftek

  • Guest
Re: Fun with MText
« Reply #3 on: April 13, 2007, 11:10:00 AM »
Remarkably enough, I have just been working on some MText and the only difference in my code is I am setting the rotation property.

I grab the grip and it works as expected.

MaksimS

  • Guest
Re: Fun with MText
« Reply #4 on: April 13, 2007, 11:19:31 AM »
Huh, I have no faintest idea what's wrong with it. I'm using Autodesk Map 3D 2007 here, but that makes no difference. Look what happens with created MText. Then, when I try to pick that MText grip ACAD enters entity selection mode (?)

(I don't set the MText width, maybe that's a problem?)



Remarkably enough, I have just been working on some MText and the only difference in my code is I am setting the rotation property.

I grab the grip and it works as expected.
« Last Edit: April 13, 2007, 11:21:56 AM by MaksimS »

LE

  • Guest
Re: Fun with MText
« Reply #5 on: April 13, 2007, 11:37:29 AM »
You need to set the Width to show the grips.

Code: [Select]
[CommandMethod("DOMTEXT")]
public void domtext()
{
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor   ed  = doc.Editor;
    Database db  = doc.Database;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        MText MTextObj = new MText();
        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
        MTextObj.Contents = "100" + "m\\U+00B2";
        MTextObj.Attachment = AttachmentPoint.MiddleCenter;
        MTextObj.TextHeight = 1;
        MTextObj.Width = 10;
        btr.AppendEntity(MTextObj);
        tr.AddNewlyCreatedDBObject(MTextObj, true);
        tr.Commit();
    }
}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun with MText
« Reply #6 on: April 14, 2007, 12:42:36 AM »
You could try

MTextObj.Width = (MTextObj.ActualWidth * 1.1) ;

to ensure the .Width satisfies Goldilocks.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun with MText
« Reply #7 on: April 14, 2007, 01:26:55 AM »
Though, I'm still not sure I understand the actual question.

MaksimS,
What are your expectations here.
Is it just to be able to select (one of) the width/height grips and rotate/move/copy relative to that ??

I don't understand this bit
Quote
... using it's only grip (AttachmentPoint.MiddleCenter on given Location) ACAD somehow switches to the object selection mode (?!?)

 
 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MaksimS

  • Guest
Re: Fun with MText
« Reply #8 on: April 14, 2007, 03:05:19 AM »
Hi Kerry,

Actually, I was just creating regular MText entity when I noticed this strange bahaviour. Yes, sounds strange, but - when I create MText object and don't set it's width (defaults to zero), like explained in my previous post - I can't use it's grip for manually modifying the MText entity. When I try to pick a grip, instead of entering MText modify state, ACAD somehow switches to entity select state (display blue rectangle and asks to select entities)... On the other hand - maybe I'm doing something wrong.

My testing configuration is:
- Autodesk Map 3D 2007 + latest Service Pack
- Windows XP Professional
- .NET 2.0
- Visual Studio 2005

When MText's width defaults to zero and you add it to the database (say, ModelSpace), it displays the MText entity with only one grip available (in my case the grip lies at AttachmentPoint.MiddleCenter). There are no other grips since MText's width equals to 0. Actually, I don't even want to set it's width. Somehow I think that this buggy behaviour doesn't have to do with Width property at all.

Please find attached DWG with this silly-acting MText entity - just try to move it around using it's grip.

Regards,
Maksim Sestic


Though, I'm still not sure I understand the actual question.

MaksimS,
What are your expectations here.
Is it just to be able to select (one of) the width/height grips and rotate/move/copy relative to that ??

I don't understand this bit
Quote
... using it's only grip (AttachmentPoint.MiddleCenter on given Location) ACAD somehow switches to the object selection mode (?!?)

 
 


MaksimS

  • Guest
Re: Fun with MText
« Reply #9 on: April 14, 2007, 03:44:36 AM »
Hmmm, I guess I found what's wrong with it :-) Still, I don't get it's behaviour within Editor.

It's about MText location, not it's Width. Now, what I was doing is passing by value a Point3d from other function that calculates location of centroid. It displays the MText as expected, but it's coordinates somehow default to 0,0,0 (?)... despite the fact that MText was not positioned on 0,0,0. The only change to the code was:

This one doesn't work:
m_Text.Location = m_Entity.Centroid

This one works right:
m_Text.Location = New Point3d(m_Entity.Centroid.X, m_Entity.Centroid.Y, m_Entity.Centroid.Z)

:-) Silly.

« Last Edit: April 14, 2007, 03:46:00 AM by MaksimS »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun with MText
« Reply #10 on: April 14, 2007, 07:28:19 AM »
That is really unusual the insert is says 0,0,0 but it is nowhere near correct the actual location.
I'd sure like to see the code ....
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MaksimS

  • Guest
Re: Fun with MText
« Reply #11 on: April 14, 2007, 08:59:39 AM »
I hope you've seen the DWG example I attached few posts ago. Haven't seen anything like this before, plus it doesn't crash ACAD. Weird.

Now for the sad part... There are more than 10 classes backing this process up and I can't send them here :-( This little thingy is a part of much larger AutodeskGeometryFactory set of classes (500+ Kbs) and I see no reasonable way of extracting usable example for posting. Damn OOP, makes stripping examples out near impossible...

Anyways, I'll try to debug the thing all the way back and post results for reviewing.

That is really unusual the insert is says 0,0,0 but it is nowhere near correct the actual location.
I'd sure like to see the code ....
« Last Edit: April 14, 2007, 09:02:16 AM by MaksimS »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Fun with MText
« Reply #12 on: April 14, 2007, 09:04:04 AM »
I hope you've seen the example I attached few posts ago. Haven't seen anything like this before, plus it doesn't crash ACAD. Weird.

......................
That is really unusual the insert is says 0,0,0 but it is nowhere near correct the actual location.
I'd sure like to see the code ....

Yes, the drawing mText.dwg is what I looked at and commented on.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MaksimS

  • Guest
Re: Fun with MText
« Reply #13 on: April 14, 2007, 09:21:28 AM »
I'll try to give it a shot:

Here's the method that creates actual MText:

Public Shared Sub BuildingTextArea()
        Using m_Entity As New Building
            Dim m_ObjectIds As ObjectId() = AutodeskFeatureFactory.GetEntity(m_Entity.ElementName)
            If m_ObjectIds.Length > 0 Then
                m_Entity.SaveSystemVariables()
                Using m_ProgressBar As New AcUtProgressBar("Processing...", m_ObjectIds.Length)
                    Dim m_Text As New AcText(m_Entity.Database, m_Entity.Transaction)
                    m_Text.Layer.Name = m_Entity.Layer.Name + "_ANNOTATION"
                    Try
                        For Each m_ObjectId As ObjectId In m_ObjectIds
                            m_Entity.ObjectId = m_ObjectId

                            m_Text.Contents = _
                                "P=" + _
                                AutodeskFeatureFactory.GetAttributeValue(m_ObjectId, m_Entity.ElementName, "FootprintSurface").ToString + _
                                "m\U+00B2"
                            m_Text.Height = 1
                            m_Text.Location = m_Entity.Centroid <<<============ Here it is
                            m_Text.ParentId = m_ObjectId
                            m_Text.Insert()
                        Next
                        m_Entity.TransactionCommit()
                    Finally
                        m_Entity.TransactionDispose()
                    End Try
                End Using
                m_Entity.RestoreSystemVariables()
            Else
                AcUtEditor.WriteMessage("No entities.")
            End If
        End Using
    End Sub

=========================
Now to the AcGeMPolygon class and it's Centroid property:

Public ReadOnly Property Centroid() As Point3d
            Get
                Dim m_Result As Point3d
                Dim m_MPolygon As MPolygon = Me.GetEntityForRead
                If m_MPolygon IsNot Nothing Then
                    Using AGF As New AutodeskGeometryFactory(Me.Database, Me.Transaction)
                        Dim m_MPolygonLoop As MPolygonLoop = m_MPolygon.GetMPolygonLoopAt(0)
                        Dim m_Point2dCollection As New Point2dCollection
                        For Each m_BulgeVertex As BulgeVertex In m_MPolygonLoop
                            m_Point2dCollection.Add(m_BulgeVertex.Vertex)
                        Next
                        Dim m_MultiPoint As MultiPoint = AGF.CreateMultiPoint(m_Point2dCollection)
                        Dim m_LinearRing As New LinearRing(m_MultiPoint.Coordinates)
                        m_Result = AGF.CreateAcGePoint3d(m_LinearRing.Centroid)    <<<============== See below...
                    End Using
                End If
                Return m_Result
            End Get
        End Property

=========================

Now to the AutodeskGeometryFactory method that actually instantiates Point3D

    Public Function CreateAcGePoint3d(ByVal point As Point) As Point3d
        Return New Point3d(point.X, point.Y, point.Z)
    End Function

=========================

What for a simple MText example... :-)




LE

  • Guest
Re: Fun with MText
« Reply #14 on: April 14, 2007, 12:54:58 PM »
I see now... weird behavior, it does not zoom to extents, if it is exploded nothing is shown, it does not allowed to paste in another drawing from scratch, you see the preview but it does not visible, you can list the drawing for all and it tells it is a mtext, but not visible...