Showing results for 
Search instead for 
Did you mean: 

Subdivide face


Hi all!


I am new to NX open and right now I am focussing on selecting a face (using Block UI styler),getting its tag,making an isocline on that face using its tag and then dividing the face in two parts using the isocline as a dividing object.


However for some reason the part where I subdivide the face doesnt seem to work, here is the snippet of code:


int AGoel_Face_Select::update_cb(NXOpen::BlockStyler::UIBlock* block)
if(block == face_select0)
//This part selects the face and returns its tag
std::vector<NXOpen::TaggedObject *>facelist= face_select0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
Face*List_faces=(Face *)facelist[0];
tag_t face_tag=List_faces->Tag();
ECHO (" the face tag is = %d\n", face_tag);

//---------Enter your code here----------- This part creates the isocline curve
int titr=0;
double direction[3] = {0.0,0.0,1.0};
double angle = 60;
double dist_tol = TOL;
int isocurve_cnt;
tag_t *isocurve;

//ECHO("The isocurve count is %d\n",isocurve_cnt);
//This part is supposed to create the subdivide face
const double proj_vec[3] = {0};

tag_t feat_obj_id_1=NULL;
//uf_list_p_t t_face_list_1=NULL;
//int lis_co_2=0;
ECHO("The isocurve count is %d,%d,%d,%f \n",isocurve_cnt,*isocurve,face_tag,proj_vec[0]);

catch(exception& ex)
//---- Enter your exception handling code here -----
AGoel_Face_Select::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox:Smiley Very HappyialogTypeError, ex.what());
return 0;


I am using Visual studio 2012 Express edition and I am getting the following result after generating isocline:subdiv_face_faulty.PNG

What i want to get is the following (got it by using divide face option) by using subdiv face:


But the code above doesnt seem to do it. I tried echoing the tag of the subdivided object but I get it as 0 (since it has been defined as NULL ) which inidicates subdiv face is not working properly


Any suggestions how i can do it? Thanks in advance


NOTE: the code has been generated using UI Block Styler template and I am using NX 10


Re: Subdivide face


Not sure if it will make any difference, try passing NULL instead of proj_vec to UF_MODL_create_subdiv_face.

Re: Subdivide face


Tried passing NULL . Doesnt work.

Re: Subdivide face


The code below is VB, but it uses the wrapped C functions. Running the code and selecting the surface of a sphere will result in an unassociative isocline curve being created along with a "subdivide face" feature. The isocline curve is used to create the subdivide face feature.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "subdivide test")


        Dim theFace As Face = Nothing
        If SelectFace("select face", theFace) = Selection.Response.Cancel Then
        End If

        Const isoclineAngle As Double = 60
        Dim isoDir() As Double = {0, 0, 1}
        Dim isoCurveTags() As Tag
        Dim isoCurveCount As Integer
        theUfSession.Modl.CreateIsoclineCurves(theFace.Tag, isoDir, isoclineAngle, 0.001, isoCurveTags, isoCurveCount)

        'lw.WriteLine("subdivide curve count: " & isoCurveCount.ToString)

        Dim subDivideFeatTag As Tag = Tag.Null
        theUfSession.Modl.CreateSubdivFace(isoCurveTags, isoCurveCount, theFace.Tag, 1, Nothing, subDivideFeatTag)


    End Sub

    Function SelectFace(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select an object"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim cursor As Point3d
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple

        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
        title, scope, selAction,
        includeFeatures, keepHighlighted, selectionMask_array,
        selObj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
            Return Selection.Response.Cancel
        End If

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

Re: Subdivide face


Thank you so much for th help. But even after using a similar logic to that which you used in the code you provided , it doesnt seem to work. Any idea as to why its not working? Thanks again. 

Re: Subdivide face


Tested the below C++ code on NX and it works fine.



// Mandatory UF Includes
#include <uf.h>
#include <uf_ui.h>
#include <uf_object_types.h>
#include <uf_modl.h>

// Internal Includes
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Selection.hxx>
#include <NXOpen/UI.hxx>

// Internal+External Includes
#include <NXOpen/Annotations.hxx>
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/Face.hxx>
#include <NXOpen/Line.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>

// Std C++ Includes
#include <iostream>
#include <sstream>

using namespace NXOpen;
using std::string;
using std::exception;
using std::stringstream;
using std::endl;
using std::cout;
using std::cerr;

// Open C error handling
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
int report_error( char *file, int line, char *call, int code)
    if (code) 

		stringstream errmsg;
		errmsg << "Error " << code << " in " << file << " at line " << line << endl;
		errmsg << call << endl;
		UI::GetUI()->NXMessageBox()->Show("Open C Error", NXOpen::NXMessageBox::DialogTypeError, errmsg.str().c_str());
		throw NXOpen::NXException::Create(code);

// NXOpen c++ test class 
class MyClass
    // class members
    static Session *theSession;
    static UI *theUI;


	void do_it();
	void print(const NXString &);
	void print(const string &);
	void print(const char*);
	TaggedObject* select_by_mask();

	Part *workPart, *displayPart;
	Selection *selmgr;
	NXMessageBox *mb;
	ListingWindow *lw;

// Initialize static variables
Session *(MyClass::theSession) = NULL;
UI *(MyClass::theUI) = NULL;

// Constructor 
	// Initialize the Open C API environment */
	UF_CALL( UF_initialize() );

	// Initialize the NX Open C++ API environment
	MyClass::theSession = NXOpen::Session::GetSession();
	MyClass::theUI = UI::GetUI();
	selmgr = theUI->SelectionManager();
	mb = theUI->NXMessageBox();
	lw = theSession->ListingWindow();

    workPart = theSession->Parts()->Work();
	displayPart = theSession->Parts()->Display();

// Destructor
	UF_CALL( UF_terminate() );

// Print string to listing window or stdout
void MyClass::print(const NXString &msg)
	if(! lw->IsOpen() ) lw->Open();
void MyClass::print(const string &msg)
	if(! lw->IsOpen() ) lw->Open();
void MyClass::print(const char * msg)
	if(! lw->IsOpen() ) lw->Open();

// Selection with mask
TaggedObject* MyClass::select_by_mask()
	NXString message("Select Face to sub divide:");
	NXString title("Select Face");
	Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
	Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
	bool include_features = 0;
	bool keep_highlighted = 0;

	// Define the mask triple(s), see also uf_object_types.h.
	// Uncomment or combine the desired mask triples
	std::vector<Selection::MaskTriple> maskArray(1);
	maskArray[0] = Selection::MaskTriple( UF_solid_type, UF_all_subtype, UF_UI_SEL_FEATURE_ANY_FACE); // Faces
	maskArray[0] = Selection::MaskTriple( UF_solid_type, UF_solid_body_subtype, 0 ); // Bodies
	maskArray[0] = Selection::MaskTriple( UF_solid_type, UF_all_subtype, UF_UI_SEL_FEATURE_ANY_EDGE); // Edges
	maskArray[0] = Selection::MaskTriple( UF_component_type, 0, 0 ); // Components
	maskArray[0] = Selection::MaskTriple( UF_line_type, 0, 0 ); // Lines
	maskArray[0] = Selection::MaskTriple( UF_drafting_entity_type, 0, 0 ); // Drafting objects
	Point3d cursor;
	TaggedObject *object;

	// Select objects using filter defined by maskArray triples
	Selection::Response res = selmgr->SelectTaggedObject(
			message, title, scope, action, include_features,
            keep_highlighted, maskArray, &object, &cursor );

	if( res == Selection::ResponseObjectSelected )
		return object;
	return 0;

// Do something
void MyClass::do_it()

	// TODO: add your code here
	double dir[3] = {0.0, 0.0, 1.0};
	double angle = 60;
	double tol;
	int isoCurve_cnt = 0;
	tag_t* isoCurves;
	tag_t feat_id;


	TaggedObject* face_id = select_by_mask();

	if (face_id != NULL)

		UF_CALL(UF_MODL_create_isocline_curves(face_id->Tag(), dir, angle, tol, &isoCurves, &isoCurve_cnt));

		if (isoCurve_cnt > 0)
			UF_CALL(UF_MODL_create_subdiv_face(isoCurves, isoCurve_cnt, face_id->Tag(), 1, NULL, &feat_id));


// Entry point(s) for unmanaged internal NXOpen C/C++ programs
//  Explicit Execution
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
		// Create NXOpen C++ class instance
		MyClass *theMyClass;
		theMyClass = new MyClass();
		delete theMyClass;
    catch (const NXException& e1)
		UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
	catch (const exception& e2)
		UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
	catch (...)
		UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");

// Unload Handler
extern "C" DllExport int ufusr_ask_unload()
	return (int)NXOpen::Session::LibraryUnloadOptionImmediately;

Re: Subdivide face


Thanks so much all of you for your help. I figured out what was wrong and I had forgotten to initialize and terminate the Open C environment. Its working fine now. Thanks again