NX二次开发源码分享: 如何判断当前零件的类型,很聪明...
NX二次开发源码分享: 如何判断当前零件的类型,很聪明...
大体思路如下!!
enum PartTypes {Empty=0, Model=1, Drawing=2, MasterDrawing=3, Assembly=4, Undefined=5, MasterModelDrawing=6, Invalid=7};
void DoIt(string[] args)
{
Part displayPart = theSession.Parts.Display;
if (displayPart != null)
{
GetPartType(displayPart);
return;
}
for (int ii = 0; ii < args.Length; ii++)
{
Echo("Processing: " + args);
try
{
PartLoadStatus loadStatus;
displayPart = (Part) theSession.Parts.OpenBaseDisplay(args, out loadStatus);
reportPartLoadStatus(loadStatus);
GetPartType(displayPart);
displayPart.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, null);
}
catch (NXException ex)
{
Echo(" " + ex.Message);
}
}
}
void GetPartType(Part thePart)
{
int nPartType = 0;
if (thePart.Bodies.ToArray().Length > 0) nPartType += 1;
if (thePart.DrawingSheets.ToArray().Length > 0) nPartType += 2;
if (thePart.ComponentAssembly.RootComponent != null) nPartType += 4;
Echo( String.Format("Part Type = {0}", (PartTypes)nPartType) );
}
页:
[1]