Revit记录需要涂黑的格子---供自己使用

class Program
{
public class Map_divide
{
//XYZ的个数
public int XNum
{
get { return XNum; }
set { XNum = value; }
}
public int YNum
{
get { return YNum; }
set { YNum = value; }
}
public int ZNum
{
get { return ZNum; }
set { ZNum = value; }
}
public void Divide_para()
{
Console.WriteLine("start");
}
//X1-Z2是3方向的最大最小值
public double[] divide(double X1,double X2,double Y1,double Y2,double Z1,double Z2)

{
double[] StepXYZ = new double[3];

double Xrange = X2 - X1;
double Yrange = Y2 - Y1;
double Zrange = Z2 - Z1;
StepXYZ[0] = Xrange / XNum;
StepXYZ[1] = Yrange / YNum;
StepXYZ[2] = Zrange / ZNum;

return StepXYZ;

}

}
public bool IsBlank2(String ExcelPath, double h,double w,double l,double width,double xx, double yy)//这个excelpath是上文的生成的第二个表格
{
int success = 0;
//主函数体
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
xlApp.Visible = true;
Microsoft.Office.Interop.Excel.Workbooks wbs = xlApp.Workbooks;
Microsoft.Office.Interop.Excel._Workbook wb = wbs.Add(ExcelPath);
//wb.Close();
//wbs.Close();
// xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);//释放进程
Microsoft.Office.Interop.Excel._Worksheet wb1 = wb.Sheets[1];
Microsoft.Office.Interop.Excel._Worksheet wb2 = wb.Sheets[2];
//string Name = wb2.Name;
//int sRowcount = wb1.Rows.Count;
//Console.WriteLine(Name);
//激活工作表
wb1.Activate(); int k = 0;
//wb2.Activate();
for (int i = 0; i <(wb1.Rows.Count)-1; i++)//对表1中的每个ijk
{
int k11 = wb1.Cells[i, 1];
int k12 = wb1.Cells[i, 2];
int k13 = wb1.Cells[i, 3];
for (int ii = i+1; ii < wb1.Rows.Count; ii++)
{
int k21 = wb1.Cells[ii, 1];
int k22 = wb1.Cells[ii, 2];
int k23 = wb1.Cells[ii, 3];
int m = ii;//这个就是需要涂黑的z段的最大值
if (k11 == k21 && k12 == k22)
{
int kh = k23 - k13;
if (kh*h<=width)
{
for (int b = i; b <=m ; b++)
{
wb2.Activate();
wb2.Cells[k++, 1] = k11;
wb2.Cells[k, 2] = k12;
wb2.Cells[k, 3] = b;
}
}
}
//x
if (k12 == k22 && k13 == k23)
{
int kw = k21 - k11;
if (kw * w <= xx)//xxyyzz是整个长宽高的管道限值
{
for (int b = i; b <= m; b++)
{
wb2.Activate();
wb2.Cells[k++, 1] = b;
wb2.Cells[k, 2] = k22;
wb2.Cells[k, 3] = k23;
}
}
}
//y
if (k11 == k21 && k13 == k23)
{
int kl = k22 - k12;
if (kl * l <= yy)
{
for (int b = i; b <= m; b++)
{
wb2.Activate();
wb2.Cells[k++, 1] = k11;
wb2.Cells[k, 2] = b;
wb2.Cells[k, 3] = k13;
}
}
}

}
success = 1;


}

if (success==1)
{
return true;
}
else
{
return false;
}
}
public bool IsBlank(String ExcelPath,double width,double[] XYZVALUE)//width代表管的宽度(即宽和高中短的那一个)
{
//循环Excel表格
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
xlApp.Visible = true;
Microsoft.Office.Interop.Excel.Workbooks wbs = xlApp.Workbooks;
Microsoft.Office.Interop.Excel._Workbook wb = wbs.Add(ExcelPath);
//wb.Close();
//wbs.Close();
// xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);//释放进程
Microsoft.Office.Interop.Excel._Worksheet wb1 = wb.Sheets[1];
Microsoft.Office.Interop.Excel._Worksheet wb2 = wb.Sheets[2];
//string Name = wb2.Name;
//int sRowcount = wb1.Rows.Count;
//Console.WriteLine(Name);
//激活工作表
wb1.Activate();int k = 0;
//wb2.Activate();
int success = 0;
for (int i = 1; i < wb1.Rows.Count; i++)
{
for (int j = 1; j < wb1.Columns.Count; j++)
{
if (wb1.Cells[0,j]=="Xmin")
{
if (XYZVALUE[0]>=wb1.Cells[i,j]&&XYZVALUE[0]<=wb1.Cells[i,j+1])
{
wb2.Activate();
wb2.Cells[k++, 1] = XYZVALUE[0];
wb2.Cells[k, 2] = XYZVALUE[1];
wb2.Cells[k, 3] = XYZVALUE[2];
success = 1;
break;
}
if (wb1.Cells[0, j] == "Ymin")
{
if (XYZVALUE[1] >= wb1.Cells[i, j] && XYZVALUE[1] <= wb1.Cells[i, j + 1])
{
//wb2.Activate();
wb2.Cells[k++, 1] = XYZVALUE[0];
wb2.Cells[k, 2] = XYZVALUE[1];
wb2.Cells[k, 3] = XYZVALUE[2];
success = 1;
break;
}
}
if (wb1.Cells[0, j] == "Zmin")
{
if (XYZVALUE[2] >= wb1.Cells[i, j] && XYZVALUE[2] <= wb1.Cells[i, j + 1])
{
//wb2.Activate();
wb2.Cells[k++, 1] = XYZVALUE[0];
wb2.Cells[k, 2] = XYZVALUE[1];
wb2.Cells[k, 3] = XYZVALUE[2];
success = 1;
break;
}
}

}

}
wb.Save();
}

if (success==1)
{
return true;
}
else
{
return false;
}
}
//循环
double h = 0;double w = 0;double l = 0;
public void inputExcel(String filename,double width,double xx0,double yy0, double X1, double X2, double Y1, double Y2, double Z1, double Z2,double[] xx, double[] yy, double[] zz, double[] step )
{
double xstep = step[0];//step是函数divide里的步长
double ystep = step[1];
double zstep = step[2];
int xxNum = xx.Length;
int yyNum = yy.Length;
int zzNum = zz.Length;
//第一次循环,对于每一个ijk;
for (int i = 0; i < xxNum; i++)
{
for (int j = 0; j <yyNum ; j++)
{
for (int k = 0; k < zzNum; k++)
{
double[] kk = new double[3];//三个数分别代表ijk,x1y1z1代表revit模型XYZ三个方向的最小值(X2Y2Z2代表最大值)
kk[0] = X1 + i * xstep;
kk[1] = Y1 + j * ystep;
kk[2] = Z1 + k * zstep;
IsBlank(filename, width, kk);//如果这个结果为true,就把ijk值打入excel表中,判断ijk所代表的格子是否为黑;
IsBlank2(filename, h,w,l,width,xx0,yy0);//在主函数中循环;
}
}
}

}

上一篇:LP04 查找替换文件


下一篇:国内贩卖管理表