Vous êtes sur la page 1sur 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

Vous aimerez peut-être aussi