Leaderboard
Popular Content
Showing content with the highest reputation on 08/30/2018 in all areas
-
Not quite, this was a "standalone" demo of the concept. I'm not sure I understand exactly what you want to do... you want to replace the increment addition of 8 that is in the while, and choose the block at the beginning, right? You will need to add the paramlst on the first setq call (with cdoc, ms...) along with the user's choice. Don't forget that setq can set any amount of variables at once....: (progn (setq paramlst '(("block1" . 3)("block2" . 5)("block3" . 8))) (setq bname "block1") (setq dist (cdr (assoc bname paramlst))) ) ;is the same as (setq paramlst '(("block1" . 3)("block2" . 5)("block3" . 8)) bname "block1" dist (cdr (assoc bname paramlst)) ) Basically at the beginning the variables are setq'ed on a single setq call, which mean that if you want to add the paramlst variable inside, you have to exclude the setq, like that: (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) ms (vla-get-modelspace c_doc) obj (vlax-ename->vla-object (car (entsel "\nSelect arc, line, spline or polyline : "))) e_pt (vlax-curve-getendpoint obj) p_len (vlax-curve-getdistatpoint obj e_pt) dist 0 paramlst '(("block1" . 3)("block2" . 5)("block3" . 8)) );end_setq Now for the user choice, we need to put it in a variable, but since we need to use initget first, we will do it just after the original setq. For the initget we will use 1 as the first argument to prevent the user to return "" if he hits enter. For the 2nd argument we need to give it a string made of all the choices separated by a space (like this "block1 block2 block3"). After that we will use getkword, which need as an argument a string containing all choices separated by /, all of it enclosed in square brackets (like this "[block1/block2/block3]"). Since this is driven by the list of choices in the paramlst variable, and we wont want to need to update both initget and getkword strings each time we add a choice in paramlst, we will make both initget and keywork dynamic and automatic. Try to follow the logic step by step of what I did to get from paramlst to the 2 required strings. (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) (mapcar 'car paramlst))))) (i wont be using code tags to be able to bold parts and add colors to show you step by step evaluation of if. Don't bite me Hulk!) (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) (mapcar 'car paramlst))))) Paramlst contains (("block1" . 3) ("block2" . 5) ("block3" . 8)) (mapcar 'car paramlst) will return ("block1" "block2" "block3"), a list made of the car of each of the list elements. (initget 1 (vl-string-right-trim " " (apply 'strcat (mapcar '(lambda (x) (strcat x " ")) '("block1" "block2" "block3") ) ))) (mapcar '(lambda (x) (strcat x " ")) '("block1" "block2" "block3")) will return ("block1 " "block2 " "block3 "), a list made of the a concatenation of each string with a space (initget 1 (vl-string-right-trim " " (apply 'strcat '("block1 " "block2 " "block3 ") ) )) (apply 'strcat '("block1 " "block2 " "block3 ") ) will return "block1 block2 block3 ", which is the equivalent of (strcat "block1 " "block2 " "block3 ") (initget 1 (vl-string-right-trim " " "block1 block2 block3 " )) (vl-string-right-trim " " "block1 block2 block3 " ) will remove any space at the right of the string and will return "block1 block2 block3". And now we are left with (initget 1 "block1 block2 block3") For the getkword, I took the same approach but used "/" instead of a space " " in the strcat and vl-string-right-trim, but had to add the square brackets hence the extra strcat "[" string "]". Since we will use the value later, the returned value of getkword could be stored in a variable. (setq bname (getkword (strcat "[" (vl-string-right-trim "/"(apply 'strcat (mapcar '(lambda (x) (strcat x "/")) (mapcar 'car paramlst)))) "]" ) )) Now the only part left to be done is to use the block name from the getkword stored in bname variable rather than the name "block1" currently used in the vla-insert-block, and localize the new variables, paramlst and bname. Try to do it first than compare with this... ; original code by Dlanorh July 2018 ;with some modifs by Jef! made on the following thread ;https://www.cadtutor.net/forum/topic/65895-creating-presets/ (defun c:mes (/ c_doc ms obj e_pt p_len dist i_pt i_param b_ang n_obj o_lst paramlst bname) (vl-load-com) (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) ms (vla-get-modelspace c_doc) obj (vlax-ename->vla-object (car (entsel "\nSelect arc, line, spline or polyline : "))) e_pt (vlax-curve-getendpoint obj) p_len (vlax-curve-getdistatpoint obj e_pt) paramlst '(("block1" . 3) ("block2" . 5) ("block3" . 8));Jef! dist 0 );end_setq (initget 1 (vl-string-right-trim " "(apply 'strcat (mapcar '(lambda (x) (strcat x " ")) (mapcar 'car paramlst)))));Jef! (setq bname (getkword (strcat "["(vl-string-right-trim "/"(apply 'strcat (mapcar '(lambda (x) (strcat x "/")) (mapcar 'car paramlst))))"]")));Jef! (while (< dist p_len) (setq i_pt (vlax-curve-getpointatdist obj dist) i_param (vlax-curve-getparamatpoint obj i_pt) b_ang (angle '(0 0 0) (vlax-curve-getfirstderiv obj i_param)) n_obj (vla-insertblock ms (vlax-3d-point i_pt) bname 1.0 1.0 1.0 b_ang); Jef! - we insert bname instead of "block1" o_lst (cons n_obj o_lst) dist (+ dist (cdr (assoc bname paramlst)));;;now we get dist increment from paramlst using bname );end_setq );end_while (initget "Yes No") (if (= (getkword "Flip Block? [Yes / No] : ") "Yes") (foreach n_obj o_lst (vlax-put-property n_obj 'rotation (+ (vlax-get-property n_obj 'rotation) pi)) );end_foreach );end_if );end_defun2 points
-
Something like this perhaps? (defun coords ( lst ) (if (and lst (listp lst)) (if (and (< 1 (length lst) 4) (vl-every 'numberp lst)) (list lst) (append (coords (car lst)) (coords (cdr lst))) ) ) )2 points
-
1 point
-
Another (defun coords (lst) (apply 'append (mapcar '(lambda (x) (cond ((atom x) nil) ((vl-every 'numberp x) (list x)) ((coords x)) ) ) lst ) ) )1 point
-
(defun foo ( L / pointp r) (defun pointp ( p ) (and (vl-consp p) (= 3 (length p)) (apply 'vl-every (cons 'numberp (list p))))) (while L (setq r (append (vl-remove-if-not 'pointp L) r)) (setq L (apply 'append (vl-remove-if-not 'vl-consp L))) ); while r ); defun foo _$ (equal (coords lst) (foo lst) 1e-2) T The above check equals to (vl-consp lst) (defun f ( L ) (cond ( (atom L) nil) ( (append (f (car L)) (f (cdr L))) ) ( (and (= 3 (length L)) (vl-every 'numberp L)) (list L) ) ) )1 point
-
Hi loody. This seems the perfect candidate for the assoc function. Just build a list made of block name/dist associated lists. That way you can dynamically retrieve the dist from the assoc using the block name as the key. Not duplicating routines is the best way to avoid discrepancies if you need to make modifications... (progn (setq paramlst '(("block1" . 3)("block2" . 5)("block3" . 8))) (setq bname "block1") (setq dist (cdr (assoc bname paramlst))) ) Cheers1 point
-
Ah, I might have forgotten to mention other arbitrary decided criteria, such as "only 1 function" and "no subfunctions".. because (defun keepcoords ( L / helper ret) (defun helper ( L ) (if (listp L) (if (and (atom (car L)) (numberp (car L)) (atom (cadr L)) (numberp (cadr L)) (atom (caddr L)) (numberp (caddr L)) (= 3 (length L)) ) (setq ret (cons L ret));L (mapcar '(lambda (x) (helper x) ) L ) ) ) ) (helper L) ret ) seems less elegant than a simple building recursion. But it works. Still, feel free to post if you can find a way to achieve it in a single function.1 point
-
I use SOLVIEW/SOLDRAW, SOLPROF and SECTIONVIEW if setting up a Viewport doesn't work. Viewbase on large 3D drawings seem to be very large in file size for me.1 point
-
To think of it, maybe it is caused by the chosen syntax highlight. I noticed that HTML (the one by default) sometimes gives weird results, like when you have in VLIDE a quote mismatch, and everything turns the color of a string. Obviously by choosing something other than "no highlight syntax", it might look for a number of parameters, closing bracket like } and since it is never found, the html color highlight tags might get mismatched, superposed etc... *poking David* Is it possible to make No Syntax Highlighting the default choice for everyone in the code pasting window?1 point
-
1 point
-
I would use a batch file like the one below setLocal EnableDelayedExpansion SET count= for /f "tokens=* delims= " %%x in (c:\Temp\filelist.csv) do ( REM ["-----template file to be copyed-----"]["-----location of new files-----\%%x"] cOPY "[color="red"]Template File[/color]" "[color="red"]New file location[/color]\%%x" /y ) endlocal The filelist.csv would have to be in the following format. drawing 1.dwg drawing 2.dwg drawing 3.dwg drawing 4.dwg drawing 5.dwg1 point