Ug secondary development learning advanced helper-operation recording

Source: Internet
Author: User

What is operation recording? This is a tool added in the ug nx series for recording manual operation commands. A series of NXOpen program commands for recording. These commands can be used to reproduce the operation. Of course, we can also learn NXOpen.

However, recording programs often record the command stream for manual operations. Many of the information is fixed operations and not flexible. The entire manual operation process can be reproduced. At the same time, not all commands can be recorded. As the UG Help system said: Some commands cannot be recorded, and some commands can only be partially recorded. As I mentioned in my previous post, UG has two Development Kits: Open and NXOpen, which are mainly APIs and APIs. NXOpen is a class library. The operation recording result is in the NXOpen program format. However, Open is better than NXOpen in some details. Therefore, operation recording cannot replace secondary development.

However, UG operation recording has a lot of significance: Reproduce the entire operation through text; change the program content can moderately change the operation process without redoing the entire operation; this record helps us to learn about the NXOpen program.

Now, we will record a command stream for creating a block.

I use NX6, and other versions are similar.

Select User Interface in "Preferences ].

In the "user interface Preferences" dialog box, select operation record language in the "Operation Records" Tab ].

UG NX6 supports recording of java, C #, C ++, and other language commands. C # is supported by NX6.

Select Operation record in the Tools menu. There are three common commands:

Recording-Pause recording-stop recording

You can also choose operation recording from the toolbar ].

Select recording and select the directory for saving the recording command program.

The recording mark will appear on the menu and toolbar of UG. If no command is available, it cannot be recorded.

Select the block command to bring up the create block dialog box.

I changed the length, width, and height to 10, 20, and 30. Click "OK" to generate the block.

Click Save.

Select Stop recording to end the recording.

Next we will talk about this recording program.

View plaincopy to clipboardprint?

··· · 50 ······· · 90 ····· · 140 · 150

  1. // NX 6.0.0.24
  2. // Journal created by nicholas on Tue Feb 17 21:18:57 2009 China Standard Time
  3. //
  4. Using System;
  5. Using NXOpen;
  6. Public class NXJournal
  7. {
  8. Public static void Main (string [] args)
  9. {
  10. Session theSession = Session. GetSession ();
  11. Part workPart = theSession. Parts. Work;
  12. Part displayPart = theSession. Parts. Display;
  13. //----------------------------------------------
  14. // Menu: insert-> Design Feature-> Block...
  15. //----------------------------------------------
  16. NXOpen. Session. UndoMarkId markId1;
  17. MarkId1 = theSession. SetUndoMark (NXOpen. Session. MarkVisibility. Visible, "Start ");
  18. NXOpen. Features. Feature nullFeatures_Feature = null;
  19. NXOpen. Features. BlockFeatureBuilder blockFeatureBuilder1;
  20. BlockFeatureBuilder1 = workPart. Features. CreateBlockFeatureBuilder (nullFeatures_Feature );
  21. BlockFeatureBuilder1.BooleanOption. Type = NXOpen. GeometricUtilities. BooleanOperation. BooleanType. Create;
  22. Body [] targetBodies1 = new Body [1];
  23. Body nullBody = null;
  24. TargetBodies1 [0] = nullBody;
  25. BlockFeatureBuilder1.BooleanOption. SetTargetBodies (targetBodies1 );
  26. TheSession. SetUndoMarkName (markId1, "Block dialog box ");
  27. NXOpen. Session. UndoMarkId markId2;
  28. MarkId2 = theSession. SetUndoMark (NXOpen. Session. MarkVisibility. Invisible, "Block ");
  29. BlockFeatureBuilder1.Type = NXOpen. Features. BlockFeatureBuilder. Types. OriginAndEdgeLengths;
  30. Point point1;
  31. Point1 = blockFeatureBuilder1.OriginPoint;
  32. BlockFeatureBuilder1.OriginPoint = point1;
  33. Point3d originPoint1 = new Point3d (0.0, 0.0, 0.0 );
  34. BlockFeatureBuilder1.SetOriginAndLengths (originPoint1, "10", "20", "30 ");
  35. BlockFeatureBuilder1.SetBooleanOperationAndTarget (NXOpen. Features. Feature. BooleanType. Create, nullBody );
  36. NXOpen. Features. Feature feature1;
  37. Feature1 = blockFeatureBuilder1.CommitFeature ();
  38. TheSession. DeleteUndoMark (markId2, null );
  39. TheSession. SetUndoMarkName (markId1, "Block ");
  40. BlockFeatureBuilder1.Destroy ();
  41. WorkPart. FacetedBodies. DeleteTemporaryFacesAndEdges ();
  42. //----------------------------------------------
  43. // Menu: file-> Save
  44. //----------------------------------------------
  45. PartSaveStatus partSaveStatus1;
  46. PartSaveStatus1 = workPart. Save (NXOpen. BasePart. SaveComponents. True, NXOpen. BasePart. CloseAfterSave. False );
  47. PartSaveStatus1.Dispose ();
  48. //----------------------------------------------
  49. // Menu: Tools> Operation Records> Stop Recording
  50. //----------------------------------------------
  51. }
  52. Public static int GetUnloadOption (string dummy) {return (int) Session. LibraryUnloadOption. Immediately ;}
  53. }

// NX 6.0.0.24 // Journal created by Nicholas on TUE Feb 17 21:18:57 2009 China Standard Time // 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; // ------------------------------------------------ // menu: insert-> 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 dialog box"); nxopen. session. undomarkid markid2; markid2 = thesession. setundomark (nxopen. session. markvisibility. invisible, "Block"); blockfeaturebuilder1.type = nxopen. features. blockfeaturebuilder. types. originandedgelengths; point point1; point1 = blockfeaturebuilder1.originpoint; region = point1; point3d originpoint1 = new point3d (0.0, 0.0, 0.0); partition (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 (); // saved // menu: file-> Save // saved partsavestatus partsavestatus1; partsavestatus1 = workpart. save (nxopen. basepart. savecomponents. true, nxopen. basepart. closeaftersave. false); partsavestatus1.dispose (); // outputs // menu: tool-> operation record-> stop recording // records} public static int getunloadoption (string dummy) {return (INT) session. libraryunloadoption. immediately ;}}

The Main function is an entry function.

Rows 11-13 are declarations of common variables.

17-57 is the command record for creating blocks.

Among them, 17-18 is the declaration of UndoMark. It is equivalent to a transaction and can be affected by a rollback program.

By default, UG sets UndoMark for each command. Therefore, if the program using UndoMark blocks is less efficient, use UndoMark to declare that the program in the middle is not used as your UndoMark. It helps improve efficiency.

51-53 end the UndoMark block.

22NXOpen adopts the factory-like mode. workPart. Features. CreateBlockFeatureBuilder generates an object.

49 feature1 = blockFeatureBuilder1.CommitFeature (); generate features

-65 click the Save button to record the command.

Original article: http://blog.csdn.net/begtostudy/archive/2009/02/17/3903124.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.