Add text

Add text

Anonymous
Not applicable
480 Views
2 Replies
Message 1 of 3

Add text

Anonymous
Not applicable
I'm trying to add a piece of text to a drawing and then save and close the drawing.
This code runs without error but the text is not on the drawing when I open it to check.
There has to be something simple wrong.
First one to help gets a gift. (see below for details)

-----------------------------
private void StampDrawing(string fullDwgPath, string stampString)
{
Document ThisDrawing = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(fullDwgPath);
ThisDrawing.LockDocument();
Database thisDB = ThisDrawing.Database;
Autodesk.AutoCAD.ApplicationServices.TransactionManager tm = ThisDrawing.TransactionManager;
using (Transaction trans = tm.StartTransaction())
{
BlockTable bt = (BlockTable)thisDB.BlockTableId.GetObject(OpenMode.ForWrite);
BlockTableRecord modelsp = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

DBText stampText = new DBText();
stampText.TextString = stampString;
stampText.Height = 12;
stampText.HorizontalMode = TextHorizontalMode.TextRight;
stampText.Rotation = 0;
modelsp.AppendEntity(stampText);
trans.TransactionManager.AddNewlyCreatedDBObject(stampText, true);
trans.Commit();
}
tm.Dispose();
ThisDrawing.CloseAndSave(fullDwgPath);
thisDB.Dispose();
}
-----------------------------

The gift of helping is the best gift of all.
0 Likes
481 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
public sub testsomestuff

Dim stampstring As String = "I stamped this drawing"

Dim thisDB As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = thisDB.TransactionManager.StartTransaction

Dim bt As BlockTable = trans.GetObject(thisDB.BlockTableId, OpenMode.ForWrite, False, True)
Dim modelsp As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

Dim stampText As DBText = New DBText()
stampText.TextString = stampString
stampText.Height = 12
stampText.HorizontalMode = TextHorizontalMode.TextRight
stampText.Rotation = 0


modelsp.AppendEntity(stampText)

trans.AddNewlyCreatedDBObject(stampText, True)

trans.Commit()

thisDB.Dispose()

End Using

end sub


that code works for me......
obviously it runs from inside autocad....

I would recommend stepping through the code line by line to make sure every line is executing.
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks for your reply.
I am aware that the code you posted works but doesn't do what I need.

I need to open a drawing, add the text, save the drawing and close the drawing. All programatically.
0 Likes