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
- // 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;
-
- 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 ();
-
- //----------------------------------------------
- // Menu: file-> Save
- //----------------------------------------------
- PartSaveStatus partSaveStatus1;
- PartSaveStatus1 = workPart. Save (NXOpen. BasePart. SaveComponents. True, NXOpen. BasePart. CloseAfterSave. False );
-
- PartSaveStatus1.Dispose ();
- //----------------------------------------------
- // Menu: Tools> Operation Records> 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 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