Thursday, September 2, 2010

How to walk the "Drawing List"

In trying to decide what element of CC3 XP programming I was going to blog about next, I started to re-read all of the old posts on the cc2-dev-l email list @ groups.yahoo.com. 

Wow, I had forgotten how much valuable information was out there. If you have the time (And it will take a bit of time) just start at the beginning and read through the threads.  I promise that you will learn something – I did!

I found a request by Linda Kekumu.  It seemed that she had a large number of maps that had lots of Notes attached to them and they were wrong.  She needed a quick way to clear out all the notes on a map, instead of manually removing them one at a time.  Peter responded with this dash of code.

The reason I selected it for this post is that it is probably the smallest piece of code that displays how to use DLScan.  Now DLScan does exactly as the name says, it scans the “Drawing List” (i.e. the drawing database) and calls a function for every “identified” element.  I say “identified” because there are times when you only want to look at a subset of the entire Drawing List.

In this new XP command, we scan the Drawing List with the DLS_Std flag, telling DLScan that we want to scan the Drawing List for “all standard all non-erased elements”.

Then in our called function (ClearNotesScan) we check the EType of each identified  element (pEntRec) .  If the EType equals ET_Note, we know it is a Note and we call DLErase to remove the element from the Drawing List.

So, with this, you can now scan through a map and look at every identified element!

Code Snippet – MyClearNotes Command
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Program: CC3DeveloperBlog.dll
  4. // File Name: MyClearNotes.cpp
  5. // Written by Peter Olsson (Copied here by L. Lee Saunders)
  6. // (C)2010 Beer & Pretzel Games
  7. // All rights reserved
  8. //
  9. /////////////////////////////////////////////////////////////////////////////

  10. #include <windows.h>
  11. #include <math.h>

  12. extern"C"
  13. {
  14.     #include <xp.h>
  15.     #include <math.h>
  16. }
  17. extern XP MyXP;
  18. /////////////////////////////////////////////////////////////////////////////


  19. /////////////////////////////////////////////////////////////////////////////
  20. DWORD XPCALL ClearNotesScan(hDLIST hDList, pENTREC pEntRec, PARM p1, PARM p2)
  21. {
  22.     //If the Entity Record is of type "Note" then erase the Entity from DL
  23.     if(pEntRec->CStuff.EType==ET_NOTE) { DLErase(pEntRec); }
  24.     return 0;
  25. }
  26. /////////////////////////////////////////////////////////////////////////////


  27. /////////////////////////////////////////////////////////////////////////////
  28. void XPCALL MyClearNotes(void)
  29. {
  30.     //Description copied from FCW32.TXT
  31.     //---------------------------------------------------------------
  32.     // ClearSel - Clear All Selection bits
  33.     //---------------------------------------------------------------
  34.     ClearSel();

  35.     //This sets an undo point so that every action after this to the end of
  36.     //the command will be reversed if the user selects UNDO.
  37.     MarkUndo();

  38.     //Drawing list scan. We are interested in only the first three parameters
  39.     // Param #1: Drawing list - If null, it is the main list
  40.     // Param #2: Our Callback function for every identified element in the DL
  41.     // Param #3: DSFlags. How we identify what DL elements we want
  42.     DLScan(NULL, ClearNotesScan, DLS_Std, 0, 0);

  43.     //End the command
  44.     CmdEnd();
  45. }
  46. /////////////////////////////////////////////////////////////////////////////

No comments:

Post a Comment