Creating a Path element without adding it to the Drawing List

Note: This is a cross post.  The original is posted @ The CC3 Developer Blog

Wow, its been a while since I’ve written a post here.  The holidays are always a busy family blur.  Well, here is the latest installment …

The path/poly element is the most used element in CC3.  You really cannot get much done with it.  Try building anything in CC3 without it (Sure you can just use more primitive elements and use multipoly & group for joining and filling, but really you are just re-creating the path/poly element).  So if you want to get something done in an XP, odds are you are going to be working with paths/polys.

If you have been following this blog or the cc2-dev-list on groups.yahoo.com, you have seen code that creates path.  The code always creates a empty drawing list element then works on this record entity to “change” it into a path/poly.  I’ve always had a bit of a bad feeling about that.  It seems that it would be more “correct” to only add completed elements to the drawing list.  So, after quite a bit of frustration, I’ve successfully  worked out the code to create a path/poly element independent of the drawing list.

The code below creates a closed path (poly) with with four points:

Code Snippet – Build a PATH2 Element
  1. PATH2 *pathPtr = (PATH2*)malloc(sizeof(PATH2));
  2. pathPtr->CStuff.ERLen = sizeof(PATH2);    // entity record length
  3. pathPtr->CStuff.EType = ET_PATH2;         // entity type code
  4. pathPtr->CStuff.EFlags = 0;               // erase/select bits
  5. pathPtr->CStuff.EFlags2 = 0;              // extra flags
  6. pathPtr->CStuff.EColor = 1;               // entity color
  7. pathPtr->CStuff.EColor2 = 1;              // fill (2nd) color
  8. pathPtr->CStuff.EThick = 0;               // pen thickness 0..25.4 mm
  9. pathPtr->CStuff.WPlane = 0;               // workplane (0 = XY plane)
  10. pathPtr->CStuff.ELayer = 1;               // layer
  11. pathPtr->CStuff.ELStyle = 0;              // line style (0=solid)
  12. pathPtr->CStuff.GroupID = 0;              // group id (0 = not grouped)
  13. pathPtr->CStuff.EFStyle = 0;              // fill style (0=hollow)
  14. pathPtr->CStuff.LWidth = 0.0;             // line width
  15. pathPtr->CStuff.Tag = 0;                  // entity tag id
  16. pathPtr->Path.SmType = 0;                 //SmType
  17. pathPtr->Path.SRes = 8;                   //SRes
  18. pathPtr->Path.SParm = 0.0;                //SParm
  19. pathPtr->Path.EParm = 0.0;                //EParm
  20. pathPtr->Path.Count = 0;                  //Count
  21. pathPtr->Path.Flags = 0;                  //Flags
  22. pathPtr->Path.unused = 0;                 //unused
  23. GetCStuff((pENTREC)pathPtr);
  24. pathPtr = (PATH2*)realloc(pathPtr, sizeof(PATH2) + sizeof(GPOINT2) * 4);
  25. pathPtr->CStuff.ERLen = sizeof(PATH2) + sizeof(GPOINT2) * 4;
  26. pathPtr->Path.Nodes[0].x = 0.0;            //Nodes[0]
  27. pathPtr->Path.Nodes[0].y = 0.0;            //Nodes[0]
  28. pathPtr->Path.Nodes[1].x = 0.0;            //Nodes[1]
  29. pathPtr->Path.Nodes[1].y = 1000.0;         //Nodes[1]
  30. pathPtr->Path.Nodes[2].x = 1000.0;         //Nodes[2]
  31. pathPtr->Path.Nodes[2].y = 1000.0;         //Nodes[2]
  32. pathPtr->Path.Nodes[3].x = 1000.0;         //Nodes[3]
  33. pathPtr->Path.Nodes[3].y = 0.0;            //Nodes[3]
  34. pathPtr->Path.Count = 4;
  35. pathPtr->Path.EParm = 4.0;
  36. pathPtr->Path.Flags = NL_CLS;
  37. pENTREC pEntRec = DLApnd(NULL, (pENTREC)pathPtr);
  38. EDraw(pEntRec);
  39. free(pathPtr);

Comments are closed.