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:
- PATH2 *pathPtr = (PATH2*)malloc(sizeof(PATH2));
- pathPtr->CStuff.ERLen = sizeof(PATH2); // entity record length
- pathPtr->CStuff.EType = ET_PATH2; // entity type code
- pathPtr->CStuff.EFlags = 0; // erase/select bits
- pathPtr->CStuff.EFlags2 = 0; // extra flags
- pathPtr->CStuff.EColor = 1; // entity color
- pathPtr->CStuff.EColor2 = 1; // fill (2nd) color
- pathPtr->CStuff.EThick = 0; // pen thickness 0..25.4 mm
- pathPtr->CStuff.WPlane = 0; // workplane (0 = XY plane)
- pathPtr->CStuff.ELayer = 1; // layer
- pathPtr->CStuff.ELStyle = 0; // line style (0=solid)
- pathPtr->CStuff.GroupID = 0; // group id (0 = not grouped)
- pathPtr->CStuff.EFStyle = 0; // fill style (0=hollow)
- pathPtr->CStuff.LWidth = 0.0; // line width
- pathPtr->CStuff.Tag = 0; // entity tag id
- pathPtr->Path.SmType = 0; //SmType
- pathPtr->Path.SRes = 8; //SRes
- pathPtr->Path.SParm = 0.0; //SParm
- pathPtr->Path.EParm = 0.0; //EParm
- pathPtr->Path.Count = 0; //Count
- pathPtr->Path.Flags = 0; //Flags
- pathPtr->Path.unused = 0; //unused
- GetCStuff((pENTREC)pathPtr);
- pathPtr = (PATH2*)realloc(pathPtr, sizeof(PATH2) + sizeof(GPOINT2) * 4);
- pathPtr->CStuff.ERLen = sizeof(PATH2) + sizeof(GPOINT2) * 4;
- pathPtr->Path.Nodes[0].x = 0.0; //Nodes[0]
- pathPtr->Path.Nodes[0].y = 0.0; //Nodes[0]
- pathPtr->Path.Nodes[1].x = 0.0; //Nodes[1]
- pathPtr->Path.Nodes[1].y = 1000.0; //Nodes[1]
- pathPtr->Path.Nodes[2].x = 1000.0; //Nodes[2]
- pathPtr->Path.Nodes[2].y = 1000.0; //Nodes[2]
- pathPtr->Path.Nodes[3].x = 1000.0; //Nodes[3]
- pathPtr->Path.Nodes[3].y = 0.0; //Nodes[3]
- pathPtr->Path.Count = 4;
- pathPtr->Path.EParm = 4.0;
- pathPtr->Path.Flags = NL_CLS;
- pENTREC pEntRec = DLApnd(NULL, (pENTREC)pathPtr);
- EDraw(pEntRec);
- free(pathPtr);