NXOpen通过选择点控件,查询面与体的信息
说明:使用选择控件,通过设置选中的模式为面上的点。
通过点的tag,获得面上的点的平面
/// <summary>
/// 从点找到对应面,返回的是平面
/// </summary>
/// <param name="pointTag"></param>
/// <returns></returns>
public static Tag AskFaceTagFormPoint(Tag pointTag)
{
Tag pointFaceTag = Tag.Null;
Tag[] parents;
int nParents;
theUfSession.So.AskParents(pointTag, UFConstants.UF_SO_ASK_ALL_PARENTS, out nParents, out parents); //查找关联对象
for (int t = parents.Length - 1; t >= 0; t--)
{
int type, subtype;
theUfSession.Obj.AskTypeAndSubtype(parents[t], out type, out subtype);
if (type == 70 && subtype == 2) //面的tag类型分类
{
pointFaceTag = parents[t];
break;
}
}
return pointFaceTag;
}
从面Tag获取体的Tag
private static Tag GetBodyLayerAndAtt(Tag faceTag)
{
Tag bodyTag; //获取到体的Tag
theUfSession.Modl.AskFaceBody(faceTag, out bodyTag);
return bodyTag;
}
从体获取实体的属性与图层
从体获取属性与图层首先需要将Tag对象转换为NXopen的Body对象,需要使用万能转换函数进行转换。
private static void GetBodyLayerAndAtt(Tag bodyTag)
{
Body selectBody = (Body)NXOpen.Utilities.NXObjectManager.Get(bodyTag); //Tag对象转换为Body
string layerValue = selectBody.Layer.ToString(); //体图层
var bodyAtt = selectBody.GetUserAttributes();
List<string> bodyAttList = new List<string>(); //体的所有属性名称集合
foreach (var att in bodyAtt)
{
string title = att.Title;//属性的名称
string strValue = att.StringValue; //属性的值
bodyAttList.Add(title);
}
}
获取面的法向量
public static Vector3d AskFaceVector3d(Tag faceTag, Point3d selectPoint)
{
UFSession theUfSession = UFSession.GetUFSession();
int type;
double[] points = { selectPoint.X, selectPoint.Y, selectPoint.Z };
double[] dirs = { 0, 0, 0 }; //面的法向量
double[] box = { 0, 0, 0, 0, 0, 0 };
double radius;
double radData;
int norm;
theUfSession.Modl.AskFaceData(faceTag, out type, points, dirs, box, out radius, out radData, out norm);
Vector3d faceVec = new Vector3d(dirs[0], dirs[1], dirs[2]);
return faceVec;
}