- 积分
- 14398
- 明经币
- 个
- 注册时间
- 2007-7-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 chpmould 于 2012-9-9 23:17 编辑
论坛上很难看到有关UG二次开发的贴,今天刚好有空发个简单的例子,活跃一下论坛的气氛,下面是用C#在UG中的二次开发的简单实例,[创建一个正方体],希望可以帮到需要入门的朋友,高手请勿抛砖...![](source/plugin/imc_colorcode/images/loading.gif)
- using System;
- public class Program
- {
- private static Session theSession;
- public static Program theProgram;
- public static bool isDisposeCalled;
- public Program()
- {
- try
- {
- theSession = Session.GetSession();
- isDisposeCalled = false;
- }
- catch (NXOpen.NXException ex)
- {
- UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
- }
- }
- public static int Main(string[] args)
- {
- int retValue = 0;
- try
- {
- theProgram = new Program();
- Part thePart = theSession.Parts.Work;
- NXOpen.Features.Feature block = null;
- NXOpen.Features.BlockFeatureBuilder theBuilder = thePart.Features.CreateBlockFeatureBuilder(block);
- NXOpen.Point3d basePoint = new Point3d(100f, 100f, 100f);
- theBuilder.SetOriginAndLengths(basePoint, "0", "0", "0");
- theBuilder.Commit(); UI.GetUI().NXMessageBox.Show("", NXMessageBox.DialogType.Information, "你已成功完成了第一个二次开发程序!");
- theProgram.Dispose();
- }
- catch (NXOpen.NXException ex)
- {
- UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
- }
- return retValue;
- }
- public void Dispose()
- {
- try
- {
- if (isDisposeCalled == false)
- {
- //Add your application code here
- }
- isDisposeCalled = true;
- }
- catch (NXOpen.NXException ex)
- {
- UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
- }
- }
- public static int GetUnloadOption(string arg)
- {
- return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
- }
- }
|
|