To record only part of an object's state, specify kFalse for the autoUndo parameter, and then use the undoFiler::writeItem() function (or another write xxx () function) to save the relevant information in the undo file.
The setNumSides() function of AsdkPoly is a typical example of a modification function. Because assertWriteEnabled() specifies kFalse for autoUndo, the class assumes the responsibility of recording relevant parts of the object's state. First, the modification function must record the class descriptor object so that derived classes can check and let this class process its partial undo data if necessary.
undoFiler()->writeAddress(AsdkPoly::desc());
Then the modification function needs to indicate the type of action, followed by the data. In this example, the type of operation is kSetNumSides and the data is mNumSides.
Acad::ErrorStatus AsdkPoly::setNumSides(int numSides) { assertWriteEnabled(Adesk::kFalse, Adesk::kTrue); if (numSides<3) return Acad::eInvalidInput; if (mNumSides == numSides) return Acad::eOk; // There are situations under which AutoCAD doesn't // want to do undo recording, so it won't create an // undo filer. Check for the existence of the filer // before starting to write into it. // AcDbDwgFiler *pFiler = NULL; if ((pFiler = undoFiler()) != NULL) { undoFiler()->writeAddress(AsdkPoly::desc()); undoFiler()->writeItem((Adesk::Int16)kSetNumSides); undoFiler()->writeItem((Adesk::Int32)mNumSides); } mNumSides = numSides; return Acad::eOk; }
Once an object has performed an auto undo operation, which records its full state, additional requests for auto undo are ignored.