.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 3
mohnston
299 Views, 2 Replies

Add text

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.
CAD Programming Solutions
2 REPLIES 2
Message 2 of 3
MarkPendergraft
in reply to: mohnston

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.
Message 3 of 3
mohnston
in reply to: mohnston

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.
CAD Programming Solutions

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