After editing table text with a custom VB.NET program, once exited from the program, if I want to roll back to the original text using the AutoCAD Undo button, the drawing must be regenerated to have the previous text displayed properly.
Following is the sequence of the operations
1. Create a table entitled "MyTable"
2. NETLOAD (myprogram)
3. Launch myprogram
4. Myprogram edits table text in order to change table title from "MyTable" to "Components Table"
5. Exit myprogram
6. Press the AutoCAD native Undo button in order to bring back the table title to it's original value (MyTable)
7. The table title still remains "Components Table"
8. To have the table title displayed properly "MyTable" I have to regenerate the drawing with the Regen native AutoCAD function
The other objects like single line text for example do not need to regenerate the drawing, simply pressing Undo and the text is rolled back properly.
Why the table text need to regenerate the drawing?
Thankyou to all
Luigi Ballotta
Solved! Go to Solution.
Solved by max.senft. Go to Solution.
Hi Augusto,
Step #3
Launch myprogram simply typing a custom command as it could be "mycmd";
Step #4
Using acLockCurrDoc As DocumentLock = acDoc.LockDocument()
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'As texts in tables are MText objects, MyObjectID is the ObjectID of the MText object embedded in a table object
Dim MultiLineText As MText = acTrans.GetObject(MyObjectID, OpenMode.ForWrite, False, True)
'Current MultiLineText.Contents is "MyTable" and I wanto to change it in "Components Table" so:
MultiLineText.Contents = "Components Table"
acTrans.Commit()
acDoc.Editor.Regen()
End Using
End Using
After this, the text of the table is changed to "Components Table" which is correct, but if I want to roll back the edit with the AutoCAD native Undo, I also have to type "_regen", to make sure that the text of the table is restored to his original content (MyTable). Sure the text is already restored to its original content pressing Undo, but the correct content is shown only after typing "_regen".
Exit myprogram simply closing the form of MyProgram.
thankyou,
regards
Hi there,
I'd rather use the Table Class given by the AutoCAD .NET API. Which means you can access each cell of the table by its index:
myTable.Cells(0, 0).Value = "Some String Value"
At least in my small test I just wrote, AutoCAD was able to correctly update the table when using the Undo-Button. PLUS: If I set the Content property of the MText object directly, the table won't auto-adjust if the new value is longer/shorter.
You don't have to struggle with all that "graphical representation" of your table if you use the Table class!
Regards
Max
Uhm, like any other object. Here's a sample snippet:
ObjectId selObjId; // This variable must be set via manual user selection, for example
var doc = Application.DocumentManager.MdiActiveDocument;
using (var tr = doc.TransactionManager.StartTransaction())
{
var selObj = tr.GetObject(selObjId, OpenMode.ForWrite);
if (selObj is Table)
{
var myTable = (Table)selObj;
myTable.Cells[0, 0].Value = "Table! " + DateTime.Now.ToString();
}
}
Hi,
I didn't say it has to be a manual selection. Going through the object dictionary programmatically is possible as well, of course.
Maybe this helps as a start?
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
using (var tr = doc.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord ms = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId curObj in block)
{
Entity curEnt = tr.GetObject(curObj, OpenMode.ForRead) as Entity;
if (curEnt == null)
{
continue;
}
if (curEnt is Table)
{
var tmpTable = (Table)curEnt;
// Do something with the table object
}
}
}
Max
Can't find what you're looking for? Ask the community or share your knowledge.