外部开发:部件属性 外部exe启动UG NX

NX支持外部读取修改部件属性,修改后注意需要保存,UF_PART_save();

外部exe启动UG NX            

                1 用.net2003建立一个控制台应用程序   2 将目录ugiimanaged下除ManagedLoader.dll外的dll文件加入到你的工程里面的References   3 将下面的代码复制到你的Main函数里面                theSession = Session.GetSession();                                theSession.Parts.NewDisplay("d:\1.prt",NXOpen.Part.Units.Millimeters);                NXOpen.Features.Feature nullFeatures_Feature = null;                NXOpen.Part pp=theSession.Parts.Work;                myblock = pp.Features.CreateBlockFeatureBuilder(nullFeatures_Feature) ;                Point3d ps = new Point3d(0.0, 0.0, 0.0);                myblock.SetOriginAndLengths(ps, "100", "100", "100");                myblock.CommitFeature();                NXOpen.PartSaveStatus status;                theSession.Parts.Work.Save(NXOpen.Part.SaveComponents.True,NXOpen.Part.CloseAfterSave.False, out status);       4 修改项目的属性,将输出文件定位到ugii目录   5 编译直接运行生成的exe文件(不需要启动UG)   6 在d:下会生成文件1.prt    using System;   using NXOpen;   using NXOpen.UF;       namespace drawBlock   {      class Class1      {        public static Session theSession;        public static UFSession theUFSession;            static void Main(string[] args)        {          theSession = Session.GetSession();           theUFSession = UFSession.GetUFSession();           theSession.Parts.NewDisplay("d:\1.prt",NXOpen.Part.Units.Millimeters);               NXOpen.Features.Feature nullFeatures_Feature = null;           NXOpen.Part pp=theSession.Parts.Work;               NXOpen.Features.BlockFeatureBuilder myblock=pp.Features.CreateBlockFeatureBuilder(nullFeatures_Feature) ;          Point3d ps = new Point3d(0.0, 0.0, 0.0);           myblock.SetOriginAndLengths(ps, "100", "100", "100");           myblock.CommitFeature();           NXOpen.PartSaveStatus status;           theSession.Parts.Work.Save(NXOpen.Part.SaveComponents.True,NXOpen.Part.CloseAfterSave.False, out status);        }      }   }
 
 
 

set UGII_BASE_DIR="D:SiemensNX80" set UGII_LANG=simpl_chinese set UGII_ROOT_DIR="D:SiemensNX80UGII"

D: cd "D:SiemensNX80UGII"

set USER_STARTUP=C:TWBKFapplicationYQ_PrintPDF_Auto.dll start "UG80" "D:SiemensNX80UGIIugraf.exe"

echo on rem pause exit

原文地址:https://www.cnblogs.com/whiteIcrow/p/3857809.html