Bom List

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

(defun c:bomlist(/ sel ss ff i ii n method)

(scmd 0)
;- ????????acad_bom_list.exe???(check .exe later used if exists)
(if (null (findfile "c:/cpc_pdm/Acad_bom_list.exe"))
(progn
(alert "c:/cpc_pdm/Acad_bom_list.exe???,????\n\n???PDM???????,???????")
(exit) ;??????(program exists)
))
;----------------------------
(initget 2 "s")
(setq sel (getkword "\n?????(??BLOCK),?Enter?????: "))
(if (null sel)
(progn
(if (null (setq ss (entss (ssget "x") "insert")));????????(seeking all blo
cks in dwg)
(progn
(alert "! ???????(??BLOCK) !")
(exit)
))
(setq method 1) ;????????,??method=1????(cause seeking balloons exist,so set
method=1)
)
(progn ;???????(user selecting balloons)
(while (null (setq ss (ssget))))
(setq ss (entss ss "insert")
method 2 ;?method=2 ????(set method=2)
)
))
(if (null (findfile "c:/temp_pdm")) ;???????????(creating fold ready for locat
ing txt file)
(acet-file-mkdir "c:/temp_pdm")
)
(setq ff (open "c:/temp_pdm/bomlist.txt" "w"));?????(creating txt file)
(setq i 0
n (sslength ss)
m 0
)
(write-line (strcat (getdwgname) ".dwg BOM???????") ff)
(repeat n ;??????????txt?(gethering balloons' attributes into txt file)
(setq m (1+ m))
(setq i (1+ i))
(if (= method 1)
(setq blkent (ssname ss (- n i))) ;????? case method=1
(setq blkent (ssname ss (1- i))) ;????? case method=2
)
(if (= (strcase (ent_code 2 (entget blkent))) "BAL");??????? (identifying if
balloon)
(progn ;??????????ii(getting balloon's attributes set to ii)
(setq ii (strcat (getattvalue blkent "??")
" "
(getattvalue blkent "????")
" "
(getattvalue blkent "??")
)
)
(write-line ii ff) ;?ii???????(writing ii into txt file)
)))
(close ff) ;????????(saving and closing txt file)
(if (> m 0)
(startapp "c:/cpc_pdm/acad_bom_list.exe C:/temp_pdm/bomlist.txt") ; ??exe??(
???)(to start c:/cpc_pdm/acad_bom_list.exe with a parameter:bomlist.txt)
(alert "! ???????(??BLOCK) !")
)
(princ)
)
???acad_bom_list.exe?CPP???????FormActivate???
.cpp
#include "fstream.h"
#pragma link "CGAUGES"
void __fastcall TForm_BOMList::FormActivate(TObject *Sender)
{ //????????????????,????????????(activating program,accepting parameter, if t
here isn't parameter with in,program will terminate and close)
String txt=ParamStr(1);
if(!FileExists(txt)) {
ShowMessage("! ????,??????[ "+txt+" ] !");
exit(0);
}
else {
Label2->Caption=tlt;
//- ??StringGrid??(adjusting StringGrid's format)
StringGrid1->RowCount=2;
StringGrid1->ColCount=6;
StringGrid1->FixedRows=1;
StringGrid1->ColWidths[0]=30;
StringGrid1->ColWidths[1]=80;
StringGrid1->ColWidths[2]=140;
StringGrid1->ColWidths[3]=140;
StringGrid1->ColWidths[4]=200;
StringGrid1->ColWidths[5]=40;
StringGrid1->Cells[0][0]="??";
StringGrid1->Cells[1][0]="??";
StringGrid1->Cells[2][0]="????";
StringGrid1->Cells[3][0]="????";
StringGrid1->Cells[4][0]="??";
StringGrid1->Cells[5][0]="??";
//---------------------
char buff[65535];
String temp;
ifstream infile;
infile.open(txt.c_str());//??txt?(open txt file)
if (!infile) return ;
//-- ??? --
infile.getline(buff,sizeof(buff));
Label1->Caption=buff;
//------------
while (!infile.eof()) { //??txt??????(reading data in txt file)
infile.getline(buff,sizeof(buff));
temp = buff;
if (Trim(temp)=="") continue;
DynamicArray < String > ar1;
ar1=divide_str(temp," ");
String pno=ar1[1].Trim().UpperCase();
StringGrid1->RowCount++;
StringGrid1->Cells[0][StringGrid1->RowCount-2]=ar1[0];
StringGrid1->Cells[1][StringGrid1->RowCount-2]=pno;
String cc=get_pno_a_field_string(PDM,pno,"emtr_cname"); //?????????????(ge
tting part's Chinese name from database)
if(cc!="")
StringGrid1->Cells[2][StringGrid1->RowCount-2]=cc;
else { //????,????(part not exists,jump to next one)
StringGrid1->Cells[2][StringGrid1->RowCount-2]=" (????)";
continue;
}
StringGrid1->Cells[3][StringGrid1->RowCount-2]=get_pno_a_field_string(PDM,
pno,"emtr_ename"); //?????????????(getting part's Englist name from database)
StringGrid1->Cells[4][StringGrid1->RowCount-2]=get_pno_a_field_string(PDM,
pno,"spec"); //???????????(getting data's spec data from database)
StringGrid1->Cells[5][StringGrid1->RowCount-2]=ar1[2];
}
StringGrid1->RowCount--;
infile.close(); //??txt?(close txt file)
}
}
???acad_bom_list.exe?CPP???Excel????
void __fastcall TForm_BOMList::BitBtn1Click(TObject *Sender)
{
stg2xls(StringGrid1,Label1->Caption,"",Form_BOMList); //stg2xls????????,?Strin
gGrid?????Excel (stg2xls is a function designed by myself,exporting StringGrid's
data to Excel)
}

You might also like