The second development of UG has two systems: Open and NXOpen. Open is mainly a styling function, and NXOpen is comprehensive. Open originally supports C/C ++ and. net NXOpen. UF namespaces. NXOpen supports C ++ and. net.
The Open system supports the original UFun or API of C, with the most users. Later, Open C ++ emerged. However, Open C ++ supports editing and other attribute behaviors and cannot be created. Therefore, features are generally created through APIS, such as entities, and queried and modified through C ++ classes.
The NXOpen system is fully object-oriented, so features can be created and modified. Of course, NXOpen supports almost all UG functions.
Open
NXOpen
C
UFun (API); process-oriented development; mainly supports styling
C ++
Open C ++ class library; object-oriented development; some support styling functions, without feature creation functions, etc., need to use UFun
Supported by the NXOpen namespace, the corresponding header file must be included.
. Net
UFun is encapsulated in the NXOpen. UF namespace.
Supported by the NXOpen namespace, the corresponding Assembly needs to be referenced.
Therefore, if you use the C/C ++ method, you can use Open C and C ++ to create features and use C ++ for management. If you use. net, you can directly use NXOpen. If you are not familiar with NXOpen, you can follow the knowledge of Open C to get started with NXOpen. UF.
The following examples show how to use the above system. Because the. net platform is common, I only use the C # example and VB. I Don't Understand java. Sorry.
1. Open C
1. Example of Traversal
# Include <uf_object_types.h>
# Include <uf_part.h>
# Include <uf_obj.h>
# Include <uf_modl.h>
# Include <string>
# Include <sstream>
Using std: string;
Using std: stringstream;
// The following is a program snippet.
UgSession session (true );
Try
{
/* TODO: Add your application code here */
Uf_list_p_t lpObj;
UF_MODL_create_list (& lpObj );
Tag_t prt = UF_PART_ask_display_part ();
Tag_t Next_tag = NULL_TAG;
Do
{
UF_OBJ_cycle_objs_in_part (prt, UF_solid_type, & Next_tag );
If (Next_tag = NULL_TAG) break;
Int t, subtype;
UF_OBJ_ask_type_and_subtype (Next_tag, & t, & subtype );
If (subtype = UF_solid_body_subtype)
Uf_modl_put_list_item (lpobj, next_tag );
} While (1 );
Logical is_open;
Uf_ui_is_listing_window_open (& is_open );
If (! Is_open) uf_ui_open_listing_window ();
Int sum;
Uf_modl_ask_list_count (lpobj, & sum );
For (INT I = 0; I <sum; I ++)
{
Tag_t T;
Uf_modl_ask_list_item (lpobj, I, & T );
Stringstream S;
S <(INT) T;
String STR;
STR = S. STR ();
Uf_ui_write_listing_window (Str. c_str ());
Uf_ui_write_listing_window ("\ n ");
}
// Uf_ui_exit_listing_window ();
Uf_modl_delete_list (& lpobj );
}
/* Handle errors */
Catch (const ugexception & exception)
{
Processexception (exception );
}
2. Example of creating a block
# Include <UF. h>
# Include <uf_ui.h>
# Include <uf_exit.h>
# Include <uf_modl.h>
// The following is a program snippet.
/* Initialize the API environment */
If (uf_call (uf_initialize ()))
{
/* Failed to initialize */
Return;
}
/* Todo: add your application code here */
Double corner [3] = {0, 0 };
Char * edge [3] = {"10", "5", "20 "};
Tag_t tag;
Uf_modl_create_block (uf_nullsign, null_tag, corner, edge, & tag );
/* Terminate the API environment */
Uf_call (uf_terminate ());
Ii. Open c ++
1. Example of Traversal
# Include <ug_typed.hxx>
# Include <ug_part.hxx>
# Include <ug_body.hxx>
# Include <ug_string.hxx>
Using std: string;
// The following is a program snippet.
UgSession session (true );
Try
{
/* TODO: Add your application code here */
UgPart * pWorkPart = UgSession: getWorkPart ();
UgTypedObject * pObj;
Ostrstream buffer;
For (pObj = pWorkPart-> iterateFirst ();
PObj;
PObj = pWorkPart-> iterateNext (pObj ))
{
Std: string name = pObj-> getName ();
UgBody * pBody = dynamic_cast <UgBody *> (pObj );
If (pBody)
{
Buffer <(int) pBody-> getTag () <"\ n ";
}
}
UgInfoWindow: open ();
UgInfoWindow: write (string (buffer. str ()));
Delete buffer. str ();
}
/* Handle errors */
Catch (const UgException & exception)
{
ProcessException (exception );
}
2. Example of searching by template
# Include <ug_body.hxx>
# Include <ug_iterator.hxx>
# Include <ug_string.hxx>
// The following is a program snippet.
UgSession session (true );
Try
{
/* TODO: Add your application code here */
Ostrstream buffer;
// Construct an iterator for NX face objects
UgIterator <UgBody> pObj; // workpart can be specified in other ways
// UgIterator <UgFace *> curFace;
//// Loop through all faces
// While (! CurFace. isFinished ())
//{
/// Get the name of the current face
// Std: string faceName = (* curFace)-> getName ();
// CurFace. findNext ();
//}
// Loop through all faces
While (! PObj. isFinished ())
{
// Get the name of the current face
Std: string faceName = (* pObj)-> getName ();
Buffer <(int) (* pObj)-> getTag () <endl;
PObj. findNext ();
}
UgInfoWindow: open ();
UgInfoWindow: write (std: string (buffer. str ()));
Delete buffer. str ();
}
/* Handle errors */
Catch (const UgException & exception)
{
ProcessException (exception );
}
Iii. NXOpen C ++
1. Example of creating a block
# Include <nxopen/session. hxx>
# Include <nxopen/part. hxx>
# Include <nxopen/features_blockfeaturebuilder.hxx>
# Include <nxopen/features_block.hxx>
# Include <nxopen/partcollection. hxx>
# Include <nxopen/features_featurecollection.hxx>
# Include <nxopen/UI. hxx>
# Include <nxopen/nxmessagebox. hxx>
Using namespace nxopen;
// The following is a program snippet.
Nxopen: Session * thesession = nxopen: Session: getsession ();
Try
{
/* Todo: add your application code here */
PART * thepart = thesession-> parts ()-> Work ();
Nxopen: features: feature * block = NULL;
Nxopen: features: blockfeaturebuilder * thebuilder = thepart-> features ()-> createblockfeaturebuilder (Block );
Nxopen: point3d basepoint (100,100,100 );
Thebuilder-> setoriginandlengths (basepoint, "100", "200", "300 ");
// Nxopen. Body thebody = NULL;
// Thebuilder. setbooleanoperationandtarget (nxopen. features. feature. booleantype. Create, thebody );
Thebuilder-> commit ();
// Thebuilder-> commitfeature ();
Nxopen: Ui: getui ()-> nxmessagebox ()-> show ("", nxmessagebox: dialogtype: dialogtypeinformation, "OK! ");
// UI-> getui ()-> nxmessagebox. Show ("", nxmessagebox. dialogtype. Information, "OK! ");
}
/* Handle errors */
Catch (const ugexception & exception)
{
Processexception (exception );
}
2. Examples of traversing features
# Include <NXOpen/Session. hxx>
# Include <NXOpen/Part. hxx>
# Include <NXOpen/Features_BlockFeatureBuilder.hxx>
# Include <NXOpen/Features_Block.hxx>
# Include <NXOpen/PartCollection. hxx>
# Include <NXOpen/Features_FeatureCollection.hxx>
# Include <NXOpen/UI. hxx>
# Include <NXOpen/NXMessageBox. hxx>
# Include <NXOpen/ListingWindow. hxx>
Using namespace NXOpen;
// The following is a program snippet.
NXOpen: Session * theSession = NXOpen: Session: GetSession ();
Try
{
/* TODO: Add your application code here */
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, "OK! ");
// UI-> GetUI ()-> NXMessageBox. Show ("", NXMessageBox. DialogType. Information, "OK! ");
}
/* Handle errors */
Catch (const UgException & exception)
{
ProcessException (exception );
}
Iv. NXOpen C #
1. Example of creating a blcok
Using NXOpen;
Using NXOpen. Utilities;
Using NXOpen. UF;
Using NXOpenUI;
// The following is a program snippet.
Session theSession = Session. GetSession ();
Try
{
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, "100", "200", "300 ");
TheBuilder. Commit ();
// TheBuilder. CommitFeature ();
UI. GetUI (). NXMessageBox. Show ("", NXMessageBox. DialogType. Information, "OK! ");
}
Catch (NXException ex)
{
UI. GetUI (). NXMessageBox. Show ("error! ", NXMessageBox. DialogType. Error, ex. Message );
}
2. Examples of traversing features
Using NXOpen;
Using nxopen. utilities;
Using nxopen. UF;
Using nxopenui;
// The following is a program snippet.
Session thesession = session. getsession ();
Thesession. listingwindow. open ();
Try
{
Part thepart = thesession. parts. Work;
Foreach (nxopen. features. Feature C in thepart. features)
{
// Nxopen. features. Block T = C as nxopen. features. block;
// If (T! = NULL)
//{
// Thesession. listingwindow. writeline (T. tostring ());
//}
Thesession. listingwindow. writeline (C. Name + "--" + C. tostring ());
}
Ui. getui (). nxmessagebox. Show ("", nxmessagebox. dialogtype. Information, "OK! ");
}
Catch (nxexception ex)
{
UI. GetUI (). NXMessageBox. Show ("error! ", NXMessageBox. DialogType. Error, ex. Message );
}
5. NXOpen. UF
1. Following the example 1 sub-implementation in Open C
Using NXOpen;
Using NXOpen. Utilities;
Using NXOpen. UF;
Using NXOpenUI;
NXOpen. UF. UFSession theUFSession = NXOpen. UF. UFSession. GetUFSession ();
Try
{
Double [] corner = {0, 0, 0 };
String [] edge = {"10", "5", "20 "};
Tag tag;
TheUFSession. Modl. CreateBlock1 (FeatureSigns. Nullsign, corner, edge, out tag );
}
Catch (NXException ex)
{
UI. GetUI (). NXMessageBox. Show ("error! ", NXMessageBox. DialogType. Error, ex. Message );
}
2. Follow the example 2 in Open C to implement
Using NXOpen;
Using NXOpen. Utilities;
Using NXOpen. UF;
Using NXOpenUI;
NXOpen. UF. UFSession theUFSession = NXOpen. UF. UFSession. GetUFSession ();
Try
{
Tag [] list = null;
Tag thePart = theUFSession. Part. AskDisplayPart ();
TheUFSession. Modl. CreateList (out list );
Tag Next_tag = Tag. Null;
Do
{
TheUFSession. Obj. CycleObjsInPart (thePart, 70/* UF_solid_type */, ref Next_tag );
If (Next_tag = Tag. Null) break;
Int t, subType;
TheUFSession. Obj. AskTypeAndSubtype (Next_tag, out t, out subType );
If (subType = 0/* UF_solid_body_subtype */)
TheUFSession. Modl. PutListItem (list, Next_tag );
} While (true );
Bool isOpen;
TheUFSession. Ui. IsListingWindowOpen (out isOpen );
If (! IsOpen) theUFSession. Ui. OpenListingWindow ();
Int sum;
TheUFSession. Modl. AskListCount (list, out sum );
For (int I = 0; I <sum; I ++)
{
Tag t;
TheUFSession. Modl. AskListItem (list, I, out t );
TheUFSession. Ui. WriteListingWindow (t. ToString ());
}
/* Treat all the arguments with the "Output to be freed" annotation as an output parameter.
* The system takes care of freeing memory .*/
}
Catch (NXException ex)
{
UI. GetUI (). NXMessageBox. Show ("error! ", NXMessageBox. DialogType. Error, ex. Message );
}