ojacomarket Posted April 11, 2020 Posted April 11, 2020 Dear LISP-users, I have an issue. I have created a loop with using REPEAT. Then I try to draw just a circle with (command "CIRCLE" (getpoint) 0.5) in my drawing and AutoCAD doesn't react on that at all. It finished the loop and then ends code (however there weren't (princ) symbols and parenthesis is OK. Am I missed something from REPEAT theory? With best regards, Quote
Jonathan Handojo Posted April 11, 2020 Posted April 11, 2020 (edited) It draws the circle just fine for me with radius 0.5. I always try to avoid (command …) [just a habit of mine to increase evaluation speed] so I would do: (repeat ntimes (entmake (list '(0 . "CIRCLE") (cons 10 (getpoint "\nSpecify center: ")) '(40 . 0.5) ) ) ) Or keep clicking until you press enter: (while (setq pt (getpoint "\nSpecify center <Exit>: ")) (entmake (list '(0 . "CIRCLE") (cons 10 pt) '(40 . 0.5) ) ) ) Edited April 11, 2020 by Jonathan Handojo 1 Quote
Lee Mac Posted April 11, 2020 Posted April 11, 2020 (edited) Per Jonathan's response, this could be achieved using entmake, though a basic command call should still operate successfully providing the syntax is correct. Here are three possible methods: 1. CIRCLE Command Call (defun c:test1 ( / cen ) (while (setq cen (getpoint "\nSpecify circle center <exit>: ")) (command "_.circle" "_non" cen 0.5) ) (princ) ) 2. Vanilla AutoLISP using entmake (defun c:test2 ( / cen ocs ) (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)) (while (setq cen (getpoint "\nSpecify circle center <exit>: ")) (entmake (list '(000 . "CIRCLE") (cons 010 (trans cen 1 ocs)) '(040 . 0.5) (cons 210 ocs) ) ) ) (princ) ) 3. ActiveX using the addcircle method (defun c:test3 ( / cen spc ) (setq spc (vlax-get-property (vla-get-activedocument (vlax-get-acad-object)) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace) ) ) (while (setq cen (getpoint "\nSpecify circle center <exit>: ")) (vla-addcircle spc (vlax-3D-point (trans cen 1 0)) 0.5) ) (princ) ) Each example will operate successfully under all UCS & View settings, though the Vanilla AutoLISP example is likely to be the fastest. Edited April 11, 2020 by Lee Mac 1 Quote
ojacomarket Posted April 11, 2020 Author Posted April 11, 2020 3 hours ago, Jonathan Handojo said: It draws the circle just fine for me with radius 0.5. I always try to avoid (command …) [just a habit of mine to increase evaluation speed] so I would do: (repeat ntimes (entmake (list '(0 . "CIRCLE") (cons 10 (getpoint "\nSpecify center: ")) '(40 . 0.5) ) ) ) Or keep clicking until you press enter: (while (setq pt (getpoint "\nSpecify center <Exit>: ")) (entmake (list '(0 . "CIRCLE") (cons 10 pt) '(40 . 0.5) ) ) ) Thank you very much guys, those routines are indeed perfectly act, but maybe I didn't explained my case clearly, the main problem of mine is that I have some other loop (REPEAT), actually this loop creates lines between circle centers, then loop ends with parenthesis and I want after create just simple circle in random (with getpoint) place on modelspace. And when I run code it doesn't occur any error, it just process the loop and ends code without "asking me to "specify center.." And I have no idea why i can't draw just a circle, when I end a loop of joining lines within ONE code (defun).. Quote
ojacomarket Posted April 11, 2020 Author Posted April 11, 2020 29 minutes ago, Lee Mac said: Per Jonathan's response, this could be achieved using entmake, though a basic command call should still operate successfully providing the syntax is correct. Here are three possible methods: 1. CIRCLE Command Call (defun c:test1 ( / cen ) (while (setq cen (getpoint "\nSpecify circle center <exit>: ")) (command "_.circle" "_non" cen 0.5) ) (princ) ) 2. Vanilla AutoLISP using entmake (defun c:test2 ( / cen ocs ) (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)) (while (setq cen (getpoint "\nSpecify circle center <exit>: ")) (entmake (list '(000 . "CIRCLE") (cons 010 (trans cen 1 ocs)) '(040 . 0.5) (cons 210 ocs) ) ) ) (princ) ) 3. ActiveX using the addcircle method (defun c:test3 ( / cen spc ) (setq spc (vlax-get-property (vla-get-activedocument (vlax-get-acad-object)) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace) ) ) (while (setq cen (getpoint "\nSpecify circle center <exit>: ")) (vla-addcircle spc (vlax-3D-point (trans cen 1 0)) 0.5) ) (princ) ) Each example will operate successfully under all UCS & View settings, though the Vanilla AutoLISP example is likely to be the fastest. Thank you very much guys, those routines are indeed perfectly act, but maybe I didn't explained my case clearly, the main problem of mine is that I have some other loop (REPEAT), actually this loop creates lines between circle centers, then loop ends with parenthesis and I want after create just simple circle in random (with getpoint) place on modelspace. And when I run code it doesn't occur any error, it just process the loop and ends code without "asking me to "specify center.." And I have no idea why i can't draw just a circle, when I end a loop of joining lines within ONE code (defun).. Quote
Jonathan Handojo Posted April 11, 2020 Posted April 11, 2020 Are you after something like this? (defun c:cln ( / pt lst) (while (setq pt (getpoint "\nSpecify center <Exit>: ")) (setq lst (cons pt lst)) (entmake (list '(0 . "CIRCLE") (cons 10 pt) '(40 . 0.5) ) ) (if (cadr lst) (entmake (list '(0 . "LINE") (cons 10 (car lst)) (cons 11 (cadr lst)) ) ) ) ) (princ) ) I'm finding it difficult to interpret what you're after though. You can perhaps post your code and I'll try to analyse what you're after. Quote
ojacomarket Posted April 11, 2020 Author Posted April 11, 2020 6 minutes ago, Jonathan Handojo said: Are you after something like this? (defun c:cln ( / pt lst) (while (setq pt (getpoint "\nSpecify center <Exit>: ")) (setq lst (cons pt lst)) (entmake (list '(0 . "CIRCLE") (cons 10 pt) '(40 . 0.5) ) ) (if (cadr lst) (entmake (list '(0 . "LINE") (cons 10 (car lst)) (cons 11 (cadr lst)) ) ) ) ) (princ) ) I'm finding it difficult to interpret what you're after though. You can perhaps post your code and I'll try to analyse what you're after. Yeah, sure, here it is, what code does is: 1. create selection set of some circles, get them centers and then draw single lines between circles with specified features only. 2. I figured out how to combine them into polyline (this code is under comments and the end of loooong code) 3. I try to figure out how to close those set of lines (difficult to explain, so I posted 2 pics how it should be) I also pinned a file of that in .dwg, so the only thing you should do is to click on some TEXT (kolv5.....h9....hdet122...etc) and it draws a lines between only specified circles but I want to close the "lines polygon" and then I could tranform it into polyline and then it is OK. (defun c:PLFULLTEST () (setq circle_set_selection_1 (ssget "x" (list (cons 0 (cdr (assoc 0 (setq entget_circle1 (entget (car (entsel))))))) (cons 8 (cdr (assoc 8 entget_circle1))) (cons 1 (cdr (assoc 1 entget_circle1)))))) ;O_o; created selection set of all objects that contain DXF codes 0 and 8 on selection by user (setq circle_set_selection_length_1 (sslength circle_set_selection_1)) ;O_o; investigate how many objects are included into selection set (setq circle_num_1 (- 1 )) ;just variable that will be used as startpoint of polyline (setq circle_num_2 0) (repeat circle_set_selection_length_1 ;repeat loop as many times as written in the selection set length (setq circle_num_1 (1+ circle_num_1)) ;new value of variable (setq circle_num_2 (1+ circle_num_2)) (setq circle_names_1 (entget (ssname circle_set_selection_1 circle_num_1))) ;get entity name of every member of selection set (setq circle_names_2 (entget (ssname circle_set_selection_1 circle_num_2))) (setq circle_coords_1 (cdr (assoc 10 circle_names_1))) ;taking coordinates of centers of the circles (setq circle_coords_2 (cdr (assoc 10 circle_names_2))) (setq circle_coords_1_Y (+ 0.05 (cadr circle_coords_1))) (setq circle_coords_2_Y (+ 0.05 (cadr circle_coords_2))) (setq circle_NEW_coords_1 (list (car circle_coords_1) circle_coords_1_Y)) (setq circle_NEW_coords_2 (list (car circle_coords_2) circle_coords_2_Y)) (cond ((wcmatch (cdr (assoc 1 entget_circle1)) " h*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "HOONEKP") (cons 8 "HOONE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " hdet*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "HOONEKP") (cons 8 "HOONEDET") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " a*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "ASFBET") (cons 8 "TEE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " b*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "ASFBET") (cons 8 "TEE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " kill*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "KRUUSKILL") (cons 8 "TEE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " ak*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "AAREKIVI") (cons 8 "TEE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " kt*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "TEERADA") (cons 8 "TEE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " pt*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "PINNASTEE") (cons 8 "TEE") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " paed*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "LA_AED") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " aedvund*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "AIAVUND") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " vaed*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "VO_AED") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " maed*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "RAKAED") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " kaed*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "KIVIAED") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " myyr*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "MYYR") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " r*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "RAJATISP") (cons 8 "RAJATIS") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " kolv*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "KOLVIK") (cons 8 "HALJASTUS") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " hek*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "HEKK") (cons 8 "AED") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " tm*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "KOLVIK") (cons 8 "RELJEEF") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " np*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "NOLVAPEAL") (cons 8 "RELJEEF") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " na*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "NOLVAALL") (cons 8 "RELJEEF") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ((wcmatch (cdr (assoc 1 entget_circle1)) " kraav*") (setq poly_make_1 (entmake (list (cons 0 "LINE") (cons 6 "KRAAVIPERV") (cons 8 "VEEKOGU") (cons 10 circle_NEW_coords_1) (cons 11 circle_NEW_coords_2))))) ) ;; -------------> this is the end of COND (setq ssget_112 (ssget "x" (list (assoc 6 poly_make_1) (assoc 8 poly_make_1)))) ;(setq pp1 (apply 'command (list "pedit" "m" ssget_112 "" "y" "j" 0 ""))) ) ;; -------------> this is the end of REPEAT, AND AFTER THAT NO more command could be executed and I have no idea WHY.. ;(setq test_punt_1 (cdr (assoc 10 (entget (ssname ssget_112 0))))) ;(setq test_punt_2 (cdr (assoc 10 (entget (ssname ssget_112 (- (sslength ssget_112) 1)))))) ;(entmake (list (cons 0 "LINE") (cons 6 (cdr (assoc 6 poly_make_1))) (cons 8 (cdr (assoc 8 poly_make_1))) (cons 10 test_punt_1) (cons 11 test_punt_2))) ;(apply 'command (list "CIRCLE" (getpoint) 50)) (princ) ) test.dwg Quote
BIGAL Posted April 11, 2020 Posted April 11, 2020 (edited) Wow got dizzy with that code an easy way is as you make a circle add the center points to a list. Then draw a single poly line this is the way I normally approach a task like this. If you want to see the poly as you add a circle you will need to make 1st circle out side of while. Then can make 1st pline section. Then add a line as you add a circle lastpt -> newpt then use pedit Join (entlast) so will see it happening. For make 1 pline ; create pline from a list of points ; By Alan H March 2019 (defun AHpllst ( lst / x) (command "_pline") (while (= (getvar "cmdactive") 1 ) (repeat (setq x (length lst)) (command (nth (setq x (- x 1)) lst)) ) (command "") ; for close (command "c") ) ) ; (ahpllst (list '(0 0) '(10 10) '(35 6))) (defun ahaddlstpts ( / ) (setq lst '()) (while (setq pt (getpoint "\nPick point enter to exit")) (setq lst (cons pt lst)) ) ) ; (ahpllst lst) There is another post recently about joining circles only like a week old may be usefull to look at. Edited April 11, 2020 by BIGAL 1 Quote
hanhphuc Posted April 12, 2020 Posted April 12, 2020 (edited) 14 hours ago, ojacomarket said: (defun c:PLFULLTEST () ;;snippet;; hi, take a look here BTW, just curious.. (assoc 1 entget_circle1) ??? circle textstring ?? 10 hours ago, BIGAL said: Wow got dizzy with that code @ojacomarket i prefer assoc list but in your case (cond (bla)( bla)), suggest foreach but your wild card pattern is too common like: " a*" " b*" " r*", you may get multiple result!! Try this simple test, just key-in any word, it princ out LT&Layer if wmatch condition met note: please check if any typos in list ?? it was just quick clipboard edit (defun c:test (/ lst str) (setq lst '((" h*" "HOONEKP" "HOONE") (" hdet*" "HOONEKP" "HOONEDET") (" a*" "ASFBET" "TEE") (" b*" "ASFBET" "TEE") (" kill*" "KRUUSKILL" "TEE") (" ak*" "AAREKIVI" "TEE") (" kt*" "TEERADA" "TEE") (" pt*" "PINNASTEE" "TEE") (" paed*" "LA_AED" "AED") (" aedvund*" "AIAVUND" "AED") (" vaed*" "VO_AED" "AED") (" maed*" "RAKAED" "AED") (" kaed*" "KIVIAED" "AED") (" myyr*" "MYYR" "AED") (" r*" "RAJATISP" "RAJATIS") (" kolv*" "KOLVIK" "HALJASTUS") (" hek*" "HEKK" "AED") (" tm*" "KOLVIK" "RELJEEF") (" np*" "NOLVAPEAL" "RELJEEF") (" na*" "NOLVAALL" "RELJEEF") (" kraav*" "KRAAVIPERV" "VEEKOGU") ) ) (while (and (setq str (getstring t "\nInput text : ")) (/= str "")) (foreach x lst (if (wcmatch (strcat " " str) (car x)) ;;; (entmake (list (cons 0 "LINE") ;;; (cons 6 (cadr x)) ;;; (cons 8 (caddr x)) ;;; (cons 10 circle_NEW_coords_1) ;;; (cons 11 circle_NEW_coords_2) ;;; ) ;;; ) (princ (strcat "\n" (vl-princ-to-string (cdr x)))) ) ) (princ) ) ) Edited April 12, 2020 by hanhphuc test code added 1 Quote
ojacomarket Posted April 13, 2020 Author Posted April 13, 2020 On 4/12/2020 at 11:45 AM, hanhphuc said: hi, take a look here BTW, just curious.. (assoc 1 entget_circle1) ??? circle textstring ?? @ojacomarket i prefer assoc list but in your case (cond (bla)( bla)), suggest foreach but your wild card pattern is too common like: " a*" " b*" " r*", you may get multiple result!! Try this simple test, just key-in any word, it princ out LT&Layer if wmatch condition met note: please check if any typos in list ?? it was just quick clipboard edit (defun c:test (/ lst str) (setq lst '((" h*" "HOONEKP" "HOONE") (" hdet*" "HOONEKP" "HOONEDET") (" a*" "ASFBET" "TEE") (" b*" "ASFBET" "TEE") (" kill*" "KRUUSKILL" "TEE") (" ak*" "AAREKIVI" "TEE") (" kt*" "TEERADA" "TEE") (" pt*" "PINNASTEE" "TEE") (" paed*" "LA_AED" "AED") (" aedvund*" "AIAVUND" "AED") (" vaed*" "VO_AED" "AED") (" maed*" "RAKAED" "AED") (" kaed*" "KIVIAED" "AED") (" myyr*" "MYYR" "AED") (" r*" "RAJATISP" "RAJATIS") (" kolv*" "KOLVIK" "HALJASTUS") (" hek*" "HEKK" "AED") (" tm*" "KOLVIK" "RELJEEF") (" np*" "NOLVAPEAL" "RELJEEF") (" na*" "NOLVAALL" "RELJEEF") (" kraav*" "KRAAVIPERV" "VEEKOGU") ) ) (while (and (setq str (getstring t "\nInput text : ")) (/= str "")) (foreach x lst (if (wcmatch (strcat " " str) (car x)) ;;; (entmake (list (cons 0 "LINE") ;;; (cons 6 (cadr x)) ;;; (cons 8 (caddr x)) ;;; (cons 10 circle_NEW_coords_1) ;;; (cons 11 circle_NEW_coords_2) ;;; ) ;;; ) (princ (strcat "\n" (vl-princ-to-string (cdr x)))) ) ) (princ) ) ) Thank you very much for your time and yeah, now I know how to post codes so it will be easier to see, what I had to say hah I will check this code out Quote
ojacomarket Posted April 13, 2020 Author Posted April 13, 2020 On 4/12/2020 at 2:54 AM, BIGAL said: Wow got dizzy with that code an easy way is as you make a circle add the center points to a list. Then draw a single poly line this is the way I normally approach a task like this. If you want to see the poly as you add a circle you will need to make 1st circle out side of while. Then can make 1st pline section. Then add a line as you add a circle lastpt -> newpt then use pedit Join (entlast) so will see it happening. For make 1 pline ; create pline from a list of points ; By Alan H March 2019 (defun AHpllst ( lst / x) (command "_pline") (while (= (getvar "cmdactive") 1 ) (repeat (setq x (length lst)) (command (nth (setq x (- x 1)) lst)) ) (command "") ; for close (command "c") ) ) ; (ahpllst (list '(0 0) '(10 10) '(35 6))) (defun ahaddlstpts ( / ) (setq lst '()) (while (setq pt (getpoint "\nPick point enter to exit")) (setq lst (cons pt lst)) ) ) ; (ahpllst lst) There is another post recently about joining circles only like a week old may be usefull to look at. Thanks for help! I will try that out, btw this is my first serious task, that way an approach is so complicated, that is actually seen from my looooooooooooooong code ;D ;D Quote
Recommended Posts
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.