Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte limbi doc
AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml


Fisiere script si AutoLISP

autocad



+ Font mai mare | - Font mai mic



Fisiere script si AutoLISP

Daca vreti sa folositi un program AutoLISP pentru a procesa citeva desene in editor, pe rind, probabil veti combina un program AutoLISP cu un fisier script pentru o procesare automata.

AutoLISP se initializeaza la fiecare noua sesiune de editare, adica ori de cite ori incepeti un nou desen sau editati unul deja existent. Initializarea elibereaza zona de memorie destinata AutoLISP-ului stergind toate functiile definite de utilizator si de aplicatii, si variabilele din proces.



Sa presupunem ca avem o functie AutoLISP definita dupa cum urmeaza. Ce se intimpla cind aceasta functie este in actiune?

Command: (defun c:my_new () (command '._new' ''))
C:MY_NEW

Command: my_new
Command: ._new File name:

Command: !c:my_new
nil

C:MY_NEW apeleaza comanda AutoCAD NEW si incepe un nou desen. Dupa ce editorul grafic a fost initializat, verificam setarea funtiei C:MY_NEW si vedem ca este nil. Acest lucru se datoreaza faptului ca AutoLISP este intotdeauna initializat impreuna cu editorul grafic.

Cu alte cuvinte, orice functie AutoLISP care recicleaza editorul grafic se autodistruge.

Pentru a rezolva aceasta problema, puteti folosi fisiere script in combinatie cu programe AutoLISP pentru a procesa mai multe desene cu acelasi cod AutoLISP. Fisierul script reincarca si apeleaza programul AutoLISP la fiecare nou desen. Codul AutoLISP scrie fisierul script, defineste functia pentru a fi apelata din fisierul script si apeleaza fisierul script.

Iata un exemplu tipic.

Dorim sa procesam toate fisierele grafice din directorul student/batchdwg cu un program AutoLISP care tipareste un raport ce cuprinde numarul de Block Definitions din desen si numele lor. (Acest exercitiu presupune ca un astfel de director cu fisiere grafice exista deja in computer.)

Fisierul program run.lsp defineste doua functii AutoLISP: C:RUN si C:RUN_REPORT.

C:RUN executa urmatoarele activitati in ordine.

Va asigura ca aplicatia ADS XDOS este incarcata.

Cere un nume de director de la utilizator.

Cere o lista cu toate fisierele grafice din director.

Scrie un fisier script care deschide fiecare desen, reincarca run.lsp si apeleaza functia C:RUN_REPORT pentru fiecare desen.

Apeleaza fisierul script.

Functia C:RUN_REPORT scrie un fisier raport pentru fiecare desen care contine Block Definitions. Fisierul raport are acelasi nume ca si desenul cu o extensie .rpt si se afla in acelasi director ca si desenul. Functia listeaza numele fiecarui Block in desen si de cite ori Block a fost inserat.

c:run foloseste functia dosdir din fisierul xdos.exe, o aplicatie ADS real mode pentru ACAD R12 care se afla in CompuServe ACAD Forum in Library 2. xdos este in directorul student din computerul dvs. Instructiunile de folosire a acestei functii se afla in fisierul xdos.txt.

intr-un desen nou, folositi comanda definita in run.lsp. Urmati instructiunile de mai jos.

Command: (load 'run')
C:RUN_REPORT

Command: run

Dupa ce ultimul desen a fost procesat, examinati continutul urmatoarelor trei fisiere:

d:astudentarun.scr

d:astudentabatchdwgablock5.rpt

d:astudentabatchdwgablock10.rpt

(defun C:RUN ()

(if

(not (member 'DOSDIR' (atoms-family 1))) ;Check for dosdir function.

(if ;If not there, attempt to

(= 'bad' (xload 'XDOS.EXE' 'bad')) ;load XDOS program; exit

(progn ;if attempt fails.

(prompt 'anCan't load XDOS.EXE.')

(exit)

)

)

)

(setq dwgdir (getstring 'anDirectory: ')) ;Get directory from user.

(setq dwgnames ;Get list of drawings.

(dosdir (strcat dwgdir 'aa' '*.dwg') 0)

)

(setq fp (open 'run.scr' 'w')) ;Open file run.scr for

;writing in current dir.

;The script commands will open each drawing in turn, load the

;file run.lsp and apply the run_report command to each file.

(foreach a dwgnames ;Write script file.

(progn

(princ '(if (= 0 (getvar a'DBMODa')) (command a'._OPENa')' fp)

(princ '(command a'._OPENa' a'Na'))an' fp)

(princ (strcat dwgdir 'aa' a 'an') fp)

(princ '(load a'run.lspa')an' fp)

(princ 'run_reportan' fp)

)

)

(setq fp (close fp)) ;Close run.scr file.

(command '._SCRIPT' 'run') ;Call script as last

; expression.

(defun C:RUN_REPORT ()

(setq block_name_list nil) ;Initialize list of Block names.

(if

(setq block_table_list (tblnext 'BLOCK' t)) ;We have a Block?

(progn

(prompt 'anFinding Block names.') ;Keep the customer happy.

(while ;Add its name to the list and

block_table_list ;get the next one.

(setq block_name (cdr (assoc 2 block_table_list)))

(setq block_name_list (cons block_name block_name_list))

(setq block_table_list (tblnext 'BLOCK'))

)

;Sort the list of Block names.

(setq block_name_list (acad_strlsort block_name_list))

;Get the number of Insert entities for each Block.

;Create a list of dotted pairs. Each dotted pair consists

;of a Block name and the number of Insert entities.

(prompt 'anFinding INSERT entities.') ;Keep the customer happy.

(setq report_list nil count 0) ;Initialize the list and counter.

(repeat ;For all the Block names

(length block_name_list) ;find how many INSERT entities.

(setq block_name (nth count block_name_list))

(setq s_set ;Returns selection-set of all

(ssget 'X' ;the INSERT entities of the

(list ;current block_name.

(cons 0 'INSERT')

(cons 2 block_name)

)

)

)

(setq ;Add a dotted pair of the form

report_list ;('BLOCK_NAME' . 'NUMBER') to

(cons ;the report_list.

(cons

block_name

(if ;If, for example, the Block 'DOOR'

s_set ;is not inserted in this drawing,

(itoa (sslength s_set)) ;add the dotted pair ('DOOR' . '0').

)

)

report_list

)

)

(setq count (1+ count)) ;Next Block name.

(princ '.') ;Keep the customer happy.

)

(setq report_list (reverse report_list)) ;Reverse report list.

(setq s_set nil) ;Free selection-set.

;Print report to disk file dwgname.rpt.

(prompt 'anWriting report to disk.')

(setq fp (open (strcat (getvar 'DWGNAME') '.rpt') 'w'))

(write-line (strcat 'Drawing ' (getvar 'DWGNAME') 'an') fp)

(write-line 'Block names # of insertions' fp)

(write-line '=========== ===============' fp)

(setq count 0) ;First Block name.

(repeat

(length report_list) ;Get 'em all

(setq block_name

(car (nth count report_list))

insert_number

(cdr (nth count report_list))

)

(setq spacer '') ;Calculate number of spaces to 36th

(repeat ;character from end of Block name.

(- 36 (strlen block_name))

(setq spacer (strcat ' ' spacer))

)

(write-line ;Write Block name, spaces to the

(strcat ;36th character, and the number of

block_name ;INSERT entities for that Block.

spacer

insert_number

)

fp

)

(setq count (1+ count)) ;Next block name.

)

(setq fp (close fp)) ;Close dwgname.rpt file.

)

)

(prin1) ;Quiet exit.



Politica de confidentialitate | Termeni si conditii de utilizare



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 1309
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved