1 用.net2003建立一个控制台应用程序 2 将目录ugii\managed下除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); } } }