Author Topic: Transient graphics not showing Text  (Read 507 times)

0 Members and 1 Guest are viewing this topic.

ROYNIJKAMP

  • Mosquito
  • Posts: 12
Transient graphics not showing Text
« on: June 11, 2020, 07:25:19 AM »
I am displaying a temporary line between 2 picked polylines.
The line is showing as expected execept for the Text object.
I have tried to add a Text to the Transient Graphics, but is it not showing.
Why is the Text not showing, is it not possible to show the text on the Fly?

Below the code i use.
Code - vb.net: [Select]
  1. Public Class clsMarkerLine
  2.     Private Shared plStart As Polyline
  3.     Private Shared plEind As Polyline
  4.  
  5.     Private Shared m_markers As DBObjectCollection = New DBObjectCollection()
  6.     Private Shared collectints As IntegerCollection = New IntegerCollection()
  7.  
  8.     Public Shared Sub StartMarker(ByVal polyStart As Polyline, ByVal polyEind As Polyline)
  9.         Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  10.         AddHandler ed.PointMonitor, New PointMonitorEventHandler(AddressOf ed_PointMonitor)
  11.         plStart = polyStart
  12.         plEind = polyEind
  13.     End Sub
  14.  
  15.     Public Shared Sub StopMarker()
  16.         Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  17.         ed.TurnForcedPickOn()
  18.         RemoveHandler ed.PointMonitor, New PointMonitorEventHandler(AddressOf ed_PointMonitor)
  19.         ClearMarkers()
  20.     End Sub
  21.  
  22.     Private Shared Sub ed_PointMonitor(ByVal sender As Object, ByVal e As PointMonitorEventArgs)
  23.         showLine(e.Context.RawPoint)
  24.     End Sub
  25.  
  26.     Private Shared Sub showLine(ByVal pt As Point3d)
  27.         ClearMarkers()
  28.         'marker line
  29.         Dim myLine As Line = dynLine(pt)
  30.         m_markers.Add(myLine)
  31.         aGi.TransientManager.CurrentTransientManager.AddTransient(myLine, aGi.TransientDrawingMode.DirectShortTerm, 128, collectints)
  32.                 'marker text
  33.         Dim myText As DBText = dynLineLengthText(pt, myLine)
  34.         m_markers.Add(myText)
  35.         aGi.TransientManager.CurrentTransientManager.AddTransient(myText, aGi.TransientDrawingMode.DirectShortTerm, 128, collectints)
  36.        
  37.     End Sub
  38.  
  39.     Public Shared Function dynLine(pt As Point3d, Optional sLayer As String = "0") As Line
  40.         Dim myLine As Line = New Line()
  41.         myLine.StartPoint = pt
  42.         myLine.EndPoint = plStart.GetClosestPointTo(pt, True)
  43.         Dim pts As New Point3dCollection()
  44.         myLine.IntersectWith(plEind, Intersect.ExtendThis, pts, New IntPtr(0), New IntPtr(0))
  45.         If pts.Count > 0 Then
  46.             myLine.StartPoint = pts(0)
  47.         End If
  48.         myLine.Layer = sLayer
  49.         myLine.ColorIndex = 10
  50.         dynLine = myLine
  51.     End Function
  52.  
  53.    
  54.  
  55.     Public Shared Function dynLineLengthText(pt As Point3d, ln As Line, Optional sLayer As String = "0") As DBText
  56.         Dim acText As DBText = New DBText()
  57.         Dim dStart As Double = (ln.StartPoint.X + ln.EndPoint.X) / 2
  58.         Dim dEind As Double = (ln.StartPoint.Y + ln.EndPoint.Y) / 2
  59.         Dim ptCenter As Point3d = New Point3d(dStart, dEind, 0)
  60.         Dim CustomLineParmameters As CustomLineParam = getCustomLineParam(ln, ptCenter, True, False, 0.0, 0.5)
  61.         Dim newAngle As Double = CustomLineParmameters.Angle
  62.        
  63.         acText.Rotation = newAngle * Math.PI / 180
  64.         acText.TextString = Math.Round(CustomLineParmameters.LineLength, 2).ToString & " m"
  65.         acText.Position = CustomLineParmameters.Point
  66.         acText.Layer = sLayer
  67.         acText.ColorIndex = 10
  68.         dynLineLengthText = acText
  69.     End Function
  70. End Class

n.yuan

  • Bull Frog
  • Posts: 289
Re: Transient graphics not showing Text
« Reply #1 on: June 11, 2020, 12:12:06 PM »

...

Code - vb.net: [Select]
  1. Public Class clsMarkerLine
  2.    
  3.     ...
  4.     Private Shared collectints As IntegerCollection = New IntegerCollection()
  5.  
  6.    ...
  7.  
  8.     Private Shared Sub showLine(ByVal pt As Point3d)
  9.         ClearMarkers()
  10.         'marker line
  11.         Dim myLine As Line = dynLine(pt)
  12.         m_markers.Add(myLine)
  13.         aGi.TransientManager.CurrentTransientManager.AddTransient(myLine, aGi.TransientDrawingMode.DirectShortTerm, 128, collectints)
  14.                 'marker text
  15.         Dim myText As DBText = dynLineLengthText(pt, myLine)
  16.         m_markers.Add(myText)
  17.         aGi.TransientManager.CurrentTransientManager.AddTransient(myText, aGi.TransientDrawingMode.DirectShortTerm, 128, collectints)
  18.        
  19.     End Sub
  20.  
  21.     ...
  22.  
  23. End Class

I think the issue lies in the argument of IntegerCollection passed into AddTransient() method: you need to pass a new/empty IntegerCollection, not one shared by multiple calls, like:

TransientManager.AddTransient(myLine, aGi.TransientDrawingMode.DirectShortTerm, 128, new IntegerCollection())
TransientManager.AddTransient(myText, aGi.TransientDrawingMode.DirectShortTerm, 128, new IntegerCollection())


huiz

  • Swamp Rat
  • Posts: 869
  • Certified Prof C3D
Re: Transient graphics not showing Text
« Reply #2 on: June 11, 2020, 01:24:54 PM »
I am not sure if it is impossible but I had only success with shx fonts, not with ttf fonts.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Jeff_M

  • King Gator
  • Posts: 3975
  • C3D user & customizer
Re: Transient graphics not showing Text
« Reply #3 on: June 11, 2020, 01:29:04 PM »
I have always used the single IntergerCollection for any number of objects to be displayed, Norman.

If the text style used is a TrueType font, trying changing to one that uses an SHX font. I seem to recall having issues with TT fonts in TransientGraphics. huiz beat me to this.


n.yuan

  • Bull Frog
  • Posts: 289
Re: Transient graphics not showing Text
« Reply #4 on: June 11, 2020, 06:09:39 PM »
I have always used the single IntergerCollection for any number of objects to be displayed, Norman.
...

Good to know, Jeff. Thanks.

ROYNIJKAMP

  • Mosquito
  • Posts: 12
Re: Transient graphics not showing Text
« Reply #5 on: June 15, 2020, 05:07:53 AM »
Thanks for the quick responses.

At the moment i have tried 2 options with SHX text with no luck at all.
What i tried so far:
option 1
  • manual created a text style with SHX font
  • set new created style as default/current
  • Create a DBText object with just a TextString and a Position and add it to the Transientmanager
option 2
  • create a shx textstyle by code
  • set textstyle as default/current
  • Create a DBText object with just a TextStyle objectid, TextString and a Position and add it to the Transientmanager

Is so difficult to show the Text object or am i missing something?

Jeff_M

  • King Gator
  • Posts: 3975
  • C3D user & customizer
Re: Transient graphics not showing Text
« Reply #6 on: June 15, 2020, 06:23:10 PM »
You aren't setting the DBText to use a TextStyle. Also, if the Style doesn't have a defined height, you need to also set that. Here I'm tracking along a street alignment and added the word Test to the cursor location.

This is the code to show the graphics:
Code - C#: [Select]
  1.         private void showLine_and_X(Point3d curPt, Point3d pt3, double scale)
  2.         {
  3.             ClearMarkers();
  4.             Line line1 = new Line(curPt, pt3);
  5.             Line line2 = new Line(Utility.PolarPoint(pt3, line1.Angle + (Math.PI * 0.25), 0.15 * scale), Utility.PolarPoint(pt3, line1.Angle + (Math.PI * 1.25), 0.15 * scale));
  6.             Line line3 = new Line();
  7.             line3.StartPoint = line2.StartPoint;
  8.             line3.EndPoint = line2.EndPoint;
  9.             line3.TransformBy(Matrix3d.Rotation(Math.PI * 0.5, Vector3d.ZAxis, pt3));
  10.             line1.ColorIndex = 1;
  11.             line2.ColorIndex = 3;
  12.             line3.ColorIndex = 3;
  13.             var txt = new DBText();
  14.             txt.TextString = "Test";
  15.             txt.Position = curPt;
  16.             txt.TextStyleId = styleid; //this is saved as a global variable in the command code
  17.             txt.Height = 4.0;
  18.             aGi.TransientManager.CurrentTransientManager.AddTransient(line1, aGi.TransientDrawingMode.DirectShortTerm, 128, intColl);
  19.             aGi.TransientManager.CurrentTransientManager.AddTransient(line2, aGi.TransientDrawingMode.DirectShortTerm, 128, intColl);
  20.             aGi.TransientManager.CurrentTransientManager.AddTransient(line3, aGi.TransientDrawingMode.DirectShortTerm, 128, intColl);
  21.             aGi.TransientManager.CurrentTransientManager.AddTransient(txt, aGi.TransientDrawingMode.DirectShortTerm, 128, intColl);
  22.  
  23.             m_mrkers.Add(line1);
  24.             m_mrkers.Add(line2);
  25.             m_mrkers.Add(line3);
  26.             m_mrkers.Add(txt);
  27.         }
  28.  
« Last Edit: June 15, 2020, 07:15:09 PM by Jeff_M »

ROYNIJKAMP

  • Mosquito
  • Posts: 12
Re: Transient graphics not showing Text
« Reply #7 on: July 02, 2020, 06:16:00 AM »
Thanks Jeff for pointing me in the right direction.
The problem was not defining a height in my style and not when creating the text.
After setting the height my Text is shown.

I'm feeling stuppid to overlook this. :uglystupid2:

CADbloke

  • Bull Frog
  • Posts: 321
  • Crash Test Dummy
Re: Transient graphics not showing Text
« Reply #8 on: July 03, 2020, 07:02:16 PM »
.SetDatabaseDefaults() can avoid some of these kinds of hassles. Not all, just some.