Пример - нарисовать контуры зон из ARCHICAD в AutoCAD полилиниями
//---------------------------------------------
// LABPP
// Нарисовать зоны полилиниями в AutoCAD
// Draws Zone elements in AutoCAD by PolyLines
//---------------------------------------------
int main()
{
int ires;
ires = autocad_request("attach");
if(ires != 0)
{
cout << "Can't attach AutoCAD\n";
return -1;
}
int iTable;
object("create","ts_table",iTable);
ts_table(iTable,"add_column",0,"double","x",0);
ts_table(iTable,"add_column",1,"double","y",0);
ts_table(iTable,"add_column",2,"double","b",0);
ac_request("load_elements_list_from_selection",0,"ZoneType");
ires = ac_request("get_loaded_elements_list_count",0);
int icount = ac_getnumvalue();
if(icount == 0)
{
cout << "You have not selected a Zone element.";
return -1;
}
int rowcount;
int iCoordTable;
object("create","ts_table",iCoordTable);
int i,j;
double xvalue,yvalue,si;
double pi = 3.1415926535;
int itablerowcount;
runtimecontrol("workline", "setmax", icount);
for(i=0;i<icount; i++)
{
runtimecontrol("workline", "setpos", i+1);
ac_request("set_current_element_from_list",0,i);
ac_request("get_gdlelem_property_value","ZoneName");
string szonename = ac_getstrvalue();
cout << "zonename=" << szonename << "\n";
ac_request("get_gdlelem_property_value","ROOM_AREA");
double ra = tsround(ac_getnumvalue(),2);
cout << "room_area=" << ra << "\n";
ac_request("get_gdlelem_property_value","pos.x");
double posx = ac_getnumvalue();
ac_request("get_gdlelem_property_value","pos.y");
double posy = ac_getnumvalue();
string stext = szonename;
autocad_request("specify_color_RGB",0,254,0);
autocad_request("draw_text",stext,posx-0.5,posy,0.2);
stext = "(" + sprintf("%g",ra) + ")";
autocad_request("draw_text",stext,posx-0.5,posy-0.3,0.2);
autocad_request("specify_color_RGB",254,254,0);
ts_table(iTable, "clear_rows");
ac_request("get_element_value","CoordTable",iCoordTable);
ts_table(iCoordTable, "get_rows_count", rowcount);
double lastxvalue, lastyvalue, lastsi;
double radius, firstangle;
double startangle, endangle;
double centerx,centery;
double xfornext, yfornext;
double tg_of_quatro_angle;
for(j=0;j<rowcount;j++)
{
ts_table(iCoordTable,"select_row", j);
ts_table(iCoordTable,"get_value_of","x",xvalue);
ts_table(iCoordTable,"get_value_of","y",yvalue);
ts_table(iCoordTable,"get_value_of","si",si);
//cout << "x="<<xvalue<<", y="<< yvalue << ", si="<< si << "\n";
if(j!=0)
{
if((si!=900)&&(si!=4000))
{
if(si==-1)
{
ts_table(iTable,"add_row",0,xvalue,1,yvalue,2,0);
autocad_request("draw_polyline",iTable);
ts_table(iTable, "clear_rows");
}
else {
ts_table(iTable,"add_row",0,xvalue,1,yvalue,2,0);}
}
else if(si==900)
{
ac_request("geometry_calc_2d","get_length_2point",lastxvalue, lastyvalue, xvalue, yvalue, radius);
ac_request("geometry_calc_2d","get_line_angle",lastxvalue, lastyvalue, xvalue, yvalue, firstangle);
centerx = xvalue;
centery = yvalue;
//cout << "radius=" << radius << " , firstangle="<< firstangle << "\n";
}
else if(si==4000)
{
//cout << "yvalue=" << yvalue << "\n";
if(yvalue > 0)
{
startangle = PI - (xvalue*pi/180.0 - firstangle);
endangle = PI - (-yvalue*pi/180.0 - firstangle);
}
else
{
endangle = PI - (xvalue*pi/180.0 - firstangle);
startangle = PI - (-yvalue*pi/180.0 - firstangle);
}
ac_request("geometry_calc_2d","rotate_point_and_move",centerx, centery, lastxvalue,lastyvalue, endangle, centerx, centery, 1, xfornext, yfornext);
tg_of_quatro_angle = tg((yvalue*pi/180.0)/4);
ts_table(iTable,"get_rows_count", itablerowcount);
ts_table(iTable,"select_row", itablerowcount-1);
ts_table(iTable,"set_value_of",2,tg_of_quatro_angle);
//cout << "tg=" << tg_of_quatro_angle << "\n";
xvalue = xfornext;
yvalue = yfornext;
}
}
else {
ts_table(iTable,"add_row",0,xvalue,1,yvalue,2,0); }
lastxvalue = xvalue;
lastyvalue = yvalue;
lastsi = si;
}
ts_table(iTable,"get_rows_count", itablerowcount);
if(itablerowcount>0) {
autocad_request("draw_polyline",iTable);}
}
object("delete",iCoordTable);
object("delete",iTable);
autocad_request("detach");
return 0;
}