NXOpen.UF.UFUi.SelectionOption opts = new NXOpen.UF.UFUi.SelectionOption();
int response;
Tag view;
double[] cursor = new double[3];
int unhighlight = 0;
int type;
double[] point = new double[3];
double[] dir = new double[3];
double[] box = new double[6];
double radius;
double rad_data;
int norm_dir;
Tag first_plan;
do
{
theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM);//这句必须添加,否则下面出错
theUFSession.Ui.SelectSingle(message, ref opts, out response, out first_plan, cursor, out view);
theUFSession.Modl.AskFaceData(first_plan, out type, point, dir, box, out radius, out rad_data, out norm_dir);
theUFSession.Ui.LockUgAccess(0);//这句必须添加,否则下面出错
if (type != 22)
{
MessageBox.Show("请选择一个平面");
theUFSession.Disp.SetHighlight(first_plan, 0);//取消选择
}
theUFSession.Ui.UnlockUgAccess(1);
}
while(!(type == 22 && response ==5));
if (response != 5)
{
MessageBox.Show("没有选中面");
return;
}
Tag from_part_occ;
theUFSession.Assem.AskParentComponent(first_plan, out from_part_occ);
bool is_occ = theUFSession.Assem.IsOccurrence(from_part_occ);
Tag from_part_ins = theUFSession.Assem.AskInstOfPartOcc(from_part_occ);
//提示所显示的实例的名称
string part_name;//这个是全路径part名称
string refset_name;
string instance_name;//这个是不带路径的实例名称
double[] origin = new double[3];
double[] csys_matrix = new double[9];
double[,] transform = new double[4,4];
theUFSession.Assem.AskComponentData(from_part_occ, out part_name, out refset_name, out instance_name, origin, csys_matrix, transform);
//MessageBox.Show(instance_name + " " + part_name);
//////////////////////////////
//选择第二个面
message = "please select another face";
Tag second_plan;
do
{
theUFSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM);//这句必须添加,否则下面出错
theUFSession.Ui.SelectSingle(message, ref opts, out response, out second_plan, cursor, out view);
theUFSession.Modl.AskFaceData(second_plan, out type, point, dir, box, out radius, out rad_data, out norm_dir);
theUFSession.Ui.LockUgAccess(0);
if (type != 22)
{
MessageBox.Show("请选择一个平面");
theUFSession.Disp.SetHighlight(second_plan, 0);//取消选择
}
theUFSession.Ui.UnlockUgAccess(1);
}
while (!(type == 22 && response == 5));
if (response != 5)
{
MessageBox.Show("没有选中面");
return;
}
Tag to_part_occ;
theUFSession.Assem.AskParentComponent(second_plan, out to_part_occ);
Tag to_part_ins = theUFSession.Assem.AskInstOfPartOcc(to_part_occ);
theUFSession.Assem.AskComponentData(to_part_occ, out part_name, out refset_name, out instance_name, origin, csys_matrix, transform);
//MessageBox.Show(instance_name + " " + part_name);
///////////////////////////
//构造配合关系
NXOpen.UF.UFAssem.MatingCondition ftf = new NXOpen.UF.UFAssem.MatingCondition();
ftf.constraints = new NXOpen.UF.UFAssem.Constraint[1];