VB.NET Mtext style

VB.NET Mtext style

Sgear
Advocate Advocate
2,687 Views
7 Replies
Message 1 of 8

VB.NET Mtext style

Sgear
Advocate
Advocate

 

 

Hi

 

How can I set style to mtext

 

Regards

Sgear

 

           Dim objIniFile As New clsIni("c:\file\text.ini")

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim tr As Transaction = db.TransactionManager.StartTransaction()
            ed.Regen()
            Using tr

                Dim pt As Point3d = ed.GetPoint(vbLf & "Select: ").Value
                Dim mtx As New MText()
                mtx.Location = pt
                mtx.SetDatabaseDefaults()
                mtx.TextHeight = 1

                mtx.Width = 35
       
                Dim HK = objIniFile.GetString("MAIN", "HK", "")
                Dim TP1 = objIniFile.GetString("MAIN", "TP1", "")
                Dim TP2 = objIniFile.GetString("MAIN", "TP2", "")
                Dim TP3 = " " + objIniFile.GetString("MAIN", "TP3", "")
                Dim TP4 = objIniFile.GetString("MAIN", "TP4", "")

            
                mtx.Contents = ("{\C1;" + HK + "}\P" + ("{\C1;" + TP1 + "}\P" + ("{\C1;" + TP2 + "}" + ("{\C3;" + TP3 + "}\P" + ("{\C3;" + TP4 + "}\P")))))


                mtx.SetAttachmentMovingLocation(mtx.Attachment)
                Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                btr.AppendEntity(mtx)
                tr.AddNewlyCreatedDBObject(mtx, True)
                tr.Commit()
            End Using
0 Likes
Accepted solutions (2)
2,688 Views
7 Replies
Replies (7)
Message 2 of 8

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Did you try setting MText.TextStyleId property ?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 8

SENL1362
Advisor
Advisor
Accepted solution

 

              string textStyleName = "MtextStyle";
                using (Transaction tr=db.TransactionManager.StartTransaction())
                {
                    var tsId = db.Textstyle;
                    var ts = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    if (ts.Has(textStyleName))
                        tsId = ts[textStyleName];

                    var mtext = new MText();
                    mtext.SetDatabaseDefaults();
                    mtext.TextStyleId = tsId;
                    ...


                    tr.Commit();
                }

 

 

0 Likes
Message 4 of 8

SENL1362
Advisor
Advisor
sorry Gile.
0 Likes
Message 5 of 8

Sgear
Advocate
Advocate

 

_gile, SENL1362 Thanks for the help I can know use Mtext style

 

Regards

sgear

0 Likes
Message 6 of 8

jan_tappenbeck
Collaborator
Collaborator

Hi!

 

i think this will be my code (what a english Smiley Happy ).

 

string textStyleName = "MtextStyle";
                using (Transaction tr=db.TransactionManager.StartTransaction())
                {
                    var tsId = db.Textstyle;
                    var ts = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                    if (ts.Has(textStyleName))
                        tsId = ts[textStyleName];

                    var mtext = new MText();
                    mtext.SetDatabaseDefaults();
                    mtext.TextStyleId = tsId;
                    ...


                    tr.Commit();
                }

my problem is to us in vb.net.

 

 

my try looks like

 

                        If TextStyleName.Length > 0 Then

                            Dim ts As TextStyleTable
                            Dim tsID As Autodesk.AutoCAD.DatabaseServices.TextStyleTableRecord
                            ts = CType(acTrans.GetObject(acCurDb.TextStyleTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite), TextStyleTable)
                            If ts.Has(TextStyleName) = True Then

                            End If
                        End If

.. but then my knowledge is end.

 

 

could someone help me?

 

regards Jan

0 Likes
Message 7 of 8

_gile
Consultant
Consultant

Hi,

 

If TextStyleName.Length > 0 Then
    ' initialize tsId with current text style ID
    Dim tsId As ObjectId = acCurDb.Textstyle
    Dim ts As TextStyleTable = CType(acTrans.GetObject(acCurDb.TextStyleTableId, OpenMode.ForRead), TextStyleTable)
	
    ' if the text style table contains a text style named as TextStyleName, set tsId with this text style ID
    If ts.Has(TextStyleName) Then
        tsId = ts(TextStyleName)
    End If
	
    Dim mtext As MText = new MText();
    mtext.SetDatabaseDefaults();
    mtext.TextStyleId = tsId;
'... End If

 

As it looks like you just start learning .NET, I'd suggest you to learn C# instead of VB, because, as you can see you'll need, at least, to be able to read C# examples, even if you learn VB...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 8

jan_tappenbeck
Collaborator
Collaborator

Dear Gilles,

 

since 1,5 years i work by vb.net to AutoCAD - but Primary in topobase map.

 

in last 2 month i need more or less direct AutoCAD entities!

 

you understand?

 

reagards Jan

0 Likes