0% found this document useful (0 votes)
995 views6 pages

Step by Step NX Open C++ Introduction - Cad Cam Development PDF

This document provides a step-by-step guide to creating a basic NX Open C++ application. It describes: 1) recording a journal of actions in NX to generate C++ code, 2) setting up a Visual Studio project and adding required libraries, and 3) executing the code within NX to recreate the recorded actions, in this case creating a 150mm high cylinder. The goal is to introduce the basics of using the NX Open C++ API to develop custom CAD applications within the NX environment.

Uploaded by

Luu Duc Hop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
995 views6 pages

Step by Step NX Open C++ Introduction - Cad Cam Development PDF

This document provides a step-by-step guide to creating a basic NX Open C++ application. It describes: 1) recording a journal of actions in NX to generate C++ code, 2) setting up a Visual Studio project and adding required libraries, and 3) executing the code within NX to recreate the recorded actions, in this case creating a 150mm high cylinder. The goal is to introduce the basics of using the NX Open C++ API to develop custom CAD applications within the NX environment.

Uploaded by

Luu Duc Hop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1/26/2015

StepbystepNXOpenC++Introduction|CadCamDevelopment

CadCamDevelopment

BezierCurveinDirectx10HLSLGeometryShader(https://cadcammodelling.wordpress.com/2010/06/02/beziercurvein
directx10hlslgeometryshader/)|Home(https://cadcammodelling.wordpress.com)|NANOCADCAMindustryanditsfuture
(https://cadcammodelling.wordpress.com/2010/09/12/nanocadcamindustryanditsfuture/)

StepbystepNXOpenC++Introduction
1. OpenUGSNX6andcheckyouhaveC++journalcodegeneration

(https://cadcammodelling.files.wordpress.com/2010/06/cylinder2.png)
https://cadcammodelling.wordpress.com/2010/06/08/stepbystepnxopencintroduction/

1/6

1/26/2015

StepbystepNXOpenC++Introduction|CadCamDevelopment

Startrecordingjournalandclickontheactionsyouwanttoperform.Thereisacylindercreationinmyexample.

(https://cadcammodelling.files.wordpress.com/2010/06/cylinder1.png)
2. Onceyouhavecompletedstoprecordingjournalandcheckcode.Incaseofcylinderthegeneratedcodeshouldlooklikethis:
Session*theSession=Session::GetSession();
Part*workPart(theSession>Parts()>Work());
Part*displayPart(theSession>Parts()>Display());
//
//Menu:Insert>DesignFeature>Cylinder...
//
workPart>FacetedBodies()>DeleteTemporaryFacesAndEdges();Session::UndoMarkIdmarkId1;
markId1=theSession>SetUndoMark(Session::MarkVisibilityVisible,"Start");Features::Feature
*nullFeatures_Feature(NULL);
Features::CylinderBuilder*cylinderBuilder1;
cylinderBuilder1=workPart>Features()
>CreateCylinderBuilder(nullFeatures_Feature);cylinderBuilder1>BooleanOption()
>SetType(GeometricUtilities::BooleanOperation::BooleanTypeCreate);std::vectortargetBodies1(1);
https://cadcammodelling.wordpress.com/2010/06/08/stepbystepnxopencintroduction/

2/6

1/26/2015

StepbystepNXOpenC++Introduction|CadCamDevelopment

Body*nullBody(NULL);
targetBodies1[0]=nullBody;
cylinderBuilder1>BooleanOption()>SetTargetBodies(targetBodies1);theSession
>SetUndoMarkName(markId1,"CylinderDialog");Session::UndoMarkIdmarkId2;
markId2=theSession>SetUndoMark(Session::MarkVisibilityInvisible,"Start");theSession
>SetUndoMarkName(markId2,"VectorDialog");//
//DialogBeginVector
//
Session::UndoMarkIdmarkId3;
markId3=theSession>SetUndoMark(Session::MarkVisibilityInvisible,"Vector");Point3dorigin1(0.0,
0.0,0.0);
Vector3dvector1(0.0,0.0,1.0);
Direction*direction1;
direction1=workPart>Directions()>CreateDirection(origin1,vector1,
SmartObject::UpdateOptionWithinModeling);theSession>DeleteUndoMark(markId3,NULL);theSession
>SetUndoMarkName(markId2,"Vector");theSession>DeleteUndoMark(markId2,NULL);Axis*axis1;
axis1=cylinderBuilder1>Axis();axis1>SetDirection(direction1);cylinderBuilder1>Diameter()
>SetRightHandSide("50");cylinderBuilder1>Height()>SetRightHandSide("150");Session::UndoMarkId
markId4;
markId4=theSession>SetUndoMark(Session::MarkVisibilityInvisible,"Cylinder");NXObject*nXObject1;
nXObject1=cylinderBuilder1>Commit();
theSession>DeleteUndoMark(markId4,NULL);
theSession>SetUndoMarkName(markId1,"Cylinder");
cylinderBuilder1>Destroy();
workPart>FacetedBodies()>DeleteTemporaryFacesAndEdges();
3. NowopenVisualStudio,andcreateC++Dllprojectwithblanktemplate.
4. Createandadddllmain.cppfiletoyoursourcefiles.Andaddthefollowingfunctionstoit:
UGSDLLTEST_APIintufusr_ask_unload()
{
https://cadcammodelling.wordpress.com/2010/06/08/stepbystepnxopencintroduction/

3/6

1/26/2015

StepbystepNXOpenC++Introduction|CadCamDevelopment

return(int)Session::LibraryUnloadOptionImmediately;
}
UGSDLLTEST_APIvoidufusr(char*param,int*retcod,intparam_len)
{
inti=UF_initialize();
if(i!=0)
MessageBox(NULL,L"initializeerror",L"initerror",MB_OK);UF_terminate();
}whereUGSDLLTEST_API:
#ifdefUGSDLLTEST_EXPORTS
#defineUGSDLLTEST_API__declspec(dllexport)
#else
#defineUGSDLLTEST_API__declspec(dllimport)
#endif
Firstfunctionintufusr_ask_unload()allowstochoosebetweendifferentresourcedeallocationtype.Youcanchoose
betweenLibraryUnloadOptionAtTermination,LibraryUnloadOptionExplicitlyandLibraryUnloadOptionImmediately.Ifyou
dontspecifythisfunctionLibraryUnloadOptionAtTerminationissetbydefault.ThismeansUGSdoesnotreleaseexeordll
fileuntilyoucloseit.IfyouspecifyLibraryUnloadOptionImmediatelyUGSimmediateleyreleasesafterusedll/exefileyouve
beenworkingthroughNXOpeninvocation.ThisishowwewantinNXOpenapplicationdevelopment.
Secondfunctionvoidufusr(char*param,int*retcod,intparam_len)isspecificNXOpenfunctionwhichyouhave
toprovidetohavecustomNXopenapplicationworkinginyourNXenvironment.Itdoesntmatterwhetheryourecreating
dllorexe,thisfunctionisastartpointforanyNXOpenunmanagedapplication.SeemoreforNXOpendocumentationfor
moredetails.
5. Addlibufun.lib,libugopenint.lib,libnxopencpp.libtolinkerpropertiessothatapplicationcouldbelinked.

https://cadcammodelling.wordpress.com/2010/06/08/stepbystepnxopencintroduction/

4/6

1/26/2015

StepbystepNXOpenC++Introduction|CadCamDevelopment

(https://cadcammodelling.files.wordpress.com/2010/06/cylinder3.png)
VSlinkerproperties
6. Nowaddthiscodetoyourufusrfunctionandtestit.A150mmheightcylindershouldappear.Todothisclickfrommenu
file>execute>NxOpen,andensurethataDLLfilefilterissetintheapplicationtype.Ifyoudontseeexecutemenu,change
yourUGStypetoadvancedwithfullmenus
7. Additionalimprovements
Playaraoundwithcodegeneratedbyjournalandfindunnecessarylines.
8. Result

https://cadcammodelling.wordpress.com/2010/06/08/stepbystepnxopencintroduction/

5/6

1/26/2015

StepbystepNXOpenC++Introduction|CadCamDevelopment

(https://cadcammodelling.files.wordpress.com/2010/06/cylinder5.png)

https://cadcammodelling.wordpress.com/2010/06/08/stepbystepnxopencintroduction/

6/6

You might also like