This content has been marked as final. Show 2 replies
What I want to do:
I want to place normal grid points in my existing sketch "DOTS_LOC". For example, if x=y=10, then it will create 10x10=100 points, centered at origin. I use SolidWorks2016.
The code works fine, but only when the sketch is zoomed in. When zoomed out to some extent, the dot location anywhere below 0.5 is rounded down to zero. In the attached image, you should see 9x9 grids. But it actually contains 100 points, only that points with coordinates 0.5 being rounded down to zero. For example, CreatePoint(0.5, 0.5, 0.0) is actually placed at P(0,0,0). Similary, CreatePoint(-0.5, 0.5, 0.0) is placed at P(0,0,0) as well.
Simply put, any points as close to axis as 0.5mm is sucked onto the axis line. (Please see attached image)
But It Sometimes Work As Expected!
What's even more puzzling is the same exact code works as expected when the sketch is zoomed in close enough. Has anyone seen such behavior?
private void test()
double pitch = 1.0/1000.0; //distance between points
int x = 10;
int y = 10;
string fileName = @"C:\Users\xxx\Desktop\BGA2.SLDPRT";
int IErrors = 0;
int IWarnings = 0;
bool err0, err1;
ModelDoc2 swModel = (ModelDoc2)swApp.OpenDoc6(fileName, 1, (int)swDocumentTypes_e.swDocPART, "", ref IErrors, ref IWarnings);
bool boolstatus = swModel.Extension.SelectByID2("DOTS_LOC", "SKETCH", 0, 0, 0, false, 0, null, 0);
SketchPoint skPoint = null;
for (int i = 0; i < x; i++)
double xloc = i * pitch - (x - 1) / 2.0 * pitch;
for (int j=0; j < y; j++)
double yloc = j * pitch - (y - 1) / 2.0 * pitch;
skPoint = ((SketchPoint)(swModel.SketchManager.CreatePoint(xloc, yloc, 0.0)));