我想看一级黄色大片_久久亚洲国产精品一区二区_久久精品免视看国产明星_91久久青青青国产免费

您的位置:網(wǎng)站首頁 > UG教程下載

UG二次開發(fā)學習進階幫手——操作錄制

時間:2010-11-15 10:32:37 來源:

  什么是操作錄制?這是UG NX系列中增加的可以錄制手工操作命令的工具。錄制的一系列NXOpen程序命令。通過這些命令可以重現(xiàn)操作。當然,從中我們也可以用來學習NXOpen。

  然而,錄制的程序往往是記錄我們手工操作的命令流,其中很多信息是固定的操作,不具有靈活性。可以重現(xiàn)整個手工操作過程。同時,不是所有的命令都能夠被錄制。正如UG Help系統(tǒng)所說的:有些命令不能被記錄,有些命令只能部分記錄。正如我以前的帖子說過,UG有個兩個開發(fā)包Open和NXOpen,Open主要是API和包裝 API的類。NXOpen是類庫。操作錄制的結(jié)果是NXOpen程序形式。但是Open在某些細節(jié)上要強于NXOpen。所以,操作錄制不能代替二次開發(fā)。

  雖然如此,UG操作錄制確實有很多意義:通過文本重現(xiàn)整個操作;改變程序內(nèi)容可以適度的變動操作過程,不用重做整個操作;通過這個記錄可以幫助我們學習NXOpen程序。

  現(xiàn)在,我們來錄制一個創(chuàng)建block的命令流。

  我用的是NX6,其他版本差不多。

  在菜單【首選項】里選擇【用戶界面】。

  在對話框“用戶界面首選項”中的【操作記錄】Tab中選擇【選擇操作記錄語言】。

  UG NX6支持java、C#、C++等語言命令錄制,其中C#是NX6新加入支持的。

  現(xiàn)在在菜單【工具】中選擇【操作記錄】,其中有下面三個常用命令:

  錄制-暫停錄制-停止錄制

  當然也可以選擇工具條【操作錄制】。

  選擇【錄制】,選擇保存錄制命令程序的目錄。

  之后UG的菜單和工具條上會出現(xiàn)可錄制的標示,如果沒有的命令是不能被錄制的。

  

  選擇block命令彈出創(chuàng)建block的對話框。

  我就是改了長寬高為10、20、30,點擊確定生成block。

  點擊保存按鈕。

  選擇【停止錄制】結(jié)束本次錄制。

  下面我們將說說這個錄制的程序。

  view plaincopy to clipboardprint?

  ·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150

  // NX 6.0.0.24

  // Journal created by nicholas on Tue Feb 17 21:18:57 2009 中國標準時間

  //

  using System;

  using NXOpen;

  public class NXJournal

  {

  public static void Main(string[] args)

  {

  Session theSession = Session.GetSession();

  Part workPart = theSession.Parts.Work;

  Part displayPart = theSession.Parts.Display;

  // ----------------------------------------------

  // 菜單:插入->Design Feature->Block...

  // ----------------------------------------------

  NXOpen.Session.UndoMarkId markId1;

  markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

  NXOpen.Features.Feature nullFeatures_Feature = null;

  NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;

  blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);

  blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

  Body[] targetBodies1 = new Body[1];

  Body nullBody = null;

  targetBodies1[0] = nullBody;

  blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1);

  theSession.SetUndoMarkName(markId1, "Block 對話框");

  NXOpen.Session.UndoMarkId markId2;

  markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Block");

  blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;

  Point point1;

  point1 = blockFeatureBuilder1.OriginPoint;

  blockFeatureBuilder1.OriginPoint = point1;

  Point3d originPoint1 = new Point3d(0.0, 0.0, 0.0);

  blockFeatureBuilder1.SetOriginAndLengths(originPoint1, "10", "20", "30");

  blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);

  NXOpen.Features.Feature feature1;

  feature1 = blockFeatureBuilder1.CommitFeature();

  theSession.DeleteUndoMark(markId2, null);

  theSession.SetUndoMarkName(markId1, "Block");

  blockFeatureBuilder1.Destroy();

  workPart.FacetedBodies.DeleteTemporaryFacesAndEdges();

  // ----------------------------------------------

  // 菜單:文件->保存

  // ----------------------------------------------

  PartSaveStatus partSaveStatus1;

  partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

  partSaveStatus1.Dispose();

  // ----------------------------------------------

  // 菜單:工具->操作記錄->Stop Recording

  // ----------------------------------------------

  }

  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }

  }

  // NX 6.0.0.24

  // Journal created by nicholas on Tue Feb 17 21:18:57 2009 中國標準時間

  //

  using System;

  using NXOpen;

  public class NXJournal

  {

  public static void Main(string[] args)

  {

  Session theSession = Session.GetSession();

  Part workPart = theSession.Parts.Work;

  Part displayPart = theSession.Parts.Display;

  // ----------------------------------------------

  // 菜單:插入->Design Feature->Block...

  // ----------------------------------------------

  NXOpen.Session.UndoMarkId markId1;

  markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start");

  NXOpen.Features.Feature nullFeatures_Feature = null;

  NXOpen.Features.BlockFeatureBuilder blockFeatureBuilder1;

  blockFeatureBuilder1 = workPart.Features.CreateBlockFeatureBuilder(nullFeatures_Feature);

  blockFeatureBuilder1.BooleanOption.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create;

  Body[] targetBodies1 = new Body[1];

  Body nullBody = null;

  targetBodies1[0] = nullBody;

  blockFeatureBuilder1.BooleanOption.SetTargetBodies(targetBodies1);

  theSession.SetUndoMarkName(markId1, "Block 對話框");

  NXOpen.Session.UndoMarkId markId2;

  markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Block");

  blockFeatureBuilder1.Type = NXOpen.Features.BlockFeatureBuilder.Types.OriginAndEdgeLengths;

  Point point1;

  point1 = blockFeatureBuilder1.OriginPoint;

  blockFeatureBuilder1.OriginPoint = point1;

  Point3d originPoint1 = new Point3d(0.0, 0.0, 0.0);

  blockFeatureBuilder1.SetOriginAndLengths(originPoint1, "10", "20", "30");

  blockFeatureBuilder1.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, nullBody);

  NXOpen.Features.Feature feature1;

  feature1 = blockFeatureBuilder1.CommitFeature();

  theSession.DeleteUndoMark(markId2, null);

  theSession.SetUndoMarkName(markId1, "Block");

  blockFeatureBuilder1.Destroy();

  workPart.FacetedBodies.DeleteTemporaryFacesAndEdges();

  // ----------------------------------------------

  // 菜單:文件->保存

  // ----------------------------------------------

  PartSaveStatus partSaveStatus1;

  partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);

  partSaveStatus1.Dispose();

  // ----------------------------------------------

  // 菜單:工具->操作記錄->Stop Recording

  // ----------------------------------------------

  }

  public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; }

  }

  Main函數(shù)是入口函數(shù)。

  11-13行是常用變量的聲明。

  17-57是建立block的命令記錄。

  其中,17-18是聲明UndoMark。相當于事務(wù),可以用來回滾程序影響。

  UG默認每個命令都設(shè)置了UndoMark,所以如果用用UndoMark塊的程序效率較低,采用UndoMark聲明中間的程序不在做程序你的UndoMark。對效率提高有幫助。

  51-53結(jié)束UndoMark塊。

  22NXOpen采用類廠模式,workPart.Features.CreateBlockFeatureBuilder是產(chǎn)生一個對象。

  49 feature1 = blockFeatureBuilder1.CommitFeature();生成特征

  62-65點擊保存按鈕的命令錄制。