.NET

Reply
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 1 of 17 (678 Views)
Accepted Solution

GetBoundingBox error

678 Views, 16 Replies
11-29-2011 01:27 AM
I have written the below code, Dim GE As Extents3d GE = Txt.GeometricExtents OldTxtWidth = GE.MaxPoint.X - GE.MinPoint.X But i am not getting the width of the text properly. In maxpoint i am always getting 0. Can anyone please help me out from this issue? Thank you.
*Expert Elite*
Alfred.NESWADBA
Posts: 8,888
Registered: ‎06-29-2007
Message 2 of 17 (674 Views)

Re: GetBoundingBox error

11-29-2011 02:39 AM in reply to: muthineni

Hi,

 

Textojects and Attributes makes me always thinking that I have to kick someone because of this problem :smileywink:

For me I do first the normal GeometricExtents-handling and if there is Min- or MaxPoint as 0,0,0 I check it using the COM-way, e.g.:

ctype(myTextObj.AcadObject,Interop.Common.AcadText).GetBoundingBox(PntMin,PntMax)

But be careful ==> that only works if the Text- or AttRef-object is already in the database.

 

- alfred -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 3 of 17 (673 Views)

Re: GetBoundingBox error

11-29-2011 02:50 AM in reply to: Alfred.NESWADBA
I am new to Autocad Programming, Can you please explain me a bit elaborate on how to get the TextObject Width in vb.net
*Expert Elite*
Alfred.NESWADBA
Posts: 8,888
Registered: ‎06-29-2007
Message 4 of 17 (671 Views)

Re: GetBoundingBox error

11-29-2011 02:58 AM in reply to: muthineni

Hi,

 

>> Can you please explain me a bit elaborate on how to get the TextObject Width in vb.net

you showed the code-snippet already, what should I then describe?

Plus the additional codeline in case of 0,0,0-problem I gave you in my previous message.

 

Sorry, it seems that I don't understand something.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 5 of 17 (670 Views)

Re: GetBoundingBox error

11-29-2011 03:13 AM in reply to: Alfred.NESWADBA
i am extremely sorry i am not able to understand how to get the width of a textobject in general, not if 0 comes. In general can you please tell me the code of how to get the text object width using geometricextents in vb.net?
*Expert Elite*
Alfred.NESWADBA
Posts: 8,888
Registered: ‎06-29-2007
Message 6 of 17 (665 Views)

Re: GetBoundingBox error

11-29-2011 03:28 AM in reply to: muthineni

Hi,

 

look at this code, I wrote that sometimes to get a border around a textobject. That should help you to get the width of the text (rotated or not).

 

      Public Shared Function getStringBorder(ByRef TextObj As DatabaseServices.DBText) As DatabaseServices.Curve
         Dim tRetVal As DatabaseServices.Curve = Nothing
         Dim tWorkObj As DatabaseServices.DBText = TextObj
         Dim tWorkObjIsCloned As Boolean = False
         Try
            If (tWorkObj IsNot Nothing) AndAlso (tWorkObj.TextString.Trim.Length > 0) Then
               If Not tWorkObj.IsWriteEnabled Then
                  'kopieren, damit wir damit arbeiten koennen
                  tWorkObj = CType(tWorkObj.Clone, DatabaseServices.DBText)
                  tWorkObjIsCloned = True
               End If
               Dim tPrevRotation As Double = tWorkObj.Rotation
               If tPrevRotation <> 0 Then
                  'auf waagrecht drehen, sonst kommen wir mit den extents nie zurecht
                  tWorkObj.TransformBy(Geometry.Matrix3d.Rotation(-tPrevRotation, New Geometry.Vector3d(0, 0, 1), tWorkObj.Position))
               End If
               Dim tGeomExtents As DatabaseServices.Extents3d = tWorkObj.GeometricExtents     'damit haben wir jetzt die extents des waagrecht ausgerichteten objekts
               Dim tGeomWidth As Double = tGeomExtents.MaxPoint.X - tGeomExtents.MinPoint.X
               'jetzt muessen wir noch aufpassen, ob wir es hier mit einem map/civil2009-SP2 fehler handelt, da werden naemlich
               '  texte, die nicht linksbuendig sind, so gerechnet als waeren sie linksbuendig
               If (tWorkObj.HorizontalMode <> TextHorizontalMode.TextLeft) AndAlso (tWorkObj.Position.X = tWorkObj.AlignmentPoint.X) Then
                  Select Case tWorkObj.HorizontalMode
                     Case TextHorizontalMode.TextMid, TextHorizontalMode.TextCenter
                        tGeomExtents = New DatabaseServices.Extents3d(New Geometry.Point3d(tGeomExtents.MinPoint.X - tGeomWidth / 2.0, tGeomExtents.MinPoint.Y, tGeomExtents.MinPoint.Z), New Geometry.Point3d(tGeomExtents.MaxPoint.X - tGeomWidth / 2.0, tGeomExtents.MaxPoint.Y, tGeomExtents.MaxPoint.Z))
                     Case TextHorizontalMode.TextRight
                        tGeomExtents = New DatabaseServices.Extents3d(New Geometry.Point3d(tGeomExtents.MinPoint.X - tGeomWidth, tGeomExtents.MinPoint.Y, tGeomExtents.MinPoint.Z), New Geometry.Point3d(tGeomExtents.MaxPoint.X - tGeomWidth, tGeomExtents.MaxPoint.Y, tGeomExtents.MaxPoint.Z))
                     Case Else
                        'TODO
                        'die typen 'aligned' und 'fit' werden hier mal nicht getrennt ausgewertet
                  End Select
               End If
               Dim tCurve As DatabaseServices.Polyline = New DatabaseServices.Polyline()
               tCurve.AddVertexAt(0, New Geometry.Point2d(tGeomExtents.MinPoint.X, tGeomExtents.MinPoint.Y), 0, 0, 0)
               tCurve.AddVertexAt(1, New Geometry.Point2d(tGeomExtents.MaxPoint.X, tGeomExtents.MinPoint.Y), 0, 0, 0)
               tCurve.AddVertexAt(2, New Geometry.Point2d(tGeomExtents.MaxPoint.X, tGeomExtents.MaxPoint.Y), 0, 0, 0)
               tCurve.AddVertexAt(3, New Geometry.Point2d(tGeomExtents.MinPoint.X, tGeomExtents.MaxPoint.Y), 0, 0, 0)
               tCurve.Closed = True
               If tPrevRotation <> 0 Then
                  'polylinie zum text hindrehen, textobj zurueckdrehen
                  tCurve.TransformBy(Geometry.Matrix3d.Rotation(tPrevRotation, New Geometry.Vector3d(0, 0, 1), tWorkObj.Position))
                  tWorkObj.TransformBy(Geometry.Matrix3d.Rotation(tPrevRotation, New Geometry.Vector3d(0, 0, 1), tWorkObj.Position))
               End If
            End If
         Catch ex As Exception
            Call MsgBox("Error during calculation of TextBorder" & ex.Message)
         Finally
            If tWorkObjIsCloned Then tWorkObj.Dispose()
         End Try
         Return tRetVal
      End Function

 - alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 7 of 17 (631 Views)

Re: GetBoundingBox error

12-05-2011 03:19 AM in reply to: muthineni
same problem with the above code also, in the below line, Dim tGeomWidth As Double = tGeomExtents.MaxPoint.X - tGeomExtents.MinPoint.X Maxpoint.x is always coming as 0. Could anyone please help me out from this issue? Thank you.
*Expert Elite*
Alfred.NESWADBA
Posts: 8,888
Registered: ‎06-29-2007
Message 8 of 17 (627 Views)

Re: GetBoundingBox error

12-05-2011 03:34 AM in reply to: muthineni

Hi,

 

can you reproduce that with a specific drawing? If so:

  • upload this drawing
  • let us know your producttype (if it's a vertical product)
  • let us know revision + servicepack

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 9 of 17 (624 Views)

Re: GetBoundingBox error

12-05-2011 03:51 AM in reply to: Alfred.NESWADBA

Please find the attached drawing,

In that for eaxmple for cirlce 1 (1 written inside circle), 11440-15 B1 SW ,  should be changed to -T  and the circle should be deleted, so that the text should be moved left for that the new width should be known.

Can you please check whether the min and max points are coming correctly or not?

I am using visual studio 2008 and autocad 2007.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,888
Registered: ‎06-29-2007
Message 10 of 17 (615 Views)

Re: GetBoundingBox error

12-05-2011 04:32 AM in reply to: muthineni

Hi,

 

you speak German? ... just because of layernaming :smileywink:

 

>> Can you please check whether the min and max points are coming correctly or not?

Well I don't have 2007 to test now (maybe at night), so at the moment I just have tips you can try:

You have some textstyles with "bigfont"-usage. Try to change them not to use this option, save the drawing (with another name) and try it once more.

 

With 2012 and bigfont switched off (as I don't have yours) I get Extents.MaxPoint.X <> 0 as a result using this checkcode:

   <Runtime.CommandMethod("ADESK_getMinMax")> _
   Public Shared Sub ADESK_getMinMax()
      Dim tAcadDoc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
      Dim tTrAct As DatabaseServices.Transaction = Nothing
      Try
         tTrAct = tAcadDoc.TransactionManager.StartTransaction

         Dim tRes As EditorInput.PromptEntityResult = tAcadDoc.Editor.GetEntity("Select Entitiy: ")
         If (tRes IsNot Nothing) AndAlso (tRes.Status = EditorInput.PromptStatus.OK) AndAlso (tRes.ObjectId.IsValid) Then
            Dim tEnt As DatabaseServices.Entity = CType(tTrAct.GetObject(tRes.ObjectId, DatabaseServices.OpenMode.ForRead), DatabaseServices.Entity)

            'first test through direct access
            Dim tExtents As DatabaseServices.Extents3d = tEnt.GeometricExtents
            tAcadDoc.Editor.WriteMessage(vbNewLine & "DEFAULT: MinX: " & Format(tExtents.MinPoint.X, "#0.00") & " / MaxX: " & Format(tExtents.MaxPoint.X, "#0.00"))

            'second approach using COM
            'you have to add the reference for that:
            '  Autodesk.AutoCAD.Interop.Command
            Dim tEntCOM As Interop.Common.AcadEntity = CType(tEnt.AcadObject, Interop.Common.AcadEntity)
            Dim tPntMin As Object
            Dim tPntMax As Object
            Call tEntCOM.GetBoundingBox(tPntMin, tPntMax)
            tAcadDoc.Editor.WriteMessage(vbNewLine & "COM:     MinX: " & Format(CType(tPntMin, Double())(0), "#0.00") & " / MaxX: " & Format(CType(tPntMax, Double())(0), "#0.00"))
         End If

      Catch ex As Exception
         MsgBox("Some exception occured" & vbNewLine & ex.Message)
      Finally
         If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing
      End Try

   End Sub

Please find also in this code that I did check the extents twice, the first version is how I would do it for default, the second version is by using the COM-component (as I mentined earlier).

 

- alfred -

 

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community