明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4967|回复: 7

[Scmold]UG二次开发入门实例

[复制链接]
发表于 2011-12-13 21:10 | 显示全部楼层 |阅读模式
本帖最后由 chpmould 于 2012-9-9 23:17 编辑

论坛上很难看到有关UG二次开发的贴,今天刚好有空发个简单的例子,活跃一下论坛的气氛,下面是用C#在UG中的二次开发的简单实例,[创建一个正方体],希望可以帮到需要入门的朋友,高手请勿抛砖...

  1. using System;
  2. public class Program
  3. {
  4.     private static Session theSession;
  5.     public static Program theProgram;
  6.     public static bool isDisposeCalled;
  7.     public Program()
  8.     {
  9.         try
  10.         {
  11.             theSession = Session.GetSession();
  12.             isDisposeCalled = false;
  13.         }
  14.         catch (NXOpen.NXException ex)
  15.         {
  16.             UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
  17.         }
  18.     }
  19.     public static int Main(string[] args)
  20.     {
  21.         int retValue = 0;
  22.         try
  23.         {
  24.             theProgram = new Program();
  25.             Part thePart = theSession.Parts.Work;
  26.             NXOpen.Features.Feature block = null;
  27.             NXOpen.Features.BlockFeatureBuilder theBuilder = thePart.Features.CreateBlockFeatureBuilder(block);
  28.             NXOpen.Point3d basePoint = new Point3d(100f, 100f, 100f);
  29.             theBuilder.SetOriginAndLengths(basePoint, "0", "0", "0");
  30.             theBuilder.Commit(); UI.GetUI().NXMessageBox.Show("", NXMessageBox.DialogType.Information, "你已成功完成了第一个二次开发程序!");
  31.             theProgram.Dispose();
  32.         }
  33.         catch (NXOpen.NXException ex)
  34.         {
  35.             UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
  36.         }
  37.         return retValue;
  38.     }
  39.     public void Dispose()
  40.     {
  41.         try
  42.         {
  43.             if (isDisposeCalled == false)
  44.             {
  45.                 //Add your application code here
  46.             }
  47.             isDisposeCalled = true;
  48.         }
  49.         catch (NXOpen.NXException ex)
  50.         {
  51.             UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
  52.         }
  53.     }
  54.     public static int GetUnloadOption(string arg)
  55.     {
  56.         return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
  57.     }
  58. }


 楼主| 发表于 2011-12-14 18:58 | 显示全部楼层
下面是用C++实现遍历特征的部分代码
  1. NXOpen::Session *theSession = NXOpen::Session::GetSession();
  2. try
  3. {
  4.   Part* thePart = theSession->Parts()->Work();
  5.   theSession->ListingWindow()->Open();
  6.   NXOpen::Features::FeatureCollection::iterator i;
  7.   for (i=thePart->Features()->begin();i!=thePart->Features()->end();i++)
  8.   {
  9.    theSession->ListingWindow()->WriteLine((*i)->Name()+"--"+(*i)->GetJournalIdentifier());
  10.   }
  11.   NXOpen::UI::GetUI()->NXMessageBox()->Show("", NXMessageBox::DialogType::DialogTypeInformation, "This is only test for ug!");
  12. }
  13. catch ( const UgException &exception )
  14. {
  15. processException( exception );
  16. }
复制代码
发表于 2011-12-14 19:16 | 显示全部楼层
刚入门学习
发表于 2013-6-14 13:59 | 显示全部楼层
现在在学GRIP C+实在是太难了点
发表于 2013-10-19 19:38 | 显示全部楼层
可有教程吗,都是同行
发表于 2017-10-12 09:37 | 显示全部楼层
回帖是一种美德!感谢楼主的无私分享 谢谢
发表于 2018-6-26 07:14 来自手机 | 显示全部楼层
谢谢楼主分享
发表于 2021-12-10 21:47 | 显示全部楼层
谢谢楼主分享 ,有更全的吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-19 08:26 , Processed in 0.424595 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表