转载于恩·艾克斯·红的CSDN博客
感谢大佬的分享!
刚入门的时候写的了,仅供新手了解函数用法!(NX10以后NXopen就可以直接读取刀路信息了)
int count=0;
tag_p_t objects=NULL_TAG;
tag_t setup_tag;
UF_SETUP_ask_setup( &setup_tag);
UF_UI_ONT_ask_selected_nodes(&count,&objects);
if (count!=1)
{
uc1601("选择一个程序或程序组",1);
UF_terminate ();
return;
}
tag_t initial_wcs;
tag_t wcs_value;
logical is_group=TRUE;
tag_p_t oprea_list=NULL_TAG;
UF_CSYS_ask_wcs(&initial_wcs);
UF_NCGROUP_is_group(objects[0], &is_group );
if( is_group == TRUE )
{
if (count==0)
{
uc1601("程序组为空",1);
UF_terminate ();
return;
}
UF_NCGROUP_ask_member_list(objects[0],&count,&oprea_list);
UF_PARAM_ask_tag_value(oprea_list[0],UF_PARAM_MCS,&wcs_value);
}
else
{
UF_PARAM_ask_tag_value(objects[0],UF_PARAM_MCS,&wcs_value);
}
UF_CSYS_set_wcs(wcs_value);
UF_CAM_preferences_t number;
UF_CAM_ask_cam_preferences ( &number );
number.clsf_decimal_place=5;
UF_CAM_set_cam_preferences ( &number );
char path_char[133]="D:\\tmpcls.cls";
UF_SETUP_generate_clsf( setup_tag,objects[0],"CLSF_STANDARD", path_char, UF_SETUP_OUTPUT_UNITS_OUTPUT_DEFINED );
FILE *fp=fopen(path_char,"r");
char fchar[256];
if(fp==0)
{
uc1601("转换失败",1);
UF_terminate ();
return;
}
string fbuf;
tag_t line;
double point_one[ 3 ]={0,0,0},point_two[ 3 ]={0,0,0},point_three[ 3 ]={0,0,0},point_mid[ 3 ]={0,0,0};
UF_CURVE_line_t line_coords;
double xa=0,ya=0,za=0,xc=0,yc=0,zc=0,rr=0,radius;
double tolerance=0.01;
double magnitude;
double one_vec[3]={0,0,0},two_vec[3]={0,0,0};
int k1=-1,k2=-1,k3=-1,k4=-1,k5=-1,k6=-1,k7=-1,k8=-1,create_flag=1,is_parallel=0,arc_ero=0;
while (1)
{
if (fgets(fchar,256,fp)==NULL)
{
break;
}
fbuf=fchar;
if (fbuf.compare(0,4,"GOTO")==0)
{
k1=k2=k3=k4=k5=k6=k7=k8=-1;
k1=fbuf.find('/',0);
k2=fbuf.find(',',k1+1);
k3=fbuf.find(',',k2+1);
k4=fbuf.find(',',k3+1);
point_one[0]=atof(fbuf.substr(k1+1,k2-k1-1).c_str());
point_one[1]=atof(fbuf.substr(k2+1,k3-k2-1).c_str());
if (k4==string::npos)
{
point_one[2]=atof(fbuf.substr(k3+1,fbuf.length()).c_str());
}
else
{
point_one[2]=atof(fbuf.substr(k3+1,k4-k3-1).c_str());
}
UF_CSYS_map_point(UF_CSYS_ROOT_WCS_COORDS,point_one,UF_CSYS_ROOT_COORDS ,point_one);
break;
}
}
while (1)
{
if (fgets(fchar,256,fp)==NULL)
{
break;
}
fbuf=fchar;
if (fbuf.compare(0,4,"GOTO")==0)
{
k1=k2=k3=k4=k5=k6=k7=k8=-1;
k1=fbuf.find('/',0);
k2=fbuf.find(',',k1+1);
k3=fbuf.find(',',k2+1);
k4=fbuf.find(',',k3+1);
point_two[0]=atof(fbuf.substr(k1+1,k2-k1-1).c_str());
point_two[1]=atof(fbuf.substr(k2+1,k3-k2-1).c_str());
if (k4==string::npos)
{
point_two[2]=atof(fbuf.substr(k3+1,fbuf.length()).c_str());
}
else
{
point_two[2]=atof(fbuf.substr(k3+1,k4-k3-1).c_str());
}
UF_CSYS_map_point(UF_CSYS_ROOT_WCS_COORDS,point_two,UF_CSYS_ROOT_COORDS ,point_two);
for (int k=0;k<3;k++)
{
line_coords.start_point[k]=point_one[k];
line_coords.end_point[k]=point_two[k];
}
UF_CURVE_create_line(&line_coords,&line);
for (int k=0;k<3;k++)
{
point_one[k]=point_two[k];
}
}
if (fbuf.compare(0,6,"CIRCLE")==0)
{
k1=k2=k3=k4=k5=k6=k7=k8=-1;
k1=fbuf.find('/');
k2=fbuf.find(',',k1+1);
k3=fbuf.find(',',k2+1);
k4=fbuf.find(',',k3+1);
k5=fbuf.find(',',k4+1);
k6=fbuf.find(',',k5+1);
k7=fbuf.find(',',k6+1);
k8=fbuf.find(',',k7+1);
point_three[0]=atof(fbuf.substr(k1+1,k2-k1-1).c_str());
point_three[1]=atof(fbuf.substr(k2+1,k3-k2-1).c_str());
point_three[2]=atof(fbuf.substr(k3+1,k4-k3-1).c_str());
UF_CSYS_map_point(UF_CSYS_ROOT_WCS_COORDS,point_three,UF_CSYS_ROOT_COORDS ,point_three);
radius=atof(fbuf.substr(k7+1,k8-k7-1).c_str());
if (fgets(fchar,256,fp)==NULL)
{
break;
}
fbuf=fchar;
if (fbuf.compare(0,4,"GOTO")==0)
{
int k1,k2,k3,k4;
string x,y,z;
k1=fbuf.find('/',0);
k2=fbuf.find(',',k1+1);
k3=fbuf.find(',',k2+1);
k4=fbuf.find(',',k3+1);
point_two[0]=atof(fbuf.substr(k1+1,k2-k1-1).c_str());
point_two[1]=atof(fbuf.substr(k2+1,k3-k2-1).c_str());
if (k4==string::npos)
{
point_two[2]=atof(fbuf.substr(k3+1,fbuf.length()).c_str());
}
else
{
point_two[2]=atof(fbuf.substr(k3+1,k4-k3-1).c_str());
}
UF_CSYS_map_point(UF_CSYS_ROOT_WCS_COORDS,point_two,UF_CSYS_ROOT_COORDS ,point_two);
}
UF_VEC3_sub(point_one,point_three,one_vec);
UF_VEC3_sub(point_two,point_three,two_vec);
UF_VEC3_add(one_vec,two_vec,point_mid);
UF_VEC3_unitize(point_mid,tolerance,&magnitude,point_mid);
point_mid[0]=point_three[0]+radius*point_mid[0];
point_mid[1]=point_three[1]+radius*point_mid[1];
point_mid[2]=point_three[2]+radius*point_mid[2];
UF_VEC3_is_parallel(one_vec,two_vec,tolerance,&is_parallel);
if (is_parallel==1)
{
arc_ero=1;
for (int k=0;k<3;k++)
{
point_one[k]=point_two[k];
}
}
else
{
UF_CURVE_create_arc_thru_3pts(create_flag,point_one,point_mid ,point_two,&line);
for (int k=0;k<3;k++)
{
point_one[k]=point_two[k];
}
}
}
}
fclose(fp);
uc4561(path_char,0);
UF_CSYS_set_wcs(initial_wcs);
if (arc_ero==1)
{
uc1601("部分圆弧大于π,转换失败",1);
}
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/u012077233/article/details/102618474
NX/UG二次开发-刀轨转曲线
最新推荐文章于 2024-08-21 18:16:36 发布