Leaderboard
Popular Content
Showing content with the highest reputation on 12/30/2025 in Posts
-
Greetings to all members of Cad Tutor, Based on the upcoming holidays and New Year, I'v made something interesting which I want it to share with you. Everything was made using a Lisp. I hope it will interesting to all of you and maybe give some inspiration to the next year to made something different and share it with rest of us . Notice (it is on cyrillic, in Serbian language): - ЗИМСКА СЛУЖБА = Winter service on roads; - СРЕЋНА НОВА ГОДИНА = HAPPY NEW YEAR; - XO-XO-XOO = HO-HO-HOO (). Happy New Year 2026 to all members, and wish you all the best and new codes . NovaGodina2026_CadTutor.mp4 Best regards, Saxlle.2 points
-
1 point
-
My 0.02¢ sprinkle some code in updates a variable through out the code. and recall it with error trapping This will show Error# 4 : bad argument type <(40)> ; expected <NUMBER> at [DXF/XED data] this error message would tell you to look after (setq x "4") for the error. (defun c:CIR (/ cen rad) (defun *error* (msg) (if (not (member msg '( "Function cancelled" "quit / exit abort"))) (princ (strcat "\nError# " x " : " msg)) ) (princ) ) (setq x "1") (setq cen (getpoint "\nSpecify center point: ")) (setq x "2") (if cen (progn (setq x "3") (setq rad (getdist cen "\nSpecify radius: ")) (setq x "4") (if rad (entmake (list '(0 . "CIRCLE") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 10 cen) (cons 40 ra))) ) (setq x "5") ) ) (setq x "6") (princ) ) -edit guess this is more steps then what Steven P posted. Also remember someone saying that zwcad can't use some vl commands.1 point
-
Like Steven P often use an Alert so it stops and can see where it got to. I tend to test code as I make it so I don't write all the code then test, If using defuns in main code test them by using Setq to set the value of the variables used in the defun and I use copy code and paste to command line to run a few lines at a time. The obvious problem I use Notepad++, is check for open and close bracket matching as I create code. I think it was ZWCAD that wrote VBA code when using macro record am I correct ?1 point
-
A couple of LISPs, PurgeZeroLengths and PurgeZeroTexts: Note that purgezerolengths has a 'less than a length' for very short lines, here set at 0.01 - comment that out with ;; at the beginning of the line if not needed. These remove orphaned lines and texts. Copy and paste to a new drawing (top left -> bottom right seletion) or wblock does a lot. If not needed delete points - don't show up on the printed page, and if not needed get rid. Bit more effort but using blocks for repeated objects can remove some bloating. If you don't need them to be polylines, explode 2 vertex polylines into lines (2nd LISP box below). Explode heavy polylines into LW polylines of you can, both smaller file sizes One I have tucked away, join perpendicular lines back together - example convert from PDF, dashes are individual lines, this will go some way to recreating them as lines - run after 2 vertex poly to line (3rd LISP box, not perfect, only does H or V lines) (defun c:PurgeZeroLengths ( / MySS DelSS MyEnt EndA EndB) ;; for within blocks (setq MySS (ssget (list (cons 0 "LINE,SPLINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,ELLIPSE")))) (setq acount 0) (setq DelSS (ssadd)) (while (< acount (sslength MySS)) (setq MyEnt (ssname MySS acount)) (if (equal (vlax-curve-getDistAtParam MyEnt (vlax-curve-getEndParam MyEnt)) 0) (progn (setq DelSS (ssadd MyEnt DelSS)) ) ) ; end if ;;If less then a length (if (< (vlax-curve-getDistAtParam MyEnt (vlax-curve-getEndParam MyEnt)) 0.01) (progn (setq DelSS (ssadd MyEnt DelSS)) ) ) ; end if (setq acount (+ acount 1)) ) ; end while (princ "\nDeleting ")(princ (sslength DelSS))(princ " lines") (command "erase" DelSS "") (princ) ) (defun c:PurgeZeroTexts ( / MySS DelSS MyEnt MyText) ;; for within blocks (setq MySS (ssget (list (cons 0 "*TEXT")(cons 1 "")))) (setq acount 0) (setq DelSS (ssadd)) (if MySS (progn (while (< acount (sslength MySS)) (setq MyEnt (ssname MySS acount)) (setq MyText (cdr (assoc 1 (entget MyEnt)))) (if (equal MyText "") (progn (setq DelSS (ssadd MyEnt DelSS)) ) ) ; end if (setq acount (+ acount 1)) ) ; end while (princ "\nDeleting ")(princ (sslength DelSS))(princ " lines") (command "erase" DelSS "") ) ; end progn (progn (princ "No zero content texts found") ) ) ; end if (princ) ) (defun c:pdfDashed2PL ( / MyEnt MySS EndA EndB LEndA LEndB Orientation acount EndPoints LineLengths) ;; Selects by layer and colour (defun LoadLineType (doc LineTypeName FileName) ;;https://www.cadtutor.net/forum/topic/76557-load-linetypes-from-lisphelp/ (if (and (not (existLinetype doc LineTypeName)) (vl-catch-all-error-p (vl-catch-all-apply 'vla-load (list (vla-get-Linetypes doc) LineTypeName FileName) )) ; end vl-catch ) ; end and nil T ) ; end if ) ; end defun (defun existLinetype (doc LineTypeName / item loaded) (vlax-for item (vla-get-linetypes doc) (if (= (strcase (vla-get-name item)) (strcase LineTypeName)) (setq loaded T) ) ) ) (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark thisdrawing) ;;Load Line Types (LoadLineType ThisDrawing "Dashed" "acad.lin") (LoadLineType ThisDrawing "Center" "acad.lin") ;;Select Reference Line (while (= MyEnt nil) (setq MyLine (car (entsel "\nSelect reference Line"))) (if (= MyLine nil) (princ "\nPity the fool, nothing selected. ") (setq MyEnt (entget MyLine)) ) ) ; end while ;;Work out 2 end points (if (= (cdr (assoc 0 MyEnt)) "LINE") (progn (setq EndA (cdr (assoc 10 MyEnt))) (setq EndB (cdr (assoc 11 MyEnt))) ) ; end progn (progn (setq EndA (cdr (assoc 10 MyEnt))) (setq EndB (cdr (assoc 10 (reverse MyEnt)))) ) ; end progn ) ; end if ;;Work out orientation (if (equal (car EndA) (car EndB) 0.0001) (progn (setq Orientation "V") ; Orientation (setq SSFilter "=,*,*") ; SSGET filter (setq EnFilter1 "caddr"); CAR / CADR Filter for entity (setq EnFilter2 "cadr") ; CAR / CADR Filter for entity ) ) (if (equal (cadr EndA)(cadr EndB) 0.0001) (progn (setq Orientation "H") (setq SSFilter "*,=,*") (setq EnFilter1 "cadr") (setq EnFilter2 "caddr") ) ) ;; Get Selection Set (if (= Orientation nil) (progn (princ "Selected line is not orthogonal") ) ; end progn no orientation (progn (princ "\nSelect Broken line: ") (if (assoc 62 MyEnt) (setq MySS (ssget (list (cons 0 "*LINE")(assoc 8 MyEnt)(assoc 62 MyEnt)(cons -4 SSFilter) (cons 10 EndA) ))) (setq MySS (ssget (list (cons 0 "*LINE")(assoc 8 MyEnt)(cons -4 SSFilter) (cons 10 EndA) ))) ) ;; Delete non ortho from SS (setq acount (sslength MySS)) (setq EndPoints (list)) (setq LineLengths (list)) (while ( > acount 0) (setq AnEnt (entget (ssname MySS (- acount 1)))) (setq LEndA (assoc 10 AnEnt)) (if (= (cdr (assoc 0 AnEnt)) "LWPOLYLINE") (progn (setq LEndB (assoc 10 (reverse AnEnt))) ) (progn (setq LEndB (assoc 11 AnEnt)) ) ) ; end if (if (and (equal ((eval (read EnFilter2)) LEndA) ((eval (read EnFilter2)) (assoc 10 MyEnt)) 0.0001) (equal ((eval (read EnFilter2)) LEndB) ((eval (read EnFilter2)) (assoc 10 MyEnt)) 0.0001) ) ; end and (progn ;;Lines to join in SS (setq EndPoints (cons ((eval (read EnFilter1)) LendA) EndPoints)) (setq EndPoints (cons ((eval (read EnFilter1)) LendB) EndPoints)) (setq LineLengths (cons (distance (cdr LendA) (cdr LendB)) LineLengths)) ) (progn ;; Remove lines from SS (setq MySS (ssdel (ssname MySS (- acount 1)) MySS)) ;; Remove line from selection set ) ; end progn ) ; end if (setq acount (- acount 1)) ) ; end while (setq EndPoints (vl-sort EndPoints '<)) ; order small to large ;;Modify Reference Line (if (< ((eval (read EnFilter1)) EndA)((eval (read EnFilter1)) EndB)) (progn (if (= (cdr (assoc 0 MyEnt)) "LINE") (if (= Orientation "H") (progn (setq MyEnt (subst (cons 11 (list (car EndPoints) (cadr EndA) (caddr EndA))) (assoc 11 MyEnt) MyEnt )) (setq MyEnt (subst (cons 10 (list (last EndPoints) (cadr EndB) (caddr EndB))) (assoc 10 MyEnt) MyEnt )) (entmod MyEnt) ) ; end progn (progn (setq MyEnt (subst (cons 11 (list (car EndA) (car EndPoints) (caddr EndA))) (assoc 11 MyEnt) MyEnt )) (setq MyEnt (subst (cons 10 (list (car EndA) (last EndPoints) (caddr EndB))) (assoc 10 MyEnt) MyEnt )) (entmod MyEnt) ) ; end progn ) ; end if (if (= Orientation "H") (progn (setq MyEnt (subst (cons 10 (list (car EndPoints) (cadr EndA))) (assoc 10 (reverse MyEnt)) MyEnt )) (setq MyEnt (subst (cons 10 (list (last EndPoints) (cadr EndB))) (assoc 10 MyEnt) MyEnt )) (entmod MyEnt) ) ; end progn (progn (setq MyEnt (subst (cons 10 (list (car EndA) (car EndPoints))) (assoc 10 MyEnt) MyEnt )) (setq MyEnt (subst (cons 10 (list (car EndA) (last EndPoints))) (assoc 10 (reverse MyEnt)) MyEnt )) (entmod MyEnt) ) ; end progn ) ; end if ) ; end if line ;; (princ "\nEnd A smaller") ) ;end progn (progn (if (= (cdr (assoc 0 MyEnt)) "LINE") (if (= Orientation "H") (progn (setq MyEnt (subst (cons 11 (list (car EndPoints) (cadr EndA) (caddr EndA))) (assoc 11 MyEnt) MyEnt )) (setq MyEnt (subst (cons 10 (list (last EndPoints) (cadr EndB) (caddr EndB))) (assoc 10 MyEnt) MyEnt )) (entmod MyEnt) ) (progn (setq MyEnt (subst (cons 11 (list (car EndA) (car EndPoints) (caddr EndA))) (assoc 11 MyEnt) MyEnt )) (setq MyEnt (subst (cons 10 (list (car EndA) (last EndPoints) (caddr EndB))) (assoc 10 MyEnt) MyEnt )) (entmod MyEnt) ) ) (if (= Orientation "H") (progn (setq MyEnt (subst (cons 10 (list (car EndPoints) (cadr EndA))) (assoc 10 MyEnt) MyEnt )) (setq MyEnt (subst (cons 10 (list (last EndPoints) (cadr EndB))) (assoc 10 (reverse MyEnt)) MyEnt )) (entmod MyEnt) ) (progn (setq MyEnt (subst (cons 10 (list (car EndA) (car EndPoints))) (assoc 10 (reverse MyEnt)) MyEnt )) (setq MyEnt (subst (cons 10 (list (car EndA) (last EndPoints))) (assoc 10 MyEnt) MyEnt )) (entmod MyEnt) ) ) ) ; end if line ;; (princ "\nEnd B smaller") ) ; end progn ) ; end if smaller ;; set MyEnt to line type - dashed / centre (setq LineLengths (vl-sort LineLengths '<)) ; order small to large (if (< (* 2 (cadr LineLengths))(cadr (reverse LineLengths))) ; 2nd longest line 2x longer than 2nd shorted line (vla-put-Linetype (vlax-ename->vla-object MyLine) "Center") (vla-put-Linetype (vlax-ename->vla-object MyLine) "Dashed") ) (setq MySS (ssDel MyLine MySS)) (command "erase" MySS "") ) ; end progn H or V ) ; end if Orientation H or V (vla-Endundomark thisdrawing) (princ) )1 point
