cancel
Showing results for 
Search instead for 
Did you mean: 

sheet and sheet views of DRW file in NX using C++

Pioneer
Pioneer

Hello,

I've opened a drwaing file in NX , and want to get the no. of sheets with their respective views in opened drawing file, but cannot find the relevant solution as it displays the views of only first sheet and for displaying the views of second sheet the code gets crashed! Can you provide with a suitable solution for this?

The drawing file contains 2 sheets and respective views.My code snippet is given below:

int _tmain(int argc, _TCHAR* argv[])
{
theSession = NXOpen::Session::GetSession();
int sheetcnt=0;
if(theSession != NULL)
{
NXOpen::BasePart *basePart1;
NXOpen::PartLoadStatus *partLoadStatus1;
basePart1 = theSession->Parts()->OpenBaseDisplay("D:\DRW files\\DrawingCycle_sheets.prt", &partLoadStatus1);

NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());
NXString nxspartname = displayPart->FullPath() ;
const char * name = nxspartname.GetText();
MessageBox (NULL,name,"Part name",MB_OK );

Drawings::DrawingSheetCollection *drawingsheets = displayPart->DrawingSheets();
Drawings::DrawingSheetCollection::iterator it;
Drawings::DrawingSheet *mysheet;

for(it=drawingsheets->begin();it!=drawingsheets->end();it++)
{
mysheet = *it;
mysheet ->Open();
NXString sheetname = mysheet->Name();
MessageBox (NULL,sheetname.GetText(),"Sheet name",MB_OK );
sheetcnt++;



// ----------------------------------------------
// Printing Drafting views
// ----------------------------------------------
std::vector<NXOpen::Drawings::DraftingView *> dfviews = mysheet->GetDraftingViews();
int sheetviewcount=dfviews.size();

cout<<"no. of views in a sheet: "<< sheetviewcount<<"\n";
NXOpen::NXString sheet_name = "Printing Sheet: " + mysheet->Name();
std::vector<NXOpen::NXString >sheet_names(1);
//Collecting View names and copying to String
for(int i=0;i!=dfviews.size();i++)
{
if(i==0)
{
sheet_names[0] = "Sheet contains following views: \n" + dfviews[i]->Name();

}
else
{
sheet_names[0] = sheet_names[0] +"\n"+ dfviews[i]->Name();

}
}
MessageBox(NULL,sheet_names[0].GetText(),"Drafting views",MB_OK);
}
cout <<"no.of sheets: "<< sheetcnt<<"\n"; 
}
else
{
MessageBox (NULL,"","No SESSION",MB_OK );
}
return 0;
}

For code line :

std::vector<NXOpen::Drawings::DraftingView *> dfviews = mysheet->GetDraftingViews();

it fails!

 

Your help is appreciated!

 

Thanks,

Juhi

 

5 REPLIES

Re: sheet and sheet views of DRW file in NX using C++

Siemens Phenom Siemens Phenom
Siemens Phenom

There is an example program on the GTAC Solution Center, called

 

"report_all_drawing_sheets_and_member_views.cpp" that looks like it would be a good start for what you are trying to do.  It is written to be built as a .DLL, but you should be able to transfer the working bits of the code to your external project.  I built it and ran it against your part as a .DLL, and it reported these sheets and views:


Sheet Name: SH1
   TOP@1
   ORTHO@2
   ORTHO@3
 TFR-TRI@4

 

Sheet Name: SH2
   RIGHT@8
   SX@9
   DETAIL@11
   SX@16

 

This link might work:

 

https://solutions.industrysoftware.automation.siemens.com/view.php?sort=desc&q=report+all+drawing+sh...

 

If not, go to the Solution Center and search for "nx_api4591".

 

I hope this helps!

 

Re: sheet and sheet views of DRW file in NX using C++

Pioneer
Pioneer
Hello Steve, we have tried your suggested code but no luck it's getting crashed in a next iteration loop. We have a drawing file for 3 sheets. Code reads the all views of 1st drawing sheet but get crashed for 2nd drawing sheet iteration. Here is the screen shot of same please help me out asap.

Re: sheet and sheet views of DRW file in NX using C++

Pioneer
Pioneer

Hello Steve, we have tried your suggested code but no luck it's getting crashed in a next iteration loop. We have a drawing file for 3 sheets. Code reads the all views of 1st drawing sheet but get crashed for 2nd drawing sheet iteration. Here is the screen shot of same please help me out asap.

Re: sheet and sheet views of DRW file in NX using C++

Siemens Phenom Siemens Phenom
Siemens Phenom

What version of NX are you running?

 

The error shows that you had a problem in a runtime file from the 2010 version of the Visual Studio, which is compatible with NX 8 and NX8.5.

 

For NX9 or NX10, you will need to build your automation routines with the 2012 version of the Studio, with SP1.

Re: sheet and sheet views of DRW file in NX using C++

Siemens Phenom Siemens Phenom
Siemens Phenom

I just looked at your error image again, and realized that you are probably running NX7.5.  If that is the case, then the version of the Studio that you need is 2008, also known as V9.

 

I also noticed that the .DLL that is reported to be failing is a debug .dll.  Please try building your project in Release mode.  If you must build in debug mode, do not use the /MDd switch.