chpmould 发表于 2011-12-13 21:10

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

本帖最后由 chpmould 于 2012-9-9 23:17 编辑

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

chpmould 发表于 2011-12-14 18:58

下面是用C++实现遍历特征的部分代码NXOpen::Session *theSession = NXOpen::Session::GetSession();
try
{
Part* thePart = theSession->Parts()->Work();
theSession->ListingWindow()->Open();
NXOpen::Features::FeatureCollection::iterator i;
for (i=thePart->Features()->begin();i!=thePart->Features()->end();i++)
{
   theSession->ListingWindow()->WriteLine((*i)->Name()+"--"+(*i)->GetJournalIdentifier());
}
NXOpen::UI::GetUI()->NXMessageBox()->Show("", NXMessageBox::DialogType::DialogTypeInformation, "This is only test for ug!");
}
catch ( const UgException &exception )
{
processException( exception );
}

lizhu 发表于 2011-12-14 19:16

刚入门学习

198526 发表于 2013-6-14 13:59

现在在学GRIP C+实在是太难了点

邹锋 发表于 2013-10-19 19:38

可有教程吗,都是同行

pengfei2010 发表于 2017-10-12 09:37

回帖是一种美德!感谢楼主的无私分享 谢谢

alpha223334 发表于 2018-6-26 07:14

谢谢楼主分享

1028882406@qq.c 发表于 2021-12-10 21:47

谢谢楼主分享 ,有更全的吗
页: [1]
查看完整版本: [Scmold]UG二次开发入门实例