Guest User

NX Open C#

a guest
Jul 1st, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.73 KB | None | 0 0
  1. using System;
  2. using NXOpen;
  3. using NXOpen.UF;
  4.  
  5. public class Program
  6. {
  7.     // class members
  8.     private static Session theSession;
  9.     private static UI theUI;
  10.     private static UFSession theUfSession;
  11.     public static Program theProgram;
  12.     public static bool isDisposeCalled;
  13.  
  14.     //------------------------------------------------------------------------------
  15.     // Constructor
  16.     //------------------------------------------------------------------------------
  17.     public Program()
  18.     {
  19.         try
  20.         {
  21.             theSession = Session.GetSession();
  22.             theUI = UI.GetUI();
  23.             theUfSession = UFSession.GetUFSession();
  24.             isDisposeCalled = false;
  25.         }
  26.         catch (NXOpen.NXException ex)
  27.         {
  28.             // ---- Enter your exception handling code here -----
  29.             // UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
  30.         }
  31.     }
  32.  
  33.     //------------------------------------------------------------------------------
  34.     //  Explicit Activation
  35.     //      This entry point is used to activate the application explicitly
  36.     //------------------------------------------------------------------------------
  37.     public static int Main(string[] args)
  38.     {
  39.         int retValue = 0;
  40.         try
  41.         {
  42.             theProgram = new Program();
  43.  
  44.             //TODO: Add your application code here
  45.             Tag UFPart1;
  46.             string modelName = "test";
  47.             int meterSystem = 1;
  48.             theUfSession.Part.New(modelName, meterSystem, out UFPart1);
  49.             //Создание массива точек для замкнутого объекта
  50.             double[,] pointMassive = new double[8, 3]
  51.             {
  52.                 {20, 0, 0 },
  53.                 {20, 48, 0 },
  54.                 {36, 48, 0 },
  55.                 {36, 37, 0 },
  56.                 {26, 37, 0 },
  57.                 {26, 11, 0 },
  58.                 {36, 11, 0 },
  59.                 {36, 0, 0 }
  60.             };
  61.             UFCurve.Line[] line = new UFCurve.Line[pointMassive.Length];
  62.             for (int i = 0; i < (pointMassive.Length); i++)
  63.             {
  64.  
  65.                 line[i] = new UFCurve.Line();
  66.             }
  67.             for (int i = 0; i < (pointMassive.Length - 1); i++)
  68.             {
  69.                 line[i].start_point = new double[3];
  70.                 line[i].end_point = new double[3];
  71.                     for (int j = 0; j < 3; j++)
  72.                     {
  73.                         line[i].start_point[j] = pointMassive[i, j];
  74.                         line[i].end_point[j] = pointMassive[i + 1, j];
  75.                     }
  76.             }
  77.             for (int j=0; j<3; j++)
  78.             {
  79.                 line[pointMassive.Length - 1].start_point[j] = pointMassive[pointMassive.Length - 1, j];
  80.                 line[pointMassive.Length - 1].end_point[j] = pointMassive[0, j];
  81.             }
  82.             Tag[] array2D = new Tag[pointMassive.Length];
  83.             for (int i=0; i<(pointMassive.Length); i++)
  84.             {
  85.                 theUfSession.Curve.CreateLine(ref line[i], out array2D[i]);
  86.             }
  87.             double[] refPoint = { 0.00, 0.00, 0.00 };
  88.             double[] dirPoint = { 1.00, 0.00, 0.00 };
  89.             string[] limit = { "0", "360" };
  90.             Tag[] features;
  91.             theUfSession.Modl.CreateRevolved(array2D, limit, refPoint, dirPoint, FeatureSigns.Nullsign, out features);
  92.             theUfSession.Part.Save();
  93.             theProgram.Dispose();
  94.         }
  95.         catch (NXOpen.NXException ex)
  96.         {
  97.             // ---- Enter your exception handling code here -----
  98.  
  99.         }
  100.         return retValue;
  101.     }
  102.  
  103.     //------------------------------------------------------------------------------
  104.     // Following method disposes all the class members
  105.     //------------------------------------------------------------------------------
  106.     public void Dispose()
  107.     {
  108.         try
  109.         {
  110.             if (isDisposeCalled == false)
  111.             {
  112.                 //TODO: Add your application code here
  113.             }
  114.             isDisposeCalled = true;
  115.         }
  116.         catch (NXOpen.NXException ex)
  117.         {
  118.             // ---- Enter your exception handling code here -----
  119.  
  120.         }
  121.     }
  122.  
  123.     public static int GetUnloadOption(string arg)
  124.     {
  125.         //Unloads the image explicitly, via an unload dialog
  126.         //return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
  127.  
  128.         //Unloads the image immediately after execution within NX
  129.         // return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
  130.  
  131.         //Unloads the image when the NX session terminates
  132.         return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
  133.     }
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment