exportar dados

exportar dados

alexandre_benekowski
Advocate Advocate
1,481 Views
12 Replies
Message 1 of 13

exportar dados

alexandre_benekowski
Advocate
Advocate

Olá Pessoal,

 

Fiz uma lisp que insere blocos atributados na tela. Gostaria que no final eu tivesse a possibilidade de exportar os dados para ".txt" ou ".xls" pela lisp (por meio de solicitação do usuário).

 

Como faço para inserir o dataextraction na lisp? ou melhor é possível fazer por dataextraction ou tem outra forma? porque testei e não consegui (exemplo):

 

(command "dataextraction" ...........)

 

 

0 Likes
1,482 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant

Create a template first (*.dxe file) - no other way is using command line possible. The something like this

 

(command "_.-dataextraction" "c:\\Users\\Beekee\\Desktop\\test.dxe") ; Notice a double backslash.

(if (> (getvar 'cmdactive) 0) (command "_y")) ; This is for YES, I want to overwrite exported file - if exists the file from previous extraction.

 

0 Likes
Message 3 of 13

alexandre_benekowski
Advocate
Advocate

hello BeekeeCZ,

 

First of all, Thank you very much, I almost arrive there.

 

this solution just work if I've alread made a dataextraction before. I would like one the that make a dataextaction (for example) for the first time without had made a dataextraction in command line.

 

 

Thank you very much.

 

0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

 

 

Ok, if the template was made before, your have a choice to use the template. If you're making DE manually, see the command line - hint for where to save a template.

 

(defun c:test ( / dxefilepath flag)

  (setq dxefilepath "c:\\Users\\User\\Desktop\\_Download\\Test\\Test.dxe")
 
  (cond ((not (setq flag (progn
                           (initget "Manually Template")
                           (getkword (strcat "\nDataextraction? [Manually" (if (findfile dxefilepath) "/Template" "") "] <no extraction>: "))))))

        ((= flag "Manually")
         (prompt (strcat "\nPath for save: " dxefilepath))
         (command "_.DATAEXTRACTION"))

        ((= flag "Template")
         (command "_.-DATAEXTRACTION" dxefilepath)
         (if (> (getvar 'cmdactive) 0) (command "_y"))))

  (princ)
)

 

The filepath could be depending on current file name: (getvar 'dwgprefix)

So then e.g. (setq dxefilepath (strcat (getvar 'dwgprefix) "Test.dxe"))

 

Message 5 of 13

alexandre_benekowski
Advocate
Advocate

HELLO BeekeeCZ,

 

Thanks for the attention,

 

It work very well, I wil use that in my lisp.

 

just a last question:

 

is not possible to make a ".dxe" that can be used for every draw and have a fast command that export directly by a previus model of ".dxe"? if no, that´s ok, the code you passed me is very well.

 

Thank you very much!!!!!.

 

0 Likes
Message 6 of 13

ВeekeeCZ
Consultant
Consultant

@alexandre_benekowski wrote:

 

...

 

just a last question:

is not possible to make a ".dxe" that can be used for every draw and have a fast command that export directly by a previus model of ".dxe"?.... 


I don't know what data you want to get it from.

 

But generally I would say why would not be this possible? I think that's the reason for .dxe templates anyways.

0 Likes
Message 7 of 13

alexandre_benekowski
Advocate
Advocate

Hi BeekeeCZ

 

I fond a routine written by LeeMac, that in the final of routine open a ".txt" I will try the samething too.

 

If you have a comment that could be helpful for me, please say 

 

Thank you very much!!!!

 

the routine:

 

;;---------------------=={ Polyline Information }==---------------------;;
;; ;;
;; This program provides the user with detailed information about ;;
;; every segment of a selected polyline in the form of either an ;;
;; AutoCAD Table (if available), Text file, or CSV file. ;;
;; ;;
;; Upon calling the program with the command syntax 'polyinfo' at the ;;
;; AutoCAD command-line, the user is prompted to select an LWPolyline ;;
;; to be queried from the active drawing. At this prompt the user ;;
;; also has the option to choose the form of output for the ;;
;; information harvested by the program; this output format will be ;;
;; remembered between drawing sessions to enable streamlined repeated ;;
;; program usage. ;;
;; ;;
;; The program will output LWPolyline segment data to either an ;;
;; AutoCAD Table Object created in the active drawing (if such object ;;
;; is available in the version of AutoCAD in which the program is ;;
;; being executed), or a tab-delimited Text file or CSV file ;;
;; automatically created (streamlining the program to minimise ;;
;; prompts) in the working directory of the active drawing. ;;
;; ;;
;; For every segment of the selected LWPolyline, the program will ;;
;; extract the following information: ;;
;; ;;
;; • Segment Number ;;
;; • Segment Start Vertex Coordinate ;;
;; • Segment End Vertex Coordinate ;;
;; • Segment Start Width ;;
;; • Segment End Width ;;
;; • Segment Length ;;
;; • Arc Centre (if arc segment) ;;
;; • Arc Radius (if arc segment) ;;
;; ;;
;;----------------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2014 - www.lee-mac.com ;;
;;----------------------------------------------------------------------;;
;; Version 1.0 - 2012-07-10 ;;
;; ;;
;; - First release. ;;
;;----------------------------------------------------------------------;;
;; Version 1.1 - 2012-07-16 ;;
;; ;;
;; - Added Table & Text file output options. ;;
;; - Removed basic LWPolyline properties. ;;
;;----------------------------------------------------------------------;;
;; Version 1.2 - 2014-06-14 ;;
;; ;;
;; - Fixed bug causing final segment to be omitted from output data ;;
;; when processing closed polylines. ;;
;;----------------------------------------------------------------------;;
;; Version 1.3 - 2015-04-13 ;;
;; ;;
;; - Fixed bug causing the program to crash when processing polylines ;;
;; containing arc segments. ;;
;;----------------------------------------------------------------------;;

(defun c:polyinfo ( / *error* ent enx flg ins lst out seg tmp )

(defun *error* ( msg )
(LM:endundo (LM:acdoc))
(if (= 'str (type out)) (setenv "LMac\\PolyInfo" out))
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)

(if (null (setq out (getenv "LMac\\PolyInfo")))
(setq out "TXT")
)
(princ
(strcat "\nOutput Format: "
(cond
( (= out "TXT") "Text File")
( (= out "CSV") "CSV File")
( "AutoCAD Table" )
)
)
)

(while
(progn
(setvar 'errno 0)
(initget "Output")
(setq ent (entsel "\nSelect polyline [Output]: "))
(cond
( (= 7 (getvar 'errno))
(princ "\nMissed, try again.")
)
( (null ent)
nil
)
( (= "Output" ent)
(polyinfo:chooseoutput 'out)
(setenv "LMac\\PolyInfo" out)
(princ
(strcat "\nOutput Format: "
(cond
( (= out "TXT") "Text File")
( (= out "CSV") "CSV File")
( "AutoCAD Table" )
)
)
)
)
( (/= "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent))))))
(princ "\nSelected object is not an LWPolyline.")
)
)
)
)
(cond
( (and
(= 'ename (type ent))
(= "Table" out)
(= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" (getvar 'clayer))))))
)
(princ "\nCurrent layer locked.")
)
( (= 'ename (type ent))
(setq seg 0
enx (entget ent)
lst (LM:lwvertices enx)
lst
(cons
(append '("SEG." "START X" "START Y" "END X" "END Y" "WIDTH 1" "WIDTH 2" "LENGTH")
(if (setq flg (vl-some '(lambda ( x ) (not (zerop (cdr (assoc 42 x))))) lst))
'("CENTRE X" "CENTRE Y" "RADIUS")
)
)
(mapcar
(function
(lambda ( l1 l2 / b p q )
(setq p (cdr (assoc 10 l1))
q (cdr (assoc 10 l2))
b (cdr (assoc 42 l1))
)
(append
(list (itoa (setq seg (1+ seg))))
(mapcar 'rtos p)
(mapcar 'rtos q)
(list
(rtos (cdr (assoc 40 l1)))
(rtos (cdr (assoc 41 l1)))
)
(if (zerop b)
(cons (rtos (distance p q)) (if flg '("" "" "")))
(append
(list (rtos (abs (* (LM:bulgeradius p q b) (atan b) 4))))
(mapcar 'rtos (LM:bulgecentre p q b))
(list (rtos (LM:bulgeradius p q b)))
)
)
)
)
)
lst
(if (= 1 (logand 1 (cdr (assoc 70 enx))))
(append (cdr lst) (list (car lst)))
(cdr lst)
)
)
)
)
(cond
( (= out "TXT")
(if (LM:writetxt lst (setq tmp (vl-filename-mktemp (cdr (assoc 5 enx)) (getvar 'dwgprefix) ".txt")))
(startapp "explorer" tmp)
)
)
( (= out "CSV")
(if (LM:writecsv lst (setq tmp (vl-filename-mktemp (cdr (assoc 5 enx)) (getvar 'dwgprefix) ".csv")))
(startapp "explorer" tmp)
)
)
( (setq ins (getpoint "\nSpecify point for table: "))
(LM:startundo (LM:acdoc))
(LM:addtable (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)) (trans ins 1 0) nil lst nil)
(LM:endundo (LM:acdoc))
)
)
)
)
(princ)
)

;; Add Table - Lee Mac
;; Generates a table at the given point, populated with the given data and optional title.
;; spc - [vla] VLA Block object
;; ins - [lst] WCS insertion point for table
;; ttl - [str] [Optional] Table title
;; lst - [lst] Matrix list of table cell data
;; eqc - [bol] If T, columns are of equal width
;; Returns: [vla] VLA Table Object

(defun LM:addtable ( spc ins ttl lst eqc / dif hgt i j obj stn sty wid )
(setq sty
(vlax-ename->vla-object
(cdr
(assoc -1
(dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "acad_tablestyle")))
(getvar 'ctablestyle)
)
)
)
)
)
(setq hgt (vla-gettextheight sty acdatarow))
(if (LM:annotative-p (setq stn (vla-gettextstyle sty acdatarow)))
(setq hgt (/ hgt (cond ((getvar 'cannoscalevalue)) (1.0))))
)
(setq wid
(mapcar
'(lambda ( col )
(apply 'max
(mapcar
'(lambda ( str )
( (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
(textbox
(list
(cons 01 str)
(cons 40 hgt)
(cons 07 stn)
)
)
)
)
col
)
)
)
(apply 'mapcar (cons 'list lst))
)
)
(if
(and ttl
(< 0.0
(setq dif
(/
(-
( (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
(textbox
(list
(cons 01 ttl)
(cons 40 hgt)
(cons 07 stn)
)
)
)
(apply '+ wid)
)
(length wid)
)
)
)
)
(setq wid (mapcar '(lambda ( x ) (+ x dif)) wid))
)
(setq obj
(vla-addtable spc
(vlax-3D-point ins)
(1+ (length lst))
(length (car lst))
(* 2.0 hgt)
(if eqc
(apply 'max wid)
(/ (apply '+ wid) (float (length (car lst))))
)
)
)
(vla-put-regeneratetablesuppressed obj :vlax-true)
(vla-put-stylename obj (getvar 'ctablestyle))
(setq i -1)
(if (null eqc)
(foreach col wid
(vla-setcolumnwidth obj (setq i (1+ i)) col)
)
)
(if ttl
(progn
(vla-settext obj 0 0 ttl)
(setq i 1)
)
(progn
(vla-deleterows obj 0 1)
(setq i 0)
)
)
(foreach row lst
(setq j 0)
(foreach val row
(vla-settext obj i j val)
(setq j (1+ j))
)
(setq i (1+ i))
)
(vla-put-regeneratetablesuppressed obj :vlax-false)
obj
)

;; Write CSV - Lee Mac
;; Writes a matrix list of cell values to a CSV file.
;; lst - [lst] list of lists, sublist is row of cell values
;; csv - [str] filename of CSV file to write
;; Returns T if successful, else nil

(defun LM:writecsv ( lst csv / des sep )
(if (setq des (open csv "w"))
(progn
(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
(foreach row lst (write-line (LM:lst->csv row sep) des))
(close des)
t
)
)
)

;; List -> CSV - Lee Mac
;; Concatenates a row of cell values to be written to a CSV file.
;; lst - [lst] list containing row of CSV cell values
;; sep - [str] CSV separator token

(defun LM:lst->csv ( lst sep )
(if (cdr lst)
(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
(LM:csv-addquotes (car lst) sep)
)
)

(defun LM:csv-addquotes ( str sep / pos )
(cond
( (wcmatch str (strcat "*[`" sep "\"]*"))
(setq pos 0)
(while (setq pos (vl-string-position 34 str pos))
(setq str (vl-string-subst "\"\"" "\"" str pos)
pos (+ pos 2)
)
)
(strcat "\"" str "\"")
)
( str )
)
)

;; Write Text File - Lee Mac
;; Writes a matrix of values to a tab-delimited Text file.
;; lst - [lst] list of lists, sublist is line of text values
;; txt - [str] filename of Text file to write
;; Returns T if successful, else nil

(defun LM:writetxt ( lst txt / des )
(if (setq des (open txt "w"))
(progn
(foreach itm lst (write-line (LM:lst->str itm "\t") des))
(close des)
t
)
)
)

;; List to String - Lee Mac
;; Concatenates each string in a supplied list, separated by a given delimiter
;; lst - [lst] List of strings to concatenate
;; del - [str] Delimiter string to separate each item

(defun LM:lst->str ( lst del )
(if (cdr lst)
(strcat (car lst) del (LM:lst->str (cdr lst) del))
(car lst)
)
)

;; Annotative-p - Lee Mac
;; Predicate function to determine whether a Text Style is annotative.
;; sty - [str] Name of Text Style

(defun LM:annotative-p ( sty )
(and (setq sty (tblobjname "style" sty))
(setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
(= 1 (cdr (assoc 1070 (reverse sty))))
)
)

;; LW Vertices - Lee Mac
;; Returns a list of lists in which each sublist describes
;; the position, starting width, ending width and bulge of the
;; vertex of a supplied LWPolyline

(defun LM:lwvertices ( e )
(if (setq e (member (assoc 10 e) e))
(cons
(list
(assoc 10 e)
(assoc 40 e)
(assoc 41 e)
(assoc 42 e)
)
(LM:lwvertices (cdr e))
)
)
)

;; Bulge Radius - Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b - bulge
;; Returns the radius of the arc described by the given bulge and vertices

(defun LM:bulgeradius ( p1 p2 b )
(/ (* (distance p1 p2) (1+ (* b b))) 4 (abs b))
)

;; Bulge Centre - Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b - bulge
;; Returns the centre of the arc described by the given bulge and vertices

(defun LM:bulgecentre ( p1 p2 b )
(polar p1
(+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b))))
(/ (* (distance p1 p2) (1+ (* b b))) 4 b)
)
)

;; Start Undo - Lee Mac
;; Opens an Undo Group.

(defun LM:startundo ( doc )
(LM:endundo doc)
(vla-startundomark doc)
)

;; End Undo - Lee Mac
;; Closes an Undo Group.

(defun LM:endundo ( doc )
(while (= 8 (logand 8 (getvar 'undoctl)))
(vla-endundomark doc)
)
)

;; Active Document - Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
(eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
(LM:acdoc)
)

(vl-load-com)
(eval
(append
(list 'defun 'polyinfo:chooseoutput '( sym ))
(if (vlax-method-applicable-p (vla-get-modelspace (LM:acdoc)) 'addtable)
(list
'(initget "Table TXT CSV")
'(set sym (cond ((getkword (strcat "\nChoose Output [Table/TXT/CSV] <" (eval sym) ">: "))) ((eval sym))))
)
(list
'(initget "TXT CSV")
'(set sym (cond ((getkword (strcat "\nChoose Output [TXT/CSV] <" (eval sym) ">: "))) ((eval sym))))
)
)
)
)

(princ
(strcat
"\n:: PolyInfo.lsp | Version 1.3 | \\U+00A9 Lee Mac "
(menucmd "m=$(edtime,0,yyyy)")
" www.lee-mac.com ::"
"\n:: Type \"polyinfo\" to Invoke ::"
)
)
(princ)

;;----------------------------------------------------------------------;;
;; End of File ;;
;;----------------------------------------------------------------------;;

0 Likes
Message 8 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

@alexandre_benekowski wrote:

Hi @ВeekeeCZ

 

I fond a routine written by LeeMac, that in the final of routine open a ".txt" I will try the samething too.

 

If you have a comment that could be helpful for me, please say 

 

Thank you very much!!!!

 

 

...

I would recommend you, as to beginner, don't try to learn from Lee Mac's routines. (no offence to you or LM, just my experience). Lee's routines are very advanced. And written by specific way. Keep it a time.

 

But what I do recommend - Lee has a very long library of sub routines. That's very helpful - even if you will take these only as a black box. You can manage to do more complicated things with limited knowledge. 

 

So here is a very simple routine I wrote lately, exporting some of DIM points. (no matter if its csv or txt, the approach is the same)

 

(vl-load-com)

(defun c:DimExport ( / *error* file ed ss txt pt)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))
  
  
  (if (and (setq ss (ssget '((0 . "*DIM*"))))
           (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) "-DimExport.csv") "a"))
           (write-line "x1,y1,x2,y2,value" file)
           (setq txt "")
           )
    (repeat (setq i (sslength ss))
      (setq ed (entget (ssname ss (setq i (1- i)))))
      (if (and (setq pt (cdr (assoc 13 ed)))
               (= 'list (type pt)))
        (setq txt (strcat (rtos (car pt) 2 6) "," (rtos (cadr pt) 2 6) ",")))
      (if (and (setq pt (cdr (assoc 14 ed)))
               (= 'list (type pt)))
        (setq txt (strcat txt (rtos (car pt) 2 6) "," (rtos (cadr pt) 2 6) ",")))
      (setq txt (strcat txt (rtos (cdr (assoc 72 ed)) 2 4)))
      (write-line txt file)))
  (if file (close file))
  (princ)
  )
Message 9 of 13

alexandre_benekowski
Advocate
Advocate

Hi BeekeeCZ,

 

would you mind help me to do the samethig in your code in my lisp? ".txt" with 3 colum "ESTACA" "CORTE" "ATERRO"

 

in my code I pick areas and sum cutting area and sum filling areas

 

anyway, thank you very much, If you can´t do that, no problem, I will study more and I will win. You teached me many things in autolisp.  

 

my code:

 

(defun C:VOLUME ()

;PRELIMINARES.

(setvar "attdia" 0)
(setvar "osmode" 0)
(setq layer_atual (getvar "clayer"))

;PONTO CORTE:

(setq RESPOSTA_CORTE (getint "\nInforme a quantidade de áreas de Corte na seção... "))

;CONDIÇÃO:

(cond

((= RESPOSTA_CORTE 0)
(setq soma_c 0.000)
(setq AC_FINAL (rtos soma_c 2 3))
)
((= RESPOSTA_CORTE 1)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_I11 (getvar "area"))
(setq AC_FINAL (rtos AC_I11 2 3))
)
)

((= RESPOSTA_CORTE 2)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F1 (getvar "area"))
(setq ac2 (getpoint "\nClique na segunda área de Corte...."))
(command "-boundary" ac2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F2 (getvar "area"))
(setq soma_c (+ AC_F1 AC_F2))
(setq AC_FINAL (rtos soma_c 2 3))
)
)

((= RESPOSTA_CORTE 3)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F1 (getvar "area"))
(setq ac2 (getpoint "\nClique na segunda área de Corte...."))
(command "-boundary" ac2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F2 (getvar "area"))
(setq ac3 (getpoint "\nClique na terceira área de Corte...."))
(command "-boundary" ac3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F3 (getvar "area"))
(setq soma_c (+ AC_F1 AC_F2 AC_F3))
(setq AC_FINAL (rtos soma_c 2 3))
)
)


((= RESPOSTA_CORTE 4)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F1 (getvar "area"))
(setq ac2 (getpoint "\nClique na segunda área de Corte...."))
(command "-boundary" ac2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F2 (getvar "area"))
(setq ac3 (getpoint "\nClique na terceira área de Corte...."))
(command "-boundary" ac3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F3 (getvar "area"))
(setq ac4 (getpoint "\nClique na quarta área de Corte...."))
(command "-boundary" ac4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F4 (getvar "area"))
(setq soma_c (+ AC_F1 AC_F2 AC_F3 AC_F4))
(setq AC_FINAL (rtos soma_c 2 3))
)
)

((= RESPOSTA_CORTE 5)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F1 (getvar "area"))
(setq ac2 (getpoint "\nClique na segunda área de Corte...."))
(command "-boundary" ac2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F2 (getvar "area"))
(setq ac3 (getpoint "\nClique na terceira área de Corte...."))
(command "-boundary" ac3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F3 (getvar "area"))
(setq ac4 (getpoint "\nClique na quarta área de Corte...."))
(command "-boundary" ac4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F4 (getvar "area"))
(setq ac5 (getpoint "\nClique na quinta área de Corte...."))
(command "-boundary" ac5 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F5 (getvar "area"))
(setq soma_c (+ AC_F1 AC_F2 AC_F3 AC_F4 AC_F5))
(setq AC_FINAL (rtos soma_c 2 3))
)
)

((= RESPOSTA_CORTE 6)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F1 (getvar "area"))
(setq ac2 (getpoint "\nClique na segunda área de Corte...."))
(command "-boundary" ac2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F2 (getvar "area"))
(setq ac3 (getpoint "\nClique na terceira área de Corte...."))
(command "-boundary" ac3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F3 (getvar "area"))
(setq ac4 (getpoint "\nClique na quarta área de Corte...."))
(command "-boundary" ac4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F4 (getvar "area"))
(setq ac5 (getpoint "\nClique na quinta área de Corte...."))
(command "-boundary" ac5 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F5 (getvar "area"))
(setq ac6 (getpoint "\nClique na sexta área de Corte...."))
(command "-boundary" ac6 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F6 (getvar "area"))
(setq soma_c (+ AC_F1 AC_F2 AC_F3 AC_F4 AC_F5 AC_F6))
(setq AC_FINAL (rtos soma_c 2 3))
)
)

((= RESPOSTA_CORTE 7)
(progn
(setq ac1 (getpoint "\nClique na primeira área de Corte...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F1 (getvar "area"))
(setq ac2 (getpoint "\nClique na segunda área de Corte...."))
(command "-boundary" ac2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F2 (getvar "area"))
(setq ac3 (getpoint "\nClique na terceira área de Corte...."))
(command "-boundary" ac3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F3 (getvar "area"))
(setq ac4 (getpoint "\nClique na quarta área de Corte...."))
(command "-boundary" ac4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F4 (getvar "area"))
(setq ac5 (getpoint "\nClique na quinta área de Corte...."))
(command "-boundary" ac5 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F5 (getvar "area"))
(setq ac6 (getpoint "\nClique na sexta área de Corte...."))
(command "-boundary" ac6 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F6 (getvar "area"))
(setq ac7 (getpoint "\nClique na sétima área de Corte...."))
(command "-boundary" ac7 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AC_F7 (getvar "area"))
(setq soma_c (+ AC_F1 AC_F2 AC_F3 AC_F4 AC_F5 AC_F6 AC_F7))
(setq AC_FINAL (rtos soma_c 2 3))
)
)

(t (alert "\nO programa só aceita no máximo 7 áreas de Corte!!!"))
)

;PONTO ATERRO:

(setq RESPOSTA_ATERRO (getint "\nInforme a quantidade de áreas de Aterro na seção... "))

;CONDIÇÃO:

(cond

((= RESPOSTA_ATERRO 0)
(setq soma_a 0.000)
(setq AA_FINAL (rtos soma_a 2 3))
)
((= RESPOSTA_ATERRO 1)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" aa1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_I11 (getvar "area"))
(setq AA_FINAL (rtos AA_I11 2 3))
)
)

((= RESPOSTA_ATERRO 2)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" aa1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F1 (getvar "area"))
(setq aa2 (getpoint "\nClique na segunda área de Aterro...."))
(command "-boundary" aa2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F2 (getvar "area"))
(setq soma_A (+ AA_F1 AA_F2))
(setq AA_FINAL (rtos soma_A 2 3))
)
)

((= RESPOSTA_ATERRO 3)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" aa1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F1 (getvar "area"))
(setq aa2 (getpoint "\nClique na segunda área de Aterro...."))
(command "-boundary" aa2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F2 (getvar "area"))
(setq aa3 (getpoint "\nClique na terceira área de Aterro...."))
(command "-boundary" aa3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F3 (getvar "area"))
(setq soma_A (+ AA_F1 AA_F2 AA_F3))
(setq AA_FINAL (rtos soma_A 2 3))
)
)


((= RESPOSTA_ATERRO 4)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" ac1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F1 (getvar "area"))
(setq aa2 (getpoint "\nClique na segunda área de Aterro...."))
(command "-boundary" aa2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F2 (getvar "area"))
(setq aa3 (getpoint "\nClique na terceira área de Aterro...."))
(command "-boundary" aa3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F3 (getvar "area"))
(setq aa4 (getpoint "\nClique na quarta área de Aterro...."))
(command "-boundary" aa4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F4 (getvar "area"))
(setq soma_A (+ AA_F1 AA_F2 AA_F3 AA_F4))
(setq AA_FINAL (rtos soma_A 2 3))
)
)

((= RESPOSTA_ATERRO 5)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" aa1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F1 (getvar "area"))
(setq aa2 (getpoint "\nClique na segunda área de Aterro...."))
(command "-boundary" aa2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F2 (getvar "area"))
(setq aa3 (getpoint "\nClique na terceira área de Aterro...."))
(command "-boundary" aa3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F3 (getvar "area"))
(setq aa4 (getpoint "\nClique na quarta área de Aterro...."))
(command "-boundary" aa4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F4 (getvar "area"))
(setq aa5 (getpoint "\nClique na quinta área de Aterro...."))
(command "-boundary" aa5 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F5 (getvar "area"))
(setq soma_A (+ AA_F1 AA_F2 AA_F3 AA_F4 AA_F5))
(setq AA_FINAL (rtos soma_A 2 3))
)
)

((= RESPOSTA_ATERRO 6)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" aa1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F1 (getvar "area"))
(setq aa2 (getpoint "\nClique na segunda área de Aterro...."))
(command "-boundary" aa2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F2 (getvar "area"))
(setq aa3 (getpoint "\nClique na terceira área de Aterro...."))
(command "-boundary" aa3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F3 (getvar "area"))
(setq aa4 (getpoint "\nClique na quarta área de Aterro...."))
(command "-boundary" aa4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F4 (getvar "area"))
(setq aa5 (getpoint "\nClique na quinta área de Aterro...."))
(command "-boundary" aa5 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F5 (getvar "area"))
(setq aa6 (getpoint "\nClique na sexta área de Aterro...."))
(command "-boundary" aa6 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F6 (getvar "area"))
(setq soma_A (+ AA_F1 AA_F2 AA_F3 AA_F4 AA_F5 AA_F6))
(setq AA_FINAL (rtos soma_A 2 3))
)
)

((= RESPOSTA_ATERRO 7)
(progn
(setq aa1 (getpoint "\nClique na primeira área de Aterro...."))
(command "-boundary" aa1 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F1 (getvar "area"))
(setq aa2 (getpoint "\nClique na segunda área de Aterro...."))
(command "-boundary" aa2 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F2 (getvar "area"))
(setq aa3 (getpoint "\nClique na terceira área de Aterro...."))
(command "-boundary" aa3 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F3 (getvar "area"))
(setq aa4 (getpoint "\nClique na quarta área de Aterro...."))
(command "-boundary" aa4 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F4 (getvar "area"))
(setq aa5 (getpoint "\nClique na quinta área de Aterro...."))
(command "-boundary" aa5 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F5 (getvar "area"))
(setq aa6 (getpoint "\nClique na sexta área de Aterro...."))
(command "-boundary" aa6 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F6 (getvar "area"))
(setq aa7 (getpoint "\nClique na sétima área de Aterro...."))
(command "-boundary" aa7 "")
(command "area" "o" "last")
(command "erase" "last" "")
(setq AA_F7 (getvar "area"))
(setq soma_A (+ AA_F1 AA_F2 AA_F3 AA_F4 AA_F5 AA_F6 AA_F7))
(setq AA_FINAL (rtos soma_A 2 3))
)
)

(t (alert "\nO programa só aceita no máximo 7 áreas de Aterro!!!"))
)

;INSERÇÃO DO BLOCO E ESTACA:

(setq POSICAO (getpoint "\nClique no ponto de inserção do bloco "))
(if
(and
(setq estaca (car (entsel "\nClique na Estaca: ")))
(wcmatch (cdr (assoc 0 (entget estaca))) "*TEXT")
)
(setq estaca_final (cdr (assoc 1 (entget estaca))))
)
(command "-insert" "C:/LISPS ALEXANDRE/BLOCOS/CORTE_ATERRO" POSICAO "1" "1" "0" estaca_final AA_FINAL AC_FINAL)

;CONTINUAR OU PARAR:
(initget "C P")
(setq RESPOSTA (getkword "\nDeseja continuar(C) ou Parar(P)? "))
(if (= RESPOSTA "C")
(C:VOLUME)
(progn
(setvar "clayer" layer_atual)
(prompt "\nFIM!")
(princ)
)
)
)
(prompt "\nLisp Carregada com sucesso!!!!")

 

 
 
 
 
0 Likes
Message 10 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, here you have some stuff to learn from 🙂

 

Spoiler
(defun c:Volume2 ( / *error* file oATTDIA oOSMODE iCorte aCorte iAterro aAterro pnt i ent txt fname)
  
  (defun *error* (errmsg) ; IN CASE OF ERROR IT AUTOMATICALLY GOES THRU THIS *ERROR* SUBROUTINE
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (if oATTDIA (setvar 'ATTDIA oATTDIA))
    (if oOSMODE (setvar 'OSMODE oOSMODE))
    (if oCECOLOR (setvar 'CECOLOR oCECOLOR))
    (princ))
  
  (setq oATTDIA (getvar 'ATTDIA)	
	oOSMODE (getvar 'OSMODE)
	oCECOLOR (getvar 'CECOLOR))
  
  (setvar 'ATTDIA 0)
  (setvar 'OSMODE 0)
  (setvar 'CECOLOR "1")
  
  (setq iCorte 0
	aCorte 0.)
  
  (while (setq pnt (getpoint (strcat "\nClick for area of Corte No **" (itoa iCorte) "** <no more Corte>: ")))
    (command "_.BOUNDARY" pnt ""
	     "_.AREA" "_O" "_L"
	     "_.DELAY" 200
	     "_.ERASE" "_L" "")
    (setq iCorte (1+ iCorte)
	  aCorte (+ aCorte (getvar 'area))))
  
  (setq iAterro 0
	aAterro 0.)
  
  (while (setq pnt (getpoint (strcat "\nClick for area of Aterro No **" (itoa iAterro) "** <no more Aterro>: ")))
    (command "_.BOUNDARY" pnt ""
	     "_.AREA" "_O" "_L"
	     "_.DELAY" 200
	     "_.ERASE" "_L" "")
    (setq iAterro (1+ iAterro)
	  aAterro (+ aAterro (getvar 'area))))
  
  (if (and (setq pnt (getpoint "\nClique no ponto de inserçao do bloco:"))
	   (setq ent (car (entsel "\nClique na Estaca: ")))
	   (setq txt (cdr (assoc 1 (entget ent))))
	   )
    (command "_.INSERT" "C:/LISPS ALEXANDRE/BLOCOS/CORTE_ATERRO"
	     pnt "1" "1" "0" txt (rtos aAterro 2 3) (rtos ACorte 2 3)))
  
  (setq fname (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) "-areas.txt"))
  
  (if (not (findfile fname))
    (progn 
      (setq file (open fname "w"))
      (write-line "Estaca,Corte,Aterro" file)
      (if file (close file))))
    
  (if (and txt
	   (setq file (open fname "a"))
	   (setq txt (strcat txt "," (rtos aCorte 2 3) "," (rtos aAterro 2 3)))
	   )
    (progn
      (princ "\nEstaca,Corte,Aterro\n")
      (write-line txt)
      (write-line txt file)))
  
  (if file (close file))
  (setvar 'ATTDIA oATTDIA) (setvar 'OSMODE oOSMODE) (setvar 'CECOLOR oCECOLOR)
  (princ)
  )

(prompt "\nLisp Carregada com sucesso!")

 

Notes:

- if you don't like my (while till no more Corte), rewrite it using your (setq n (getint)) and (repeat n)...

- your last prompt for Continue? - I've removed it, because WHY you have it? You can just hit SPACE or ENTER and the program runs again. Everybody knows that.

- NEVER, NEVER turn off osnaps if you DON'T bother SET IT BACK ON. You must get it back even in case of error - see the code of mine.

- have fun!

Message 11 of 13

alexandre_benekowski
Advocate
Advocate
Accepted solution

Hi, BeekeeCZ

 

 

Thank you very much for the code!!!!!!! thank you thank you!!!  you helped me so much, I´m grateful!!!!

 

this is my gift christmas!!!! my work will be faster.

 

one more Thank you so much!!!!

 

😃

 

you know a web site or do you have doc for people that is learnig autolisp? because your code is better than mine, and now, I know I have to study so much.

 

 

0 Likes
Message 12 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

@alexandre_benekowski wrote:

Hi, @ВeekeeCZ

 

 

Thank you very much for the code!!!!!!! thank you thank you!!!  you helped me so much, I´m grateful!!!!

 

this is my gift christmas!!!! my work will be faster.

 

one more Thank you so much!!!!

 

😃

 

you know a web site or do you have doc for people that is learnig autolisp? because your code is better than mine, and now, I know I have to study so much.

 

 


You're welcome!!

 

Ou, sorry that it came that much early before Christmas. If I would know that I enclose some ribbon *.gif. 🙂

 

Most of people are recommending THIS page to start. There are a lot hepful links... But I learned from a book and got a rote in here - practice and seeing the coding of other users. Maybe Henrique could you recommend some good book in Portuguese..., @hmsilva would you? 🙂

0 Likes
Message 13 of 13

hmsilva
Mentor
Mentor
Accepted solution

Hi Beekee!

 

Alexandre,

infelizmente não sei de nenhum bom livro portugues que te possa sugerir, mas se fizeres uma procura no google ou outro, irás encontrar muitos...

A minha sugestão é a mesma do Beekee, AfraLISP...

 

Unfortunately I don't know of any good book in portuguese to suggest, but if you do a search in google or another search engine, you will find many books...
My suggestion is the same as Beekee, AfraLISP...

 

Henrique

EESignature