Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/27/2022 in all areas

  1. @mhupp, Just a small remark - for future better practice (challenges) : This line : (setq lst (mapcar '(lambda (x) (list (cdr (assoc 1 (entget x))) (cdr (assoc 10 (entget x))))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))))) Consider : (setq lst (mapcar '(lambda (x / enx) (list (cdr (assoc 1 (setq enx (entget x)))) (cdr (assoc 10 enx)))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))))) Your verison does the same, but it' not 100% efficient... Tharwat is doint the same, but he is smartly avoiding getting DXF data twice (or more times)... In essence (entget) function calls that are unnecessary should be avoided as much as possible... The same is with (ssnamex) and perhaps with (nth) in comparison with (cdr), (car), (cadr), ... And from my experience, also when coding, try to avoid (member) function over (vl-position)... (member) will do it if you want to test presence of element in a list, but it is also getting you all elements reminders - outpur/return is also list, just truncated; in other hand (vl-position) will just return you integer number representing element position in checking list, thus much, much more faster - i.e. (if it returns number, than element belongs to list, and if it's nil not)... Here, just for better understanding - in many situations, you'll have to find presence of element in a list, but not with exact matching of values - for ex. point (10.0 10.0 10.0) belongs to list ((10.0 10.0 10.0) (10.1 10.1 10.1) ... ), but you obtained point with picking "nea" OSNAP near vertex (10.0 10.0 10.0) of a BOX [(0.0 0.0 0.0) (10.0 10.0 10.0)]... Now you need to find if point belongs to list : sometimes (member pt lst) => nil, and also (vl-position pt lst) => nil ;... Then what's the trick!!! Well, to overcome this cases, you just have to use different ones that do the same similar : 1. (member) ... => (vl-member-if) 2. (vl-position) ... => (vl-some) Here is how : 1. (vl-member-if '(lambda ( x ) (equal x pt fuzz)) lst) ;;; fuzz (1e-6) ;;; but like I stated - (vl-member-if) will yield you also a truncated list just like (member)... So as opposed to this in search for efficiency, the best approach is : 2. (vl-some '(lambda ( x ) (equal x pt fuzz)) lst) Those are just a few tricks for you to consider... In some occaisons, you may stumble at situation where you should use multiple (vl-some) calls nested in each other - nested iterations/recursions... And to get the fastest looping terminations with resulting outcomes (checked element - obtained), you'll see that (vl-some) has very justified appliance... To get element from list by using (vl-some), just use this snippet : (vl-some '(lambda ( x ) (if (equal x pt fuzz) x)) lst) ;;; here x element from lst was returned opposed to checking reference element pt - also fuzz factor is involved for better comparison operations... Note that [else] statement from (if) is nil - forcing (vl-some) to continue with checking iterations all the way until complete lst was processed... If no matching found (vl-some) retuns nil also, but if (vl-some) detects matching, then result is that element X, and termination occurs imidiately when matching happened - that means if lst = (x a b c d ... ), and you apply (vl-some), you'll get X in 0.00001 millisecond, but if you have lst = (a1 a2 a3 ... a9999999 a10000000 x), (vl-some) would have to do checkings all the way until it gets X - last one... So in this and similar cases, you'll have to give appropriate feeding instruction to (vl-some), i.e. you should (reverse) lst beforehand : (setq lst (reverse lst))...
    2 points
  2. Try this. (defun c:Test (/ int sel ent get lst) ;; Tharwat - Date: 27.Feb.2022 ;; (and (princ "\nSelect single texts : ") (setq int -1 sel (ssget '((0 . "TEXT") (1 . "*#"))) ) (or (< 1 (sslength sel)) (alert "Must select two texts at least to continue <!>") ) (while (setq int (1+ int) ent (ssname sel int) ) (setq get (entget ent) lst (cons (list (read (cdr (assoc 1 get))) (cdr (assoc 10 get)) ) lst ) ) ) (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) '(70 . 0) ) (mapcar (function (lambda (p) (cons 10 (cadr p)))) (vl-sort lst '(lambda (j k) (< (car j) (car k)))) ) ) ) ) (princ) ) (vl-load-com)
    2 points
  3. My take using mhupp code. Make sure Multi getvals.lsp is in a support directory, if you dont know what that means post and will provide more info. (vl-load-com) ;not needed if you dont use vla-get-area (if (not AH:getvalsm)(load "Multi Getvals.lsp")) (setq ans (AH:getvalsm (list "Enter values " "Length " 5 4 "10" "Width " 5 4 "5"))) (setq l (atoi (car ans)) W (atoi (cadr ans))) ; (setq l (getdist "\nRectangle Lenght: ")) ;have to remove rtos to keep them integers so they can be used to calculate pt3 ; (setq w (getdist "\nRectangle Width: ")) ;getdist allows for 2' if you used getint you would have to input 24 (if (setq pt1 (getpoint "\nPick Bottom Left Corner: ")) (setq pt3 (list (+ (car pt1) l) (+ (cadr pt1) w)) pt2 (list (car pt3) (cadr pt1)) pt4 (list (car pt1) (cadr pt3))) ) (command "_.Rectangle" pt1 pt3) (setq myrecarea (vla-get-area (vlax-ename->vla-object (entlast)))) ;or (setq myrecarea (* l w)) ;dont have to calculate length and width user already defined them Multi GETVALS.lsp
    1 point
  4. So, you want to go from a circle to a rectangle. Have you tried the LOFT command?
    1 point
  5. 1 point
  6. The code worked in BricsCAD. after googling error message seems to be a vl-cmdf and probably could have just changed to "command" but i don't know. updated to entmake to avoid using command or vl-cmdf altogether. that's usually the best bet.
    1 point
  7. ;;----------------------------------------------------------------------------;; ;; DRAW POLYLINE IN NUMERICAL ORDER (defun c:Foo (/ SS lst) (if (and (setq SS (ssget '((0 . "TEXT") (1 . "*#")))) (> (sslength SS) 1)) ;Tharwat (progn (setq lst (mapcar '(lambda (x) (list (cdr (assoc 1 (entget x))) (cdr (assoc 11 (entget x))))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))))) (setq lst (vl-sort lst '(lambda (a b) (< (car a) (car b))))) (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) '(70 . 0) ) (mapcar '(lambda (x) (cons 10 (cadr x))) lst) ) ) ) (prompt "\nNothing Selected") ) (princ) )
    1 point
  8. Your texts have to be single texts to be able to select them and besides that they should end with digit. (defun c:Test (/ int sel ent get lst) ;; Tharwat - Date: 26.Feb.2022 ;; (and (princ "\nSelect single texts : ") (setq int -1 sel (ssget '((0 . "TEXT") (1 . "*#")))) (or (< 1 (sslength sel)) (alert "Must select two texts at least to continue <!>") ) (while (setq int (1+ int) ent (ssname sel int)) (setq get (entget ent) lst (cons (list (atoi (substr (cdr (assoc 1 get)) 2)) (cdr (assoc 10 get)) ) lst ) ) ) (entmake (list '(0 . "LINE") (cons 10 (cadar (setq lst (vl-sort lst '(lambda (j k) (< (car j) (car k))))))) (cons 11 (cadar (reverse lst))) ) ) ) (princ) ) (vl-load-com)
    1 point
  9. Using accoreconsole would be the way to go there is example of modifying a directory. That is part 1. The accoreconsole opens a dwg then runs a script, so the 2nd part is 3xburst purge save close in a script https://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console.html
    1 point
×
×
  • Create New...