Jump to content

Lisp for placing excel-defined coordinates with label top of them


flausbert

Recommended Posts

Hi all!

 

I have been getting benefit out of your great knowledge of autocad lisps on this forum for such a long time but first time i could not find what i look for so i am posting this. I appreciate if you could help me out.

 

Thanks to you guys i am using lisp posted here http://www.cadtutor.net/forum/showthread.php?31653-Lisp-coordinates-of-points-to-excel-sheet-(-point-number)

 

Other than this great lisp, i was wondering if you could arrange something for putting label to those points instead only number. It perfectly generates numbers but what i really want put a label i can define with consecutive numbers following like WO 1, WO 2, WO 3...

 

i would be more than happy if you could give a hand

Link to comment
Share on other sites

Here is a quick generic point labelling program:

 

(defun c:ptlabel ( / ht i l pr s sf ts )
   (setq
       pr (getstring t "\nSpecify Label Prefix <None>: ")
       sf (getstring t "\nSpecify Label Suffix <None>: ")
       st (cond ((getint (strcat "\nSpecify Start Number <" (itoa (setq st (cond (st) (1)))) ">: "))) (st))
       ht (cons 40 (getvar 'TEXTSIZE))
       ts (cons  7 (getvar 'TEXTSTYLE))
   )
   (initget "LtR RtL BtT TtB")
   (setq dr (cond ((getkword (strcat "\nSpecify Direction [LtR/RtL/BtT/TtB] <" (setq dr (cond (dr) ("LtR"))) ">: "))) (dr)))
   
   (if (setq s (ssget '((0 . "POINT"))))
       (progn
           (repeat (setq i (sslength s))
               (setq l (cons (assoc 10 (entget (ssname s (setq i (1- i))))) l))
           )
           (foreach pt
               (vl-sort l
                   (cdr
                       (assoc dr
                          '(
                               ("LtR" . (lambda ( a b ) (< (cadr  a) (cadr  b))))
                               ("RtL" . (lambda ( a b ) (> (cadr  a) (cadr  b))))
                               ("BtT" . (lambda ( a b ) (< (caddr a) (caddr b))))
                               ("TtB" . (lambda ( a b ) (> (caddr a) (caddr b))))
                           )
                       )
                   )
               )
               (entmake (list '(0 . "TEXT") pt ht ts '(72 . 1) '(73 . 2) (cons 11 (cdr pt)) (cons 1 (strcat pr (itoa st) sf))))
               (setq st (1+ st))
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

Here, I've corrected... Maybe Lee was in rush hour...

 

(defun c:ptlabel ( / dr ht i lst pr s st sf ts )
   (setq
       pr (getstring t "\nSpecify Label Prefix <None>: ")
       sf (getstring t "\nSpecify Label Suffix <None>: ")
       st (cond ((getint (strcat "\nSpecify Start Number <" (itoa (setq st (cond (st) (1)))) ">: "))) (st))
       ht (cons 40 (getvar 'TEXTSIZE))
       ts (cons  7 (getvar 'TEXTSTYLE))
   )
   (initget "LtR RtL BtT TtB")
   (setq dr (cond ((getkword (strcat "\nSpecify Direction [LtR/RtL/BtT/TtB] <" (setq dr (cond (dr) ("LtR"))) ">: "))) (dr)))
   
   (if (setq s (ssget '((0 . "POINT"))))
       (progn
           (repeat (setq i (sslength s))
               (setq lst (cons (cdr (assoc 10 (entget (ssname s (setq i (1- i)))))) lst))
           )
           (foreach pt
               (vl-sort lst
                   (cdr
                       (assoc dr
                          '(
                               ("LtR" . (lambda ( a b ) (< (car  a) (car  b))))
                               ("RtL" . (lambda ( a b ) (> (car  a) (car  b))))
                               ("BtT" . (lambda ( a b ) (< (cadr a) (cadr b))))
                               ("TtB" . (lambda ( a b ) (> (cadr a) (cadr b))))
                           )
                       )
                   )
               )
               (entmake (list '(0 . "TEXT") (cons 10 pt) ht ts '(72 . 1) '(73 . 2) (cons 11 pt) (cons 1 (strcat pr (itoa st) sf))))
               (setq st (1+ st))
           )
       )
   )
   (princ)
)

 

Lee, hope you want be angry... Cheers and happy weekend... M.R.

Link to comment
Share on other sites

Lee and Marko, thank you both. Works perfectly fine now. Since i catch you both here, you think it is possible to revise it in a way that labels can come from one column of excel as the points come from other column ?

 

And i need to be able to export coordinates with these labels into excel as in here: http://www.cadtutor.net/forum/showthread.php?31653-Lisp-coordinates-of-points-to-excel-sheet-(-point-number

Link to comment
Share on other sites

i cant believe the post i have been mentioning since morning has got it all. i Just didnt read till end. Many thanks to VVA and Lee i also see your contributions in that post. You guys are incredible

Link to comment
Share on other sites

Try this :

 

(defun c:ptlabel ( / dr fn file ht i lst pr s st sf ts )
   (setq
       pr (getstring t "\nSpecify Label Prefix <None>: ")
       sf (getstring t "\nSpecify Label Suffix <None>: ")
       st (cond ((getint (strcat "\nSpecify Start Number <" (itoa (setq st (cond (st) (1)))) ">: "))) (st))
       ht (cons 40 (getvar 'TEXTSIZE))
       ts (cons  7 (getvar 'TEXTSTYLE))
   )
   (initget "LtR RtL BtT TtB")
   (setq dr (cond ((getkword (strcat "\nSpecify Direction [LtR/RtL/BtT/TtB] <" (setq dr (cond (dr) ("LtR"))) ">: "))) (dr)))
   
   (if (setq s (ssget '((0 . "POINT"))))
       (progn
           (setq fn (getfiled "Enter file to save to" (getvar 'dwgprefix) "csv" 1))
           (setq file (open fn "w"))
           (repeat (setq i (sslength s))
               (setq lst (cons (cdr (assoc 10 (entget (ssname s (setq i (1- i)))))) lst))
           )
           (foreach pt
               (vl-sort lst
                   (cdr
                       (assoc dr
                          '(
                               ("LtR" . (lambda ( a b ) (< (car  a) (car  b))))
                               ("RtL" . (lambda ( a b ) (> (car  a) (car  b))))
                               ("BtT" . (lambda ( a b ) (< (cadr a) (cadr b))))
                               ("TtB" . (lambda ( a b ) (> (cadr a) (cadr b))))
                           )
                       )
                   )
               )
               (entmake (list '(0 . "TEXT") (cons 10 pt) ht ts '(72 . 1) '(73 . 2) (cons 11 pt) (cons 1 (strcat pr (itoa st) sf))))
               (write-line (strcat pr (itoa st) sf "," (vl-princ-to-string pt)) file)
               (setq st (1+ st))
           )
           (close file)
           (startapp "explorer.exe" fn)
       )
   )
   (princ)
)

 

If I understood correctly, you wanted to export POINT data from CAD to EXCEL... Option is through CSV file; after you start EXCEL you can afterwards save sheet data to any EXCEL file format like XLS and so on...

 

Cheers, M.R.

Link to comment
Share on other sites

i actually was thinking if we have 2 columns in excel sheet, such as 213123.21,123141,54 and another adjacent column as description of this point like POINT 1. Could we take this description and put right on the point given with coordinates ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...