Visual LISP, AutoLISP and General Customization

Reply
Mentor
Posts: 1,678
Registered: ‎03-14-2004
Message 11 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-19-2009 02:03 AM 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
Contributor
Posts: 25
Registered: ‎01-14-2009
Message 12 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-20-2009 08:32 PM 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.
*MelFranks
Message 13 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-21-2009 05:46 AM 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}
Contributor
Posts: 25
Registered: ‎01-14-2009
Message 14 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-22-2009 10:30 PM 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.
Contributor
Posts: 25
Registered: ‎01-14-2009
Message 15 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-23-2009 04:41 AM 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 ?
*MelFranks
Message 16 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-23-2009 09:19 AM 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
Contributor
Posts: 25
Registered: ‎01-14-2009
Message 17 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-23-2009 09:37 PM 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
*MelFranks
Message 18 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-26-2009 06:37 AM 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}
Member
Posts: 3
Registered: ‎05-21-2008
Message 19 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-27-2009 12:46 AM 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
Contributor
Posts: 25
Registered: ‎01-14-2009
Message 20 of 24 (60 Views)

Re: Totaly new to the whole lisp thing....

01-27-2009 05:27 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community