|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
下面是我的装配代码,在执行到最后的时候老是出错,请大侠看看哪儿错了啊,我都是安装c里面的例子转换到c#里面的
//选择第一个面
string message = "please select one face";
NXOpen.UF.UFUi.Mask[] mask = new NXOpen.UF.UFUi.Mask[1];
mask[0].object_type = 71;
mask[0].object_subtype = 22;
mask[0].solid_type = 20;
NXOpen.UF.UFUi.SelectionOption opts = new NXOpen.UF.UFUi.SelectionOption();
int response;
Tag view;
double[] cursor = new double[3];
int unhighlight = 0;
opts.other_options = 0;
opts.reserved = new IntPtr();
opts.num_mask_triples = 1;
opts.mask_triples = mask;
opts.scope = 3;
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];
ftf.mated_object = from_part_ins;
ftf.name = string.Empty;
ftf.user_name = false;
ftf.constraints[0].from_status = UFAssem.LoadStatus.Ok;
ftf.constraints[0].to_status = UFAssem.LoadStatus.Ok;
ftf.constraints[0].mate_type = 3;
ftf.constraints[0].from_type = 0;
ftf.constraints[0].to_type = 0;
ftf.constraints[0].from = theUFSession.Assem.AskPrototypeOfOcc(first_plan);
ftf.constraints[0].from_part_occ = from_part_occ;
ftf.constraints[0].to = theUFSession.Assem.AskPrototypeOfOcc(second_plan);
ftf.constraints[0].to_part_occ = to_part_occ;
ftf.constraints[0].offset = 0;
ftf.constraints[0].name = "face to face";
ftf.constraints[0].user_name = true;
ftf.num_constraints = 1;
ftf.suppressed = false;
NXOpen.UF.UFAssem.McStatus status;
NXOpen.UF.UFAssem.McStructureState struct_status;
NXOpen.UF.UFAssem.Dof dof;
try
{
theUFSession.Assem.SolveMc(ref ftf, out status, out dof, transform);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
try里面报错[System.TypeLoadException] = {"无法封送类型 _MatingCondition 的字段 constraints:该类型无法作为结构字段进行封送处理。":""},跪谢了
|
|