broncos15 Posted January 25, 2016 Posted January 25, 2016 So I am working on some LISP routines to make using MLINES more enjoyable. My current quickly written code to append the dxf code 40 (which is where the mlines scale is found) is as follows: (defun c:mlwidth () (if (setq ss (LM:ssget "\nSelect multilines: " '("_:L" ((0 . "MLINE"))))) (initget 4) (setq mwidth (cond ((getdist "\nSpecify width for all mlines <0.0>: ")) (0.0))) (setq newdxf '(40 . mwidth)) (setq cnt 0) (repeat (sslength ss) (setq dxfdata (ssname ss cnt)) (setq entdata (entget dxfdata)) (setq dxfdata (subst newdxf olddxf dxfdata)) (entmod dxfdata) (setq cnt (+ 1 cnt)) ) ) ) ;; ssget - Lee Mac ;; A wrapper for the ssget function to permit the use of a custom selection prompt ;; msg - [str] selection prompt ;; arg - [lst] list of ssget arguments (defun LM:ssget (msg arg / sel) (princ msg) (setvar 'nomutt 1) (setq sel (vl-catch-all-apply 'ssget arg)) (setvar 'nomutt 0) (if (not (vl-catch-all-error-p sel)) sel ) ) . I can't figure out why this isn't actually appending the dxf data and it is instead just printing it all to the screen. Does anyone know why? Quote
Lee Mac Posted January 25, 2016 Posted January 25, 2016 A few immediate corrections: (defun c:mlwidth ( [highlight]/ ss mwidth newdxf cnt dxfdata entdata olddxf[/highlight] ) (if (setq ss (LM:ssget "\nSelect multilines: " '("_:L" ((0 . "MLINE"))))) [highlight](progn[/highlight] (initget 4) (setq mwidth (cond ((getdist "\nSpecify width for all mlines <0.0>: ")) (0.0))) (setq newdxf ([highlight]cons[/highlight] 40 mwidth)) (setq cnt 0) (repeat (sslength ss) (setq dxfdata (ssname ss cnt)) (setq entdata (entget dxfdata)) [highlight](setq olddxf (assoc 40 entdata))[/highlight] (setq dxfdata (subst newdxf olddxf dxfdata)) (entmod dxfdata) (setq cnt (+ 1 cnt)) ) [highlight])[/highlight] ) [highlight](princ)[/highlight] ) I would also recommend that you read this tutorial for an understanding of why cons must be used in this circumstance. Lee Quote
broncos15 Posted January 25, 2016 Author Posted January 25, 2016 A few immediate corrections:(defun c:mlwidth ( [highlight]/ ss mwidth newdxf cnt dxfdata entdata olddxf[/highlight] ) (if (setq ss (LM:ssget "\nSelect multilines: " '("_:L" ((0 . "MLINE"))))) [highlight](progn[/highlight] (initget 4) (setq mwidth (cond ((getdist "\nSpecify width for all mlines <0.0>: ")) (0.0))) (setq newdxf ([highlight]cons[/highlight] 40 mwidth)) (setq cnt 0) (repeat (sslength ss) (setq dxfdata (ssname ss cnt)) (setq entdata (entget dxfdata)) [highlight](setq olddxf (assoc 40 entdata))[/highlight] (setq dxfdata (subst newdxf olddxf dxfdata)) (entmod dxfdata) (setq cnt (+ 1 cnt)) ) [highlight])[/highlight] ) [highlight](princ)[/highlight] ) I would also recommend that you read this tutorial for an understanding of why cons must be used in this circumstance. Lee Thanks Lee! I am reading up on the cons function to understand it. Quote
broncos15 Posted January 25, 2016 Author Posted January 25, 2016 Lee, sorry to bug you again, but after reading your post I am still a little confused by the cons function. This is my updated code. I am confused why my use of the cons function and the assoc together don't work. (defun c:mlwidth (/ ss mwidth newdxf cnt dxfdata ent olddxf) (if (setq ss (LM:ssget "\nSelect multilines: " '("_:L" ((0 . "MLINE")))) ) (progn (initget 4) (setq mwidth (cond ((getdist "\nSpecify width for all mlines <0.0>: ")) (0.0) ) ) (setq cnt 0) (repeat (sslength ss) (setq dxfdata (ssname ss cnt)) (setq ent (entget dxfdata)) (setq dxfdata (subst (cons 40 mwidth) (assoc 8 ent) ent)) (entmod dxfdata) (setq cnt (+ 1 cnt)) ) ) ) (princ) ) Quote
broncos15 Posted January 25, 2016 Author Posted January 25, 2016 So I ended up using visual lisp. I just need to get more comfortable with it because it seems like it can make coding much easier. My final code in case people want it in the future is: (defun c:mlwidth (/ ss cnt *error*) (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) ) (princ (strcat "\nError: " msg)) ) (princ) ) (if (not *mwidthans*) (setq *mwidthans* 1.0) ) (if (setq ss (LM:ssget "\nSelect multilines: " '("_:L" ((0 . "MLINE"))))) (progn (initget 4) (setq *mwidthans* (cond ((getreal (strcat "\nSpecify width for all mlines <" (rtos *mwidthans*) ">: ")))(*mwidthans*))) (setq cnt 0) (repeat (sslength ss) (vla-put-MlineScale (vlax-ename->vla-object (ssname ss cnt)) *mwidthans* ) (setq cnt (+ 1 cnt)) ) ) ) (princ) ) ;; ssget - Lee Mac ;; A wrapper for the ssget function to permit the use of a custom selection prompt ;; msg - [str] selection prompt ;; arg - [lst] list of ssget arguments (defun LM:ssget (msg arg / sel) (princ msg) (setvar 'nomutt 1) (setq sel (vl-catch-all-apply 'ssget arg)) (setvar 'nomutt 0) (if (not (vl-catch-all-error-p sel)) sel ) ) 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.