.NET

Reply
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 1 of 3 (94 Views)

Add text

94 Views, 2 Replies
01-09-2007 09:39 AM
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
Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 2 of 3 (94 Views)

Re: Add text

01-09-2007 02:54 PM 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.
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 3 of 3 (94 Views)

Re: Add text

01-09-2007 04:44 PM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.