private string GetBodyBox(Body2 body2) { double[] BoxFeatureDblArray = new double[7]; BoxFeatureDblArray = (double[])body2.GetBodyBox(); double L = 0; double W = 0; double H = 0; L = (BoxFeatureDblArray[3] - BoxFeatureDblArray[0]) * 1000; W = (BoxFeatureDblArray[4] - BoxFeatureDblArray[1]) * 1000; H = (BoxFeatureDblArray[5] - BoxFeatureDblArray[2]) * 1000; string tempbox = string.Join("x", Math.Round(L, 2), Math.Round(W, 2), Math.Round(H, 2)); return(tempbox); }
/// <summary> /// center align /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_3(object sender, RoutedEventArgs e) { if (swApp == null) { return; } double[] bodyBox = new double[6]; PartDoc swPart = (PartDoc)swModel; object[] bodyArr = null; bodyArr = swPart.GetBodies2((int)swBodyType_e.swAllBodies, false); Body2 swBody = (Body2)bodyArr[0]; bodyBox = swBody.GetBodyBox(); double x1, y1, z1, x2, y2, z2; x1 = bodyBox[0]; y1 = bodyBox[1]; z1 = bodyBox[2]; x2 = bodyBox[3]; y2 = bodyBox[4]; z2 = bodyBox[5]; double xCenter, yCenter, xMove, yMove, zMove; xCenter = (x1 + x2) / 2; yCenter = (y1 + y2) / 2; xMove = xCenter * -1; yMove = yCenter * -1; if (z1 > z2) { zMove = z1; } else { zMove = -z2; } SelectionMgr swSelMgr = default(SelectionMgr); SelectData swSelData = default(SelectData); swSelMgr = (SelectionMgr)swModel.SelectionManager; swSelData = (SelectData)swSelMgr.CreateSelectData(); swSelData.Mark = 1; bool bRet = swBody.Select2(true, swSelData); FeatureManager ftMgr = default(FeatureManager); ftMgr = swModel.FeatureManager; Feature ftMoveCopy = ftMgr.InsertMoveCopyBody2(xMove, yMove, zMove, 0, 0, 0, 0, 0, 0, 0, false, 1); double xSize, ySize, zSize; xSize = Math.Round(Math.Abs(x1 * 1000 - x2 * 1000), 6); ySize = Math.Round(Math.Abs(y1 * 1000 - y2 * 1000), 6); zSize = Math.Round(Math.Abs(z1 * 1000 - z2 * 1000), 6); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(INFOPATH, true)) { string strInfo = PARTNAME + "," + xSize.ToString() + "," + ySize.ToString() + "," + zSize.ToString(); sw.WriteLine(strInfo); } }