Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Totaly new to the whole lisp thing....

23 REPLIES 23
Reply
Message 1 of 24
RobinHutch
300 Views, 23 Replies

Totaly new to the whole lisp thing....

hi there i have a bit of a long winded question. i have to get the total area of the drawing with holes and the number of entities of a drawing, all the drawings are simple 2D drawings. Is there a way of doing this with a lisp or is there another autocad package that i can use. the reason why i need this is for a costing file for laser cutting.
23 REPLIES 23
Message 2 of 24
EC-CAD
in reply to: RobinHutch

Yes, both actions are doable in lisp.

Here's an example to find the number of Items..

Save the following lines of code in a file called 'acaddoc.lsp',

in your AutoCAD 2xxx\support ...... folder. Use Notepad.

(defun C:TOTAL ( / P1 P2 ss)

(setq P1 (getpoint "Pick Upper Left Corner:"))

(setq P2 (getpoint P1 "\nPick Lower Right Corner:"))

(setq ss (ssget "W" P1 P2)); get all things in window

(if ss

(alert (strcat "Total Items found = " (itoa (sslength ss))))

); if

(princ)

); function



Exit, reenter AutoCAD.

At Command prompt, type in: TOTAL



For the 'holes'.. are they circles, or polylines ?

What version of AutoCAD do you have ?



Bob
Message 3 of 24
RobinHutch
in reply to: RobinHutch

Thanks Bob

it is a combination of circles and polylines, changes from time to time. and the version of Autocad is 2009.

Robin
Message 4 of 24
EC-CAD
in reply to: RobinHutch

Do you need the total area of the Materials, (and) the holes

or just the area of the holes ?

If you send me a sample drawing or two, I'll see if I can get

it done.

nospam.ec-cad@centurytel.net

(remove the nospam and the ".")



Bob
Message 5 of 24
devitg
in reply to: RobinHutch

I did it last month .



Feel free to contact me .

My email at the Lisp Header












Message 6 of 24
Anonymous
in reply to: RobinHutch

{code}

Interesting, my main occupation is programming lasers for cutting sheet metal.
Here's some code I wrote a while back.

Regards,

Mel

;;; examines polylines and circles
;;; polylines not closed are ignored and turned red
;;; part perimeter is highlighted
;;;
;;; calculates number of internal features and part area
;;; with feature area subtracted

(defun c:objarea ( / area-lst msg part-area obj-lst ss i perim perim-area obj-lst)
(vl-load-com)
(setq i -1)
(if(setq ss(ssget '((0 . "*POLYLINE,CIRCLE"))))
(progn
(repeat(sslength ss)
(cond
((vlax-curve-isClosed
(setq obj
(vlax-ename->vla-object
(ssname ss
(setq i(1+ i))
)
)
)
)
(setq obj-lst
(cons
(list
(vlax-curve-getArea obj) obj
)
obj-lst
)
)
)
(1
(vla-put-color obj 1)
(setq msg "\nOpen geometry found")
)
)
)
(setq perim (car
(setq obj-lst
(vl-sort obj-lst
(function(lambda(a b)(>(car a)(car b))))
)
)
)
perim-area (car perim)
obj-lst (cdr obj-lst)
)
(setq part-area
(last
(mapcar '(lambda(x)(setq perim-area(- perim-area(car x))))obj-lst)
)
)
(princ(strcat "\nPart area: " (rtos part-area)))
(princ(strcat "\nNumber of internal features: " (itoa(length obj-lst))))
(redraw(vlax-vla-object->ename(last perim))3)
)
)
(if msg(princ msg))
(princ)
)

{code}
Message 7 of 24
Anonymous
in reply to: RobinHutch

{code}

Whoops, I apparently forgot to account for parts with no holes.

Regards,

Mel

;;; examines polylines and circles
;;; polylines not closed are ignored and turned red
;;; part perimeter is highlighted
;;;
;;; calculates number of internal features and part
;;; area with feature area subtracted

(defun c:objarea ( / area-lst msg part-area obj-lst ss
i perim perim-area obj-lst)
(vl-load-com)
(setq i -1)
(if(setq ss(ssget '((0 . "*POLYLINE,CIRCLE"))))
(progn
(repeat(sslength ss)
(cond
((vlax-curve-isClosed
(setq obj
(vlax-ename->vla-object
(ssname ss
(setq i(1+ i))
)
)
)
)
(setq obj-lst
(cons
(list
(vlax-curve-getArea obj) obj
)
obj-lst
)
)
)
(1
(vla-put-color obj 1)
(setq msg "\nOpen geometry found")
)
)
)
(if obj-lst
(progn
(setq perim (car
(setq obj-lst
(vl-sort obj-lst
(function
(lambda(a b)(>(car a)(car b)))
)
)
)
)
perim-area (car perim)
obj-lst (cdr obj-lst)
)
(if obj-lst
(setq part-area
(last
(mapcar '(lambda(x)
(setq perim-area
(- perim-area(car x))
)
)
obj-lst)
)
)
(setq part-area perim-area)
)
(princ
(strcat "\nPart area: "
(rtos part-area)
)
)
(princ
(strcat "\nNumber of internal features: "
(itoa(length obj-lst))
)
)
(redraw(vlax-vla-object->ename(last perim))3)
)
(setq msg "\nNo valid geometry exists")
)
)
)
(if msg(princ msg))
(princ)
)

{code}
Message 8 of 24
RobinHutch
in reply to: RobinHutch

Howzit Mel

what I am trying to do is get the cut length and the number of pierce's for the part. have a program that does this but want to do this in autocad and if i can use a lisp to do this will make my life alot easier.

thanks to all for the help
Message 9 of 24
Anonymous
in reply to: RobinHutch

{code}
wrote in message news:6105983@discussion.autodesk.com...
Howzit Mel what I am trying to do is get the cut length and the number of pierce's for the part. have a program that does this but
want to do this in autocad and if i can use a lisp to do this will make my life alot easier. thanks to all for the help

I made a few changes.
I assume you are ultimately going to calculate an estimated run time?
It would be trivial to add prompts for feed rate and pierce time and do the math.

Regards,

Mel

(defun c:cutdata ( / data-lst data-lst acad-doc
cut-lgth obj ss part-area)
(vl-load-com)
(setq acad-doc (vla-get-activedocument
(vlax-get-Acad-Object)
)
cut-lgth 0
)
(if(setq ss(ssget '((0 . "*POLYLINE,CIRCLE"))))
(progn
(vlax-for obj (vla-get-activeselectionset acad-doc)
(setq data-lst
(cons
(list
(vlax-curve-getArea obj)
(if(=(vla-get-ObjectName obj)"AcDbCircle")
(* pi(* 2(vlax-get-property obj 'Radius)))
(vla-get-length obj)
)
)
data-lst
)
)
)
(setq data-lst
(vl-sort data-lst
(function
(lambda(a b)(>(car a)(car b)))
)
)
)
(setq part-area
(if(>(length data-lst)1)
(-
(caar data-lst)
(apply '+ (mapcar 'car (cdr data-lst)))
)
(caar data-lst)
)
)
(setq cut-lgth
(apply '+ (mapcar 'cadr data-lst))
)
(princ(strcat "\nCut length: " (rtos cut-lgth)))
(princ(strcat "\nPierces: " (itoa(length data-lst))))
(princ(strcat "\nPart area: " (rtos part-area)))
)
)
(princ)
)

{code}
Message 10 of 24
RobinHutch
in reply to: RobinHutch

Thanks once again

am trying to get the information so that we can do cost calculations.....the material and cutting times for the machines have already been put onto an excel spread sheet. wanting to use auto cad for everything, and not multiple programs.
Message 11 of 24
devitg
in reply to: RobinHutch

Hi Robin, did you test the LISPI upload.?



Please upload one of your's piece, and the data you need to make your calcs.



It can be made all in lisp , and it will also make a file with such data.



Also you can contact me at my email , as it is in the attached file.



Gabriel
Message 12 of 24
RobinHutch
in reply to: RobinHutch

Thanks for all the help..... I used the lisp from Mel and it worked perfectly, but have one more question for you. is it posiblre to get the square size of the part, e.g the x and y sizes. for the pricing of the laser cut part i need to know what the material use is. I have looked in autocad to see if i can get the square size but have had no luck.
Message 13 of 24
Anonymous
in reply to: RobinHutch

{code}

I added the part bounding box size and square inches, hope that's what you were after.
I also put the results in an alert box.

Regards,

Mel

(defun c:cutdata ( / data-lst data-lst acad-doc minpt
maxpt dxdy cut-lgth obj ss part-area)

(vl-load-com)
(setq acad-doc (vla-get-activedocument
(vlax-get-Acad-Object)
)
cut-lgth 0
)
(if(setq ss(ssget '((0 . "*POLYLINE,CIRCLE"))))
(progn
(vlax-for obj (vla-get-activeselectionset acad-doc)
(setq data-lst
(cons
(list
(vlax-curve-getArea obj)
(if(=(vla-get-ObjectName obj)"AcDbCircle")
(* pi(* 2(vlax-get-property obj 'Radius)))
(vla-get-length obj)
)
obj
)
data-lst
)
)
)
(setq data-lst
(vl-sort data-lst
(function
(lambda(a b)(>(car a)(car b)))
)
)
)
(setq part-area
(if(>(length data-lst)1)
(-
(caar data-lst)
(apply '+ (mapcar 'car (cdr data-lst)))
)
(caar data-lst)
)
)
(setq cut-lgth
(apply '+ (mapcar 'cadr data-lst))
)
(vla-GetBoundingBox (caddar data-lst) 'minpt 'maxpt)
(setq dxdy
(mapcar '(lambda(x y)
(abs(- x y))
)
(vlax-safearray->list minpt)
(vlax-safearray->list maxpt)
)
)
(alert
(strcat
"\nBounding box: " (rtos(car dxdy)) " x " (rtos(cadr dxdy)) "\n"
"\nBounding box Sq/Inch: " (rtos(*(car dxdy)(cadr dxdy))) "\n"
"\nCut length: " (rtos cut-lgth) "\n"
"\nPierces: " (itoa(length data-lst)) "\n"
"\nActual part area: " (rtos part-area)
)
)
)
)
(princ)
)

{code}
Message 14 of 24
RobinHutch
in reply to: RobinHutch

To All

thanks for all your help, all the info has been helpfull. if there are any other questions i will be bugging.
Message 15 of 24
RobinHutch
in reply to: RobinHutch

Hi Mel

Is there a way of saving the information that you get in the information block in a format that you can export it as a .csv file or to excel ?
Message 16 of 24
Anonymous
in reply to: RobinHutch

Sure, the data could be appended to a .csv file to be opened later in Excel.
What format would you like the data in?
I would think you would also want to associate the drawing name with each line of data?

Regards,

Mel
Message 17 of 24
RobinHutch
in reply to: RobinHutch

Hi Mel

The info that needs to go as a csv file needs to be the word cutlength one rcolumn and the actual value in the next column, this needs to be for each of those values that is genarated in the pop up window. the "x" and "y" value need to be seperated so that each value is in a column. is there a way of getting the image into the same file so that when i open excel i can see both the info and the image.

And "yes" to your second question

thanks for the help
Message 18 of 24
Anonymous
in reply to: RobinHutch

{code}

I made some changes, the data is written (appended) to a .csv file.
I added many configuration options, they are listed at the top of the routine.
Let me know if you have any questions regarding them, or any other aspect of the code.
As for the image, I'm not aware of a way to place an image along with the data, if that's what you mean.

Regards,

Mel

(defun c:cutdata ( / data-lst data-lst acad-doc minpt flnm
show-data data-order-lst fl-path-str fl-name-str
full-path labels-list data-write-list v1
v2 v3 v4 v5 v6 v7 maxpt dxdy cut-lgth obj tmp
ss part-area vlst val astr wstr tmp1)

;;; ******* configuration start ******
;;;
;;; csv file path
;;;
(setq fl-path-str "c:\\temp\\")

;;; csv file name
;;;
(setq fl-name-str "cutdata")

;;; drawing name value
;;; full file path = 1 "c:\drawings\\drawing.dwg"
;;; file name only = 0 "drawing.dwg"
;;;
(setq full-path 0)

;;; display data alert box
;;; 0 = display
;;; 1 = inhibit
(setq show-data 0)

;;; data labels
;;; only modify the label
;;; do not modify the "v" value
;;; do not modify the list order
;;;
(setq labels-list
'((v1 . "Drawing Name")
(v2 . "Cut length")
(v3 . "Pierces")
(v4 . "Bounding Box X")
(v5 . "Bounding Box Y")
(v6 . "Bounding Box Area")
(v7 . "Actual Area")
)
)

;;; data to write to file
;;; based on above list from top down
;;; write data to file = 0
;;; omit data from file = 1
;;;
(setq data-write-list
'(0 0 0 0 0 0 0)
)

;;; order data is to be written
;;; based on labels-list
;;;
(setq data-order-list
'(v1 v2 v3 v4 v5 v6 v7)
)

;;; ******* configuration end ******

(vl-load-com)
(setq acad-doc (vla-get-activedocument
(vlax-get-Acad-Object)
)
cut-lgth 0
astr ""
wstr ""
)
(if(setq ss(ssget '((0 . "*POLYLINE,CIRCLE"))))
(progn
(vlax-for obj (vla-get-activeselectionset acad-doc)
(setq data-lst
(cons
(list
(vlax-curve-getArea obj)
(if(=(vla-get-ObjectName obj)"AcDbCircle")
(* pi(* 2(vlax-get-property obj 'Radius)))
(vla-get-length obj)
)
obj
)
data-lst
)
)
)
(setq data-lst
(vl-sort data-lst
(function
(lambda(a b)(>(car a)(car b)))
)
)
)
(setq part-area
(if(>(length data-lst)1)
(-
(caar data-lst)
(apply '+ (mapcar 'car (cdr data-lst)))
)
(caar data-lst)
)
)
(setq cut-lgth
(apply '+ (mapcar 'cadr data-lst))
)
(vla-GetBoundingBox (caddar data-lst) 'minpt 'maxpt)
(setq dxdy (mapcar '(lambda(x y)
(abs(- x y))
)
(vlax-safearray->list minpt)
(vlax-safearray->list maxpt)
)
v1 (if(zerop full-path)
(getvar "dwgname")
(strcat(getvar "dwgprefix")(getvar "dwgname"))
)
v2 cut-lgth
v3 (length data-lst)
v4 (car dxdy)
v5 (cadr dxdy)
v6 (* v4 v5)
v7 part-area
vlst (mapcar '(lambda(x y)
(cons(car x)y)
)
labels-list
data-write-list
)
)
(foreach val data-order-list
(if(zerop(cdr(assoc val vlst)))
(setq astr (strcat
astr
"\n"
(setq tmp(cdr(assoc val labels-list)))
": "
(setq tmp1(vl-princ-to-string(eval val)))
"\n"
)
wstr (strcat wstr tmp "," tmp1 ",")
)
)
)
(if(zerop show-data)
(alert(substr astr 2))
)
(if(setq flnm(open(strcat fl-path-str fl-name-str ".csv")"a"))
(progn
(write-line wstr flnm)
(close flnm)
)
(alert(strcat "Unable to access " fl-name-str ".csv!\n"
"File may be open"
))
)
)
)
(princ)
)

{code}
Message 19 of 24
Toml5
in reply to: RobinHutch

Hi Mel,

Like RobinHutch I'm new to this thing. I'm after something very similar to what he wanted.
However, I'm only interested in the area of the objects, but I need to have both Sq m and Sq ft.
(I only need it as a pop up window, as it is only for checking visually).

Is this something you could help me with?

Tom
Message 20 of 24
RobinHutch
in reply to: RobinHutch

Hi Mel

The lisp works wel, is there a way of saving the .csv file as the drawing name. so that each drawing has its own .csv file.dont worry bout the drawing will export it as a .wmf file and use it that way

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost