You are on page 1of 10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment
1

Linktkhc Blogtiptheo

luuduchop@gmail.com Bngiukhin ngxut

Begtostudy'sTechnologyBlog
WelcometomyTechnologyBlog!

TRANSLATION

20110111

POSITIONSOFMYVISITORS

ABOUTME

Beck()
Shanghai,
Shanghai,China

MSN/Email:begtostudy@gmail.com,
QQ:370566617,PhDStudentin
ShanghaiJiaotongUnversity.My
Facebook:http://www.facebook.com/
begtostudy
Viewmycompleteprofile

TAGCLOUD

NXDev.(4).net(1)
AddmeasMSNconnect
TalktomebyMSN

OpenAPIsandNXOpenClassLibraryofUG/NXSecondary
Development
(Iamnotnativespeaker,sosorryformyEnglish.Ifyoufindsomemistakes,pleasetellmeinthefollowing
commentsoremailtome:begtostudy@gmail.com)
Therearetwoopenapplicationinterfacesystem,i.e.,OpenAPIsandNXOpenclasslibrary.Open,alsonamed
UFun,isbasedonCLangrageatthestartandlatersupportedC++,whichisgoodatgeometryfunctions.After
purchasedbySiemens(orextendedtoPLMbusiness),UG/NXhaveanotherone,NXOpenclasslibrary.It
concludesalmostthefunctionsofNXsoftwareandisentirelyobjectoriented.HoweverNXdidntgiveupthe
OpenAPIs,withNXOpen.UFnamespace,wecanusethembyencapsulationtechnology.Maybefortheshort
history,NXOpenhavelesshelpdatathanOpen.Andthesamereason,beforeNX6,therearesomanybugsin
NXOpen.WegivesomecomparisonsinTable1.
Table1.Comparisons
Language
C

C++

.net/java

OpenAPI/UFun
procedureoriented
goodatgeometryfunctions,
especiallyefficiency
(OpenC++)
Partlyobjectoriented
PartlysupportNXfunctions
NXOpen.UFnamespaceby
encapsulationtechnology

NXOpen
Notsupport

AlmostsupportNXfunctions
(nativecode)

AlmostsupportNXfunctions
(managedcode)

Inconclusion,ifusingC/C++,youcoulduseOpenCandOpenC++directly,andifusing.net,youprimaryuse
NXOpenandAPIbyNXOpen.UF,i.e.,youcouldusebothsystemsseparately.
Following,Iwouldtakesomeexamplestoillustratetheirdifference.For.net,IonlypickedC#,andothers,e.g.
VB,arethesame.Sorryforjava,Iknowlittleaboutit.

I.OpenC

http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

1/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

Begtostudy

551
6 22

Begtostudy

MYBLOGS

ProgamTechBlog(Chinese)
ProfessionalTechBlog(Chinese)
PersionalBlog(English)

RSS

Posts
Comments

TOTALPAGEVIEWS

13,718

BLOGARCHIVE

2011(6)
March(3)
February(1)
January(2)
OpenAPIsandNXOpenClass
LibraryofUG/NXSecond...
BuildaNXOpen.NET

1.Findeachbodyintheworkpart
#include<uf_object_types.h>
#include<uf_part.h>
#include<uf_obj.h>
#include<uf_modl.h>
#include<string>
#include<sstream>
usingstd::string
usingstd::stringstream
//codesegmentsasfollow
UgSessionsession(true)
try
{
/*TODO:Addyourapplicationcodehere*/
uf_list_p_tlpObj
UF_MODL_create_list(&lpObj)
tag_tprt=UF_PART_ask_display_part()
tag_tNext_tag=NULL_TAG
do
{
UF_OBJ_cycle_objs_in_part(prt,UF_solid_type,&Next_tag)
if(Next_tag==NULL_TAG)break
intt,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)
logicalis_open
UF_UI_is_listing_window_open(&is_open)
if(!is_open)UF_UI_open_listing_window()
intsum
UF_MODL_ask_list_count(lpObj,&sum)
for(inti=0i<sumi++)
{
tag_tt
UF_MODL_ask_list_item(lpObj,i,&t)
stringstreams
s<<(int)t
stringstr
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)

http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

2/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

application

}
/*Handleerrors*/
catch(constUgException&exception)
{
processException(exception)
}
2.Createablock
#include<uf.h>
#include<uf_ui.h>
#include<uf_exit.h>
#include<uf_modl.h>
//codesegmentsasfollow
/*InitializetheAPIenvironment*/
if(UF_CALL(UF_initialize()))
{
/*Failedtoinitialize*/
return
}
/*TODO:Addyourapplicationcodehere*/
doublecorner[3]={0,0,0}
char*edge[3]={"10","5","20"}
tag_ttag
UF_MODL_create_block(UF_NULLSIGN,NULL_TAG,corner,edge,&tag)
/*TerminatetheAPIenvironment*/
UF_CALL(UF_terminate())

II.OpenC++
1.Findeachbodyintheworkpart
#include<ug_typed.hxx>
#include<ug_part.hxx>
#include<ug_body.hxx>
#include<ug_string.hxx>
usingstd::string
//codesegmentsasfollow
UgSessionsession(true)
try
{
/*TODO:Addyourapplicationcodehere*/
UgPart*pWorkPart=UgSession::getWorkPart()
UgTypedObject*pObj
ostrstreambuffer
for(pObj=pWorkPart>iterateFirst()
pObj
pObj=pWorkPart>iterateNext(pObj))
{
std::stringname=pObj>getName()
http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

3/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

UgBody*pBody=dynamic_cast<UgBody*>(pObj)
if(pBody)
{
buffer<<(int)pBody>getTag()<<"\n"
}
}
UgInfoWindow::open()
UgInfoWindow::write(string(buffer.str()))
deletebuffer.str()
}
/*Handleerrors*/
catch(constUgException&exception)
{
processException(exception)
}
2.serching
#include<ug_body.hxx>
#include<ug_iterator.hxx>
#include<ug_string.hxx>
//codesegmentsasfollow
UgSessionsession(true)
try
{
/*TODO:Addyourapplicationcodehere*/
ostrstreambuffer
//ConstructaniteratorforNXfaceobjects
UgIterator<UgBody>pObj//workpart
//UgIterator<UgFace*>curFace
////Loopthroughallfaces
//while(!curFace.isFinished())
//{
////Getthenameofthecurrentface
//std::stringfaceName=(*(*curFace))>getName()
//curFace.findNext()
//}
//Loopthroughallfaces
while(!pObj.isFinished())
{
//Getthenameofthecurrentface
std::stringfaceName=(*pObj)>getName()
buffer<<(int)(*pObj)>getTag()<<endl
pObj.findNext()
}
UgInfoWindow::open()
UgInfoWindow::write(std::string(buffer.str()))
http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

4/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

deletebuffer.str()
}
/*Handleerrors*/
catch(constUgException&exception)
{
processException(exception)
}

III.NXOpenC++
1.Createablock
#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>
usingnamespaceNXOpen
//codesegmentsasfollow
NXOpen::Session*theSession=NXOpen::Session::GetSession()
try
{
/*TODO:Addyourapplicationcodehere*/
Part*thePart=theSession>Parts()>Work()
NXOpen::Features::Feature*block=NULL
NXOpen::Features::BlockFeatureBuilder*theBuilder=thePart>Features()>CreateBlockFeatureBuilder(block)
NXOpen::Point3dbasePoint(100,100,100)
theBuilder>SetOriginAndLengths(basePoint,"100","200","300")
//NXOpen.BodytheBody=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!")
}
/*Handleerrors*/
catch(constUgException&exception)
{
processException(exception)
}
2.FindeachFeatureintheworkpart
#include<NXOpen/Session.hxx>
#include<NXOpen/Part.hxx>
#include<NXOpen/Features_BlockFeatureBuilder.hxx>
http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

5/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

#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>
usingnamespaceNXOpen
//codesegmentsasfollow
NXOpen::Session*theSession=NXOpen::Session::GetSession()
try
{
/*TODO:Addyourapplicationcodehere*/
Part*thePart=theSession>Parts()>Work()
theSession>ListingWindow()>Open()
NXOpen::Features::FeatureCollection::iteratori
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!")
}
/*Handleerrors*/
catch(constUgException&exception)
{
processException(exception)
}

IV.NXOpenC#
1.Createablock
usingNXOpen
usingNXOpen.Utilities
usingNXOpen.UF
usingNXOpenUI
//codesegmentsasfollow
SessiontheSession=Session.GetSession()
try
{
PartthePart=theSession.Parts.Work
NXOpen.Features.Featureblock=null
NXOpen.Features.BlockFeatureBuildertheBuilder=thePart.Features.CreateBlockFeatureBuilder(block)
NXOpen.Point3dbasePoint=newPoint3d(100f,100f,100f)
theBuilder.SetOriginAndLengths(basePoint,"100","200","300")
theBuilder.Commit()
//theBuilder.CommitFeature()
http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

6/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

UI.GetUI().NXMessageBox.Show("",NXMessageBox.DialogType.Information,"OK!")
}
catch(NXExceptionex)
{
UI.GetUI().NXMessageBox.Show("error!",NXMessageBox.DialogType.Error,ex.Message)
}
2.FindeachFeatureintheworkpart
usingNXOpen
usingNXOpen.Utilities
usingNXOpen.UF
usingNXOpenUI
//codesegmentsasfollow
SessiontheSession=Session.GetSession()
theSession.ListingWindow.Open()
try
{
PartthePart=theSession.Parts.Work
foreach(NXOpen.Features.FeaturecinthePart.Features)
{
//NXOpen.Features.Blockt=casNXOpen.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(NXExceptionex)
{
UI.GetUI().NXMessageBox.Show("error!",NXMessageBox.DialogType.Error,ex.Message)
}

V.NXOpen.UF
1.analogyofCaseI.1forOpenC
usingNXOpen
usingNXOpen.Utilities
usingNXOpen.UF
usingNXOpenUI
NXOpen.UF.UFSessiontheUFSession=NXOpen.UF.UFSession.GetUFSession()
try
{
double[]corner={0,0,0}
string[]edge={"10","5","20"}
Tagtag
theUFSession.Modl.CreateBlock1(FeatureSigns.Nullsign,corner,edge,outtag)
http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

7/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

}
catch(NXExceptionex)
{
UI.GetUI().NXMessageBox.Show("error!",NXMessageBox.DialogType.Error,ex.Message)
}
1.analogyofCaseI.1forOpenC
usingNXOpen
usingNXOpen.Utilities
usingNXOpen.UF
usingNXOpenUI
NXOpen.UF.UFSessiontheUFSession=NXOpen.UF.UFSession.GetUFSession()
try
{
Tag[]list=null
TagthePart=theUFSession.Part.AskDisplayPart()
theUFSession.Modl.CreateList(outlist)
TagNext_tag=Tag.Null
do
{
theUFSession.Obj.CycleObjsInPart(thePart,70/*UF_solid_type*/,refNext_tag)
if(Next_tag==Tag.Null)break
intt,subType
theUFSession.Obj.AskTypeAndSubtype(Next_tag,outt,outsubType)
if(subType==0/*UF_solid_body_subtype*/)
theUFSession.Modl.PutListItem(list,Next_tag)
}while(true)
boolisOpen
theUFSession.Ui.IsListingWindowOpen(outisOpen)
if(!isOpen)theUFSession.Ui.OpenListingWindow()
intsum
theUFSession.Modl.AskListCount(list,outsum)
for(inti=0i<sumi++)
{
Tagt
theUFSession.Modl.AskListItem(list,i,outt)
theUFSession.Ui.WriteListingWindow(t.ToString())
}
/*Treatalltheargumentswiththe"Outputtobefreed"annotationasanoutputparameter.
*Thesystemtakescareoffreeingmemory.*/
}
catch(NXExceptionex)
{
UI.GetUI().NXMessageBox.Show("error!",NXMessageBox.DialogType.Error,ex.Message)
}
http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

8/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment
Beck()03:24

+1 Recommend this on Google

NXDev.

Nocomments:
PostaComment
Enteryourcomment...

Commentas:

Publish

hopdtvt(Google)

Signout

Notifyme

Preview

CreateaLink
NewerPost

Home

OlderPost

Subscribeto:PostComments(Atom)

VISITORS

http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

9/10

1/26/2015

Begtostudy'sTechnologyBlog:OpenAPIsandNXOpenClassLibraryofUG/NXSecondaryDevelopment

Allcopyright.PoweredbyBlogger.

http://begtostudytech.blogspot.com/2011/01/openapisandnxopenclasslibraryof.html

10/10