.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error when i create new layer for text

3 REPLIES 3
Reply
Message 1 of 4
hoathuongphuoc
356 Views, 3 Replies

Error when i create new layer for text

Hi all,

I have problem. This is, when i create new layer for text, i have met one error. I hope everybody can help me. Thanks. And this is my code;

<CommandMethod("dd")> Public Sub DrawText()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        ucs = ed.CurrentUserCoordinateSystem
        doc.LockDocument()
        ''Messenger select stone
        Dim pOption As New PromptPointOptions("")
        pOption.Message = vbLf & "Select Point:"
        Dim pResult As PromptPointResult = ed.GetPoint(pOption)
        doc.LockDocument()
        '' Start a transaction
        Using acTrants As Transaction = db.TransactionManager.StartTransaction()
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrants.GetObject(db.BlockTableId, _
            OpenMode.ForRead)
            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrants.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

            ''Create a single-line text object
           Dim acText As DBText = New DBText()
            acText.SetDatabaseDefaults()
            acText.Position = New Point3d(0, 0, 0)
            acText.Height = 100
            acText.TextString = "Cadviet"
            acText.Layer = "LTEXT"
            acText.WidthFactor = 0.8
            acBlkTblRec.AppendEntity(acText)
            '' condition add floor
            acBlkTblRec.AppendEntity(acText)
            acTrants.AddNewlyCreatedDBObject(acText, True)
            acTrants.Commit()
        End Using

 Error appear at this line->acText.Layer = "LTEXT"

3 REPLIES 3
Message 2 of 4
SENL1362
in reply to: hoathuongphuoc

Why need everybody's help, isn't just one enough? 🙂
I don't think you're code is creating the layer, it's creating a Text object which you like to put on the "LTEXT" layer.
That requires the Layer to already exists.
Two solutions:
1. Use a drawing(template) with that layer already configured;
2. or use code to create the layer before referencing it.
LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForWrite);
if (!lt.Has("LTEXT"))
{
LayerTableRecord ltr = new LayerTableRecord();
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 30); ltr.Name = "LTEXT";
ObjectId layerId = lt.Add(ltr); tr.AddNewlyCreatedDBObject(ltr, true);
}


Message 3 of 4

Along with SENL1362 suggestions, remove the extra line from your code.

 

 acBlkTblRec.AppendEntity(acText)
            '' condition add floor
            acBlkTblRec.AppendEntity(acText)

 

Message 4 of 4

Thanks very much. Just enough for me.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost