UG NX二次开发(C#)-装配-添加组件
Posted GimiGimmy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UG NX二次开发(C#)-装配-添加组件相关的知识,希望对你有一定的参考价值。
在UG NX的使用过程中,装配是很重要的一环,本文是为了实现组件的批量装配,采用UG NX二次开发,采用的主要函数为AddComponent。
AddComponent()的帮助说明如下:
其是属于NXOpen.Assemblies空间的ComponentAssembly类,
采用:
using NXOpen.Assemblies;
其实现代码如下:
/// <summary>
/// 添加组件
/// </summary>
/// <param name="sourcePart">需要添加的组件全路径</param>
/// <param name="destinationPart">组件名称</param>
/// <param name="referenceSetName"></param>
/// <param name="component"></param>
public static void AddComponent(string sourcePart,string destinationPart,string referenceSetName,out Component component)
{
Point3d basePoint = new Point3d(0,0,0);
double[] mtx = new double[9] { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 };
UFMtx3 uFMtx3 = theUFSession.Mtx3;
double[] vecProduct = new double[3];
double[] pipeLineVector = new double[3] { 0, 0, 1 };
uFMtx3.VecMultiply(pipeLineVector, mtx, vecProduct);
double[] pipeLineMtx = new double[9];
uFMtx3.InitializeZ(vecProduct, pipeLineMtx);
NXOpen.Matrix3x3 orientation = new NXOpen.Matrix3x3();
orientation.Xx = pipeLineMtx[0];
orientation.Xy = pipeLineMtx[1];
orientation.Xz = pipeLineMtx[2];
orientation.Yx = pipeLineMtx[3];
orientation.Yy = pipeLineMtx[4];
orientation.Yz = pipeLineMtx[5];
orientation.Zx = pipeLineMtx[6];
orientation.Zy = pipeLineMtx[7];
orientation.Zz = pipeLineMtx[8];
int layer = workPart.Layers.WorkLayer;
PartLoadStatus partLoadStatus;
component = workPart.ComponentAssembly.AddComponent(sourcePart, referenceSetName, destinationPart, basePoint, orientation, layer, out partLoadStatus, true);
partLoadStatus.Dispose();
}
在代码中,需要注意的是这个组件是添加在workPart下面的,workPart是显示部件,即是:
PartLoadStatus partLoadStatus;
theSession.Parts.SetDisplay((BasePart)workPart,true,true,out partLoadStatus);
效果如下图所示:
以上是关于UG NX二次开发(C#)-装配-添加组件的主要内容,如果未能解决你的问题,请参考以下文章