Can't see text in drawing created from code, but qselect finds it

Can't see text in drawing created from code, but qselect finds it

andrew_demerchant
Enthusiast Enthusiast
1,818 Views
14 Replies
Message 1 of 15

Can't see text in drawing created from code, but qselect finds it

andrew_demerchant
Enthusiast
Enthusiast

I'm adding text to a drawing via this code:

 

                        Dim theTextLabel As New Autodesk.AutoCAD.DatabaseServices.DBText()
                        theTextLabel.SetDatabaseDefaults()
                        'theTextLabel.Height = 5
                        theTextLabel.TextString = Me.ctlPID.Text
                        theTextLabel.Position = New Point3d(centroid(0), centroid(1), 0)
                        theTextLabel.Justify = AttachmentPoint.MiddleCenter
                        btr.AppendEntity(theTextLabel)
                        trans.AddNewlyCreatedDBObject(theTextLabel, True)

In the drawing, you can't see the text at all, and you can't select it with the cursor or draw a box around it.But if you qselect, you can find it, and it gets selected. The contents are correct, but no matter what I change ) be it the font, size, etc it never shows up as visible in the drawing. Any ideas?? I'm totally stumped here...

0 Likes
Accepted solutions (1)
1,819 Views
14 Replies
Replies (14)
Message 2 of 15

fieldguy
Advisor
Advisor

You should set a text style (theTextLabel.TextStyleId = the object id of the text style to use).

 

>>check here<<

0 Likes
Message 3 of 15

andrew_demerchant
Enthusiast
Enthusiast
It's got a style though - it's set via theTextLabel.SetDatabaseDefaults(), and when I see it's properties in cad, it's right - it's using my template's default style.
0 Likes
Message 4 of 15

_gile
Consultant
Consultant

Hi

 

As the DBText.Justify property is different from AttachmentPoint.BaseLeft, you have to specify the DBText.AlignmentPoint property.

 

Try with:

 

theTextLabel.Position = Point3d.Origin
theTextLabel.Justify = AttachmentPoint.MiddleCenter
theTextLabel.AlignmentPoint = New Point3d(centroid(0), centroid(1), 0)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 15

andrew_demerchant
Enthusiast
Enthusiast
Even if I leave out the justify altogether, it's still the same problem.
0 Likes
Message 6 of 15

Alexander.Rivilis
Mentor
Mentor

1) layer of entity is off?

2) Also I've not found

theTextLabel.AdjustAlignment

3) Heigth of text is 0?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 7 of 15

andrew_demerchant
Enthusiast
Enthusiast
Layers are all on - height isn't zero.
0 Likes
Message 8 of 15

SENL1362
Advisor
Advisor
Are you debugging with Visual Studio?
Is the text also invisible when opening the DWG outside of visualStudio?
0 Likes
Message 9 of 15

andrew_demerchant
Enthusiast
Enthusiast

Ah - now we're getting somewhere...that was debugging. Seems that when I run it for real (or even save from debugging and then re-open) there's a slightly different, though still weird, result.

If I save the debug dwg, and then open it normally, I can actually see and select my text - but here's the weird part...if I try to do something to it, it moves to 0,0...so that goes for changing layers, changing the height, or running a command on it like move, etc.

If I run the compiled code without debugging, I get something closer to the end result above...I get my txt at 0,0 (which isn't where it's supposed to be). There's definitely something screwy going on with my text entity....just no idea what....

0 Likes
Message 10 of 15

SENL1362
Advisor
Advisor
I currently can't run Visual but there are some settings you have to alter to see text in a debugged session.
I will send you these settings first thing tomorrow morning if not posted before by any one else on this forum.
0 Likes
Message 11 of 15

andrew_demerchant
Enthusiast
Enthusiast
Thanks! Any thoughts on why it's moving? I'm guessing that even if I get it to show up in the debug session, I'm still going to be left with that problem...
0 Likes
Message 12 of 15

SENL1362
Advisor
Advisor
no clue
0 Likes
Message 13 of 15

andrew_demerchant
Enthusiast
Enthusiast
The plot thickens - knowing that text doesn't show up right in a debug session, I was able to make use of _gile's suggestion to set the AlignmentPoint property. That at least makes the text not move to the origin when a property is changed in a normal session. But it does still move...I tried AdjustAlignment, but that seems to make no difference.
0 Likes
Message 14 of 15

SENL1362
Advisor
Advisor
Accepted solution

 

In order to show text while debuging, you need to set:

Use Legacy Managed Engine = YES

 

Screenshot_2.png

 

Sometimes i needed these settings as well:

C#/AutoCAD/Visual Studio 2013/x64/debug/AutoCAD text errors/Undefined shape
Tools>Options>Debugging>Managed Compatibility Mode=ON
(Select Projext X): Project>Properties>Debug>Enable native code debugging=On

 

Message 15 of 15

andrew_demerchant
Enthusiast
Enthusiast

Thanks! I'm using VS Express, so I had to make that change via a project file edit, but that did the trick. Oddly enough, after making that change, my text shows up in the right spot, and no longer moves on it's own after changing properties...very strange to me that a debugging engine change would affect the final biuld, but it seems to. I'm not going to complain, since my problem is seemingly solved. For what it's worth, this is my final working code:

 

                        Dim theTextLabel As New Autodesk.AutoCAD.DatabaseServices.DBText()
                        theTextLabel.SetDatabaseDefaults()
                        theTextLabel.Height = 5
                        theTextLabel.TextString = Me.ctlPID.Text

                        theTextLabel.Position = New Point3d(centroid(0), centroid(1), 0)
                        theTextLabel.Annotative = AnnotativeStates.False

                        theTextLabel.Justify = AttachmentPoint.MiddleCenter
                        theTextLabel.AlignmentPoint = New Point3d(centroid(0), centroid(1), 0)
                        theTextLabel.AdjustAlignment(db)

                        btr.AppendEntity(theTextLabel)
0 Likes