1.情景:CAM环境下,需要得到当前零件在加工坐标系下的X、 Y、 Z方向上的极值。
2.百度上找到了三个函数:
AskBoundingBox、AskBoundingBoxAligned、AskBoundingBoxExact
后三个可以指定参照坐标系,我自己测试了一下,发现出来的结果总是在绝对坐标系下的结果,最后还是得自己处理下才得到,记录一下。
Session theSession = Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
bool expand = true;
double[] min_corner = new double[3]; //角落点
double[,] directions = new double[3, 3];//方向
double[] distances = new double[3];//xyz最大距离
double[] min_corner = new double[3]; //角落点
double[,] directions = new double[3, 3];//方向
double[] distances = new double[3];//xyz最大距离
double[] outlinePoint = new double[6];
TaggedObject obj = partSel.GetSelectedObjects()[0];//partSel是一个选择控件,得到的obj是需要计算包围盒的目标零件
//方法一:
NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBox(tag.Tag, outlinePoint);
NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBox(tag.Tag, outlinePoint);
// 获取的outlinePoint再使用向量的点乘即可转换成在目标坐标系下的坐标
//下面的sys是参照的坐标系,如何获取?见后面的函数
//方法二:
//NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBoxAligned(tag.Tag, sys.Tag, expand, min_corner, directions, distances);
//方法三:
//NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBoxExact(tag.Tag, sys.Tag, min_corner, directions, distances);
//NXOpen.UF.UFSession.GetUFSession().Modl.AskBoundingBoxExact(tag.Tag, sys.Tag, min_corner, directions, distances);
//获取当前的全部几何体(加工坐标系)
void GetAllMcs(ref List<NXOpen.CAM.OrientGeometry> mcs)
{
Session theSession = Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.CAM.CAMSession camSession = theSession.CAMSession;
NXOpen.CAM.CAMSetup camSetup = workPart.CAMSetup;
NXOpen.CAM.NCGroup ncGroup = camSetup.GetRoot(NXOpen.CAM.CAMSetup.View.Geometry);
List<NXOpen.CAM.OrientGeometry> mcs = new List<NXOpen.CAM.OrientGeometry> ();
GetMcs(ncGroup, ref mcs);
{
Session theSession = Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.CAM.CAMSession camSession = theSession.CAMSession;
NXOpen.CAM.CAMSetup camSetup = workPart.CAMSetup;
NXOpen.CAM.NCGroup ncGroup = camSetup.GetRoot(NXOpen.CAM.CAMSetup.View.Geometry);
List<NXOpen.CAM.OrientGeometry> mcs = new List<NXOpen.CAM.OrientGeometry> ();
GetMcs(ncGroup, ref mcs);
}
void GetMcs(NXOpen.CAM.CAMObject camObj,ref List<NXOpen.CAM.OrientGeometry> mcs)
{
if (camObj is NXOpen.CAM.OrientGeometry)
{
NXOpen.CAM.OrientGeometry system = camObj as NXOpen.CAM.OrientGeometry;
mcs.Add(system);
}
if (camObj is NXOpen.CAM.NCGroup)
{
NXOpen.CAM.NCGroup ncGroup = camObj as NXOpen.CAM.NCGroup;
NXOpen.CAM.CAMObject[] camObjArr = ncGroup.GetMembers();
foreach (NXOpen.CAM.CAMObject icamObj in camObjArr)
{
GetMcs(icamObj,ref mcs);
}
}
}
{
if (camObj is NXOpen.CAM.OrientGeometry)
{
NXOpen.CAM.OrientGeometry system = camObj as NXOpen.CAM.OrientGeometry;
mcs.Add(system);
}
if (camObj is NXOpen.CAM.NCGroup)
{
NXOpen.CAM.NCGroup ncGroup = camObj as NXOpen.CAM.NCGroup;
NXOpen.CAM.CAMObject[] camObjArr = ncGroup.GetMembers();
foreach (NXOpen.CAM.CAMObject icamObj in camObjArr)
{
GetMcs(icamObj,ref mcs);
}
}
}
// 另外,从几何体中获取加工坐标系
NXOpen.CAM.MillOrientGeomBuilder millOrientGeomBuilder1 = workPart.CAMSetup.CAMGroupCollection.CreateMillOrientGeomBuilder(mcs[0]);
CoordinateSystem curSys = millOrientGeomBuilder1.Mcs;
millOrientGeomBuilder1.Destroy();
CoordinateSystem curSys = millOrientGeomBuilder1.Mcs;
millOrientGeomBuilder1.Destroy();
浙公网安备 33010602011771号