News:

Interested in some really terrific mobile apps? Visit www.turboapps.com for details.

Main Menu

how do you set the font before using Graphics.AddText method

Started by jrdarrah, June 30, 2022, 04:29:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jrdarrah

I was able to get add text to work in Visual Studio C# but so far I can't find out how to set the font. Where is that documented?

nikkipollard

#1
You would need to change the properties of the text.
I am not sure how it is done in c# but it should be a similar  concept to vb.net.
The graphic (text) would have a list of properties
change the value of that property

presuming you used the dwg.Graphics.AddText method, this is the vb.net code

Dim Mytext as IMSIGX.Graphic
Mytext = TcDraw.Graphics.AddText("My string", 0,0,0,200)
MyText.Properties.Item("TextFont").Value = "Verdana"
MyTex.Properties.Item("TextFormat").Value = 257           ' top left alignment

If you use the Regen method (the method the macro recorder uses) then you can use a defined property preset in the drawing the text will have the properties of the property preset

Dim gfx as IMSIGX.Graphic
gfx = tcDraw.Graphics.Add(6,"TCW40TEXT".False,"Normal Text")
gfx.Properties.Item("Info").Value = "Some words"
gfx.MoveAbsolute(1000,200,0,0,0,0)

Most graphics work like this I use the macro recorder to find out the name of the property I want to change.
Or I use excel VBA to get a list of properties for each type. By querying the selected graphic.

There is Documentation and examples provided in the program directory of the platinum version but unfortunately it is all Visual basic or C++ so you will need to guess the correct syntax for c#. There are also examples in that folder.




Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

jrdarrah

Thanks for the help. I've been trying to get the statement to set the font working for quite time time and so far nothing has worked. I tried converting the vb.net statements you posted into C#. My C# program works, it accesses turbocad, creates a drawing, draws some lines and adds text.

Here are the relevant parts of my code.

using IMSIGX;

        private IMSIGX.Application tcApp;
        private IMSIGX.IDrawing tcActDwg;
        private IMSIGX.View tcActVw;
        private IMSIGX.Graphics tcGrs;
        private IMSIGX.IGraphic tcGr;
        private IMSIGX.Vertices grVerts;
        private IMSIGX.IGraphic myText;

I can't use IMSIGX.Drawing or IMSIGX.Graphic, I have to use IDrawing and IGraphic to make my program execute.

                        tcApp = new IMSIGX.Application();
                        tcApp.Visible = true;
                        tcApp.Drawings.Add();
                        tcActDwg = tcApp.ActiveDrawing;
                        tcActVw = tcActDwg.ActiveView;
                        tcGrs = tcActDwg.Graphics;
                        tcGr = tcGrs.Add(11);
                        grVerts = tcGr.Vertices;
                        grVerts.Clear(0);
                        grVerts.UseWorldCS = true;
 
Add a line of text...

                        myText = tcGrs.AddText("Tip= " + Convert.ToString(pointsArray[0].y), 0, 0.25, 0, 0.0625,0,0,0,Left);

                    myText.Properties.Item("TextFont").Value = "Verdana";

Everything works except the myText.Properties.Item statement. I get this error.
'Properties' does not contain a definition for 'Item' and no accessible extension method 'Item' accepting a first argument of type 'Properties' could be found (are you missing a using directive or an assembly reference?)   Turbocad_import_CSV



Add another line...

                        tcGrs.AddText("Tail= " + Convert.ToString(pointsArray[nbrPoints].y), pointsArray[nbrPoints].x-0.5, 0.25, 0, 0.0625,0, 0.5,0, Right);

                        tcGr.Draw();
                        tcActVw.ZoomToExtents();
                        tcGr.Update();

What am I missing? There must be a way to specify the font.

nikkipollard

#3
In the sdk section there is an example file with a c# example.
Maybe you can see the syntax for working with properties there.
The roundness property of the round rectangle is changed like this.

varIndex = "Roundness";
               gxProp = Graphic.Properties.get_Item(ref varIndex);
               varValue = Roundness;
               gxProp.set_Value(0,ref varValue );

So if I look in the SDK documentation. And I look at the IMSIGXReference.chm go down to the properties section, in the IMSIGX overview section.
The C++ syntax is similar to the C# syntax - if that helps unravelling the mystery.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

jrdarrah

Thanks Nikki, that was the key. This is what finally worked to set the font type for a text string. Hopefully this post will help others along the way.

IMSIGX.Application tcApp;
IMSIGX.IDrawing tcActDwg;
IMSIGX.View tcActVw;
IMSIGX.Graphics tcGrs;
IMSIGX.IGraphic tcGr;
IMSIGX.Vertices grVerts;
IMSIGX.IGraphic myText;
IMSIGX.Properties pProps;
IMSIGX.Property pProp;

object varPropName = "TextFont";
object varVal = "Arial";

myText = tcGrs.AddText(CSVSafeFileName, 0, 0.5, 0,0.0625);
pProps = myText.Properties;
pProp = pProps.get_Item(ref varPropName);
pProp.set_Value(1, ref varVal);

nikkipollard

#5
Quick question
when you set the value of the property.

pProp.set_Value(1, ref varVal);

I presume the 1 is the index of the "TextFont" property in the graphics properties collection.
How did you know that the index was 1?

Does this work in C# - I know its not an integer and C# can be fussy
pProp.set_Value(ref varPropName, ref varVal);
Using the name instead of the index works in vb.net because the function expects an object instead of a long
It makes it easier to use properties because each version
can have a different index number for the same property.

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

jrdarrah

I just copied the code you posted (translated to C#) and it worked. I searched on property.set_Value to try and determine the answer to your question. "set_Value" shows up in some sdk samples but not in the help files. When I started typing in "pProp.set_Value(" it popped up int lcid for that parameter. No clue what lcid is but it seemed happy with a value of 1.

It is frustrating how little good documentation the TC SDK has available.

nikkipollard

I found this document very useful
https://forums.turbocad.com/index.php?topic=2960.0
It is all over the place so you have to search for example code. When the forum is working properly again download it if you haven't already.
Otherwise a similar document is in the programs file SDK section (tcsdk.chm)
As I said previously it is all vba code - so you will need to translate but it explains how the SDK works.


Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h