TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

When posting a problem be sure to include which version you are using.  Give as much information as possible.  If the problem is with a specific file be sure to attache it to your post.

Adding Items the Undo Buffer
Read 2678 times
* May 24, 2017, 07:17:37 AM
I am using a VBA program in Excel to collect coordinates from TC 2016 and then I add a Point Number (and optional Easting, Northing, and Elevation) text to the TC Drawing.  Here is a section of the code I use for .AddText:

        TextPosition = Range("cllTextPosition").Value
        If chkConvertToFeet.Value = False Then
            Set tcGrText = tcGrs.AddText(TCText, XCoordinate, YCoordinate, 0, LinesofText * txtTextHeight, , , , TextPosition)
            Set tcGrText = tcGrs.AddText(TCText, XCoordinate, YCoordinate, 0, LinesofText * txtTextHeight * 12, , , , TextPosition)
        End If

The problem is that the text added to the TC Drawing is not added to the TC Undo Buffer.  Does anyone know if this can be done?

"Nothing ever comes to one, that is worth having, except as a result of hard work."

--Booker T. Washington,
American educator and political leader

* May 24, 2017, 09:14:47 AM
First  -  I've no idea if this works as I've not tested it.

Looking at the tcsdk.chm doc, my interpretation is that one sets up a user defined undo record (separate from the main TC one), then add graphics to this record, when finished one issues a .close command which then tells TC to transfers the user record into the main TC stack.

There are references to it in the tcsdk.chm help file though its a shame that particular chm doesn't have a search facility.

if you have visual studio express there is an example of its use in the multi-add vb.net  file on this page http://forums.turbocad.com/index.php/topic,9564.0.html.

or for a vbs (which can be viewed in notepad),  see the attached, which was on the forum in this thread (I think) http://forums.turbocad.com/index.php/topic,1015.0.html but was deleted in a  forum clean-up,
« Last Edit: May 24, 2017, 09:20:23 AM by Andy H »


* June 13, 2017, 03:08:10 AM
this is what I found in the tcsdk Help

For each Graphic object that is created, destroyed or modified as part of an undoable action, you must add a reference to the graphic to the UndoRecord Object that you have set up. The UndoRecord Object exposes a method for each of the three actions: create, destroy and modify.
Using the UndoRecord Object
First you must create an UndoRecord Object:
Dim urec As UndoRecord
Set urec = ActiveDrawing.AddUndoRecord("Add Part")
To add a graphic to the UndoRecord Object:
Dim grNew As Graphic
Set grNew = ActiveDrawing.AddSquare
urec.AddGraphic grNew

in an old TC version with vba this code works:

Sub undo()

Dim urec As UndoRecord
Set urec = ActiveDrawing.AddUndoRecord("Add Part")

Dim grNew As Graphic
Set grNew = ActiveDrawing.Graphics.AddSquare(10, 10, 10)
urec.AddGraphic grNew

End Sub
each undorecord has to have a name.
After running the macro there is available "Undo Add Part"

best regards


* June 13, 2017, 03:16:44 AM
I just found at
undo Example
Option Explicit

Sub main()
Dim Dr As Drawing
Dim Gr As Graphic
Dim urec As UndoRecord
Set Dr = Application.ActiveDrawing
Set urec = Dr.AddUndoRecord("Remove circles drawn by macro")
Set Gr = Dr.Graphics.AddCircleCenterAndPoint(0, 0, 0, 2, 0, 0)
urec.AddGraphic Gr
Set Gr = Dr.Graphics.AddCircleCenterAndPoint(0, 0, 0, 3, 0, 0)
urec.AddGraphic Gr
MsgBox "Next step will remove both circles."
Dr.Undo (1)
End Sub