目录

C-NX二次开发获取模型中所有的草图并获取草图中的对象

目录

C# NX二次开发:获取模型中所有的草图并获取草图中的对象

大家好,今天接着讲NX二次开发获取草图相关。

获取草图的方法是从workPart中获取,如下面的例子所示:

List tags = new List();

SketchCollection sketchCollection = workPart.Sketches;

Sketch[] sketches = sketchCollection.ToArray();

for (int i = 0; i < sketches.Length; i++)

{

string name = sketches[i].Name;

if (i == sketches.Length - 1)

{

group = sketches[i].Tag;

Feature feature = sketches[i].Feature;

NXObject[] nXObjects = feature.GetEntities();

//TaggedObject[] GetSelectedObjects1=

for (int j = 0; j < nXObjects.Length; j++)

{

if(nXObjects[j].ToString().Contains(“Arc”)|| nXObjects[j].ToString().Contains(“Line”))

{

tags.Add(nXObjects[j].Tag);

}

}

//theUI.NXMessageBox.Show(“提示”, NXMessageBox.DialogType.Information, name);

}

}

在上面的例子中获取了所有的草图,并且在获取到最后一个草图的时候,取出了草图中的Arc对象和Line对象的Tag值。

当然我们的类型都是从NXObject这个基类中进行获取的,下面是NXObject包含的内容:

https://i-blog.csdnimg.cn/direct/1dca38c790ea42308df704aaf20f883c.png

public enum AttributeType

{

Invalid = 0,

Null = 1,

Boolean = 2,

Integer = 3,

Real = 4,

String = 5,

Time = 6,

Reference = 7,

Any = 100

}

public enum DateAndTimeFormat

{

Numeric = 0,

Textual = 1

}

public struct ComputationalTime

{

public int Day;

public int Minute;

public ComputationalTime(int Day, int Minute);

public override string ToString();

}

public struct AttributeInformation

{

public AttributeType Type;

public Unit Unit;

public int ArrayElementIndex;

public bool NotSaved;

public bool PdmBased;

public bool Array;

public bool Unset;

public bool Required;

public bool OwnedBySystem;

public bool Locked;

public bool IsOverride;

public bool Inherited;

public string ReferenceValue;

public ComputationalTime CompTimeValue;

public string TimeValue;

public string StringValue;

public double RealValue;

public int IntegerValue;

public bool BooleanValue;

public string TitleAlias;

public string Title;

public string Category;

public Expression Expression;

public override string ToString();

}

今天要介绍的就是这么多,我们下篇文章再见。

散会