mrharris78 Posted June 21, 2009 Posted June 21, 2009 I wonder if anyone can help on this one? I need a polyline (with the arc/radius function retained) which has 3 elements (Left Side, Central, Right Side) all with colour and width definitions. For example; Left element. Colour – Yellow, Width – 0.1 Central element. Colour – White, Width – 0.2 Right element. Colour – Yellow, Width – 0.1 Hence, Total width 0.4. see attachment. I have tried multiline but this does not work and polylines are more flexible. At the minute, I am doing this by copying and offsetting which is OK if you’re only doing a couple. It is for pavement markings..**yawn** Any help would be much appreciated. Cheers, H Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 Not one of my best, but should do the job :wink: (defun c:rdMark (/ pObj off1 off2) (vl-load-com) (command "_pline") (while (> (getvar "CMDACTIVE") 0) (command pause)) (setq pObj (vlax-ename->vla-object (entlast))) (vla-put-color pObj acWhite) (vla-put-ConstantWidth pObj 0.2) (setq off1 (vlax-safearray->list (vlax-variant-value (vla-offset pObj 0.15))) off2 (vlax-safearray->list (vlax-variant-value (vla-offset pObj -0.15)))) (mapcar (function (lambda (x) (vla-put-color x acYellow) (vla-put-ConstantWidth x 0.1))) (append Off1 Off2)) (princ)) Quote
mrharris78 Posted June 21, 2009 Author Posted June 21, 2009 Lee, That has worked a treat! Well impressed, Genius! - I am inspired to learn this stuff, but for now I think I am competent enough to modify it for different markings Greatly appreciated mate. Harris India. Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 Lee, That has worked a treat! Well impressed, Genius! - I am inspired to learn this stuff, but for now I think I am competent enough to modify it for different markings Greatly appreciated mate. Harris India. Happy to help If you have any questions about the code I posted - just ask. Lee Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 Just as an alternative, another way to phrase the LISP: (defun c:rdMark2 (/ pObj) (vl-load-com) (command "_pline") (while (> (getvar "CMDACTIVE") 0) (command pause)) (setq pObj (vlax-ename->vla-object (entlast))) (vla-put-color pObj acWhite) (vla-put-ConstantWidth pObj 0.2) (mapcar (function (lambda (x) (vla-put-color x acYellow) (vla-put-ConstantWidth x 0.1))) (apply 'append (mapcar (function (lambda (x) (vlax-safearray->list (vlax-variant-value (vla-offset pObj x))))) '(-0.15 0.15)))) (princ)) But, as far as speed goes, mapcar is slow: Elapsed milliseconds / relative speed for 512 iteration(s): (RDMARK OBJ)......25897 / 1.70 (RDMARK2 OBJ).....44023 / 1.00 Also, if you wanted to convert Polylines that are already drawn: (defun c:rdMark3 (/ ss off1 off2) (vl-load-com) (if (setq ss (ssget '((0 . "LWPOLYLINE")))) (foreach pObj (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (vla-put-color pObj acWhite) (vla-put-ConstantWidth pObj 0.2) (setq off1 (vlax-safearray->list (vlax-variant-value (vla-offset pObj 0.15))) off2 (vlax-safearray->list (vlax-variant-value (vla-offset pObj -0.15)))) (mapcar (function (lambda (x) (vla-put-color x acYellow) (vla-put-ConstantWidth x 0.1))) (append Off1 Off2)))) (princ)) Hope this helps Lee Quote
mrharris78 Posted June 21, 2009 Author Posted June 21, 2009 Thanks Lee, That convert lisp (rdmark3) is very useful indeed. I am very much a beginner when it comes to writing lisps, I have few E-Books and reference guides but still very very basic level myself. "Need more practice" I will look over your coding and try to piece together the methodology...(looks a bit advanced at first glance) If I could send you a few pints through this forum I would Cheers for your help. Harris Quote
stevesfr Posted June 21, 2009 Posted June 21, 2009 Not one of my best, but should do the job :wink: (defun c:rdMark (/ pObj off1 off2) (vl-load-com) (command "_pline") (while (> (getvar "CMDACTIVE") 0) (command pause)) (setq pObj (vlax-ename->vla-object (entlast))) (vla-put-color pObj acWhite) (vla-put-ConstantWidth pObj 0.2) (setq off1 (vlax-safearray->list (vlax-variant-value (vla-offset pObj 0.15))) off2 (vlax-safearray->list (vlax-variant-value (vla-offset pObj -0.15)))) (mapcar (function (lambda (x) (vla-put-color x acYellow) (vla-put-ConstantWidth x 0.1))) (append Off1 Off2)) (princ)) Lee, if I wanted to construct the line with say yellow on one side and another color on the other side of the center white, would I have to use mapcar twice and then append off1 and off2 separately with color statement? (or give me a clue?) Steve Quote
ronjonp Posted June 21, 2009 Posted June 21, 2009 Lee, if I wanted to construct the line with say yellow on one side and another color on the other side of the center white, would I have to use mapcar twice and then append off1 and off2 separately with color statement? (or give me a clue?) Steve Maybe this will help since the mapcar tends to confuse: (defun c:rdMark (/ pObj off1 off2) (vl-load-com) (command "_pline") (while (> (getvar "CMDACTIVE") 0) (command pause) ) (setq pObj (vlax-ename->vla-object (entlast) ) ) (vla-put-color pObj acWhite) (vla-put-ConstantWidth pObj 0.2) (setq off1 (car (vlax-invoke pobj 'offset 0.15))) (setq off2 (car (vlax-invoke pobj 'offset -0.15))) (vla-put-ConstantWidth off1 0.1) (vla-put-ConstantWidth off2 0.1) (vla-put-color off1 2) (vla-put-color off2 (acad_colordlg 1)) (princ) ) Quote
CAB Posted June 21, 2009 Posted June 21, 2009 That's the way I would probably handle the code. Also note that when you are processing small amounts of data the speed is usually not an issue using today's computers. Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 That's the way I would probably handle the code. Also note that when you are processing small amounts of data the speed is usually not an issue using today's computers. True, I just included it out of a matter of interest Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 Lee, if I wanted to construct the line with say yellow on one side and another color on the other side of the center white, would I have to use mapcar twice and then append off1 and off2 separately with color statement? (or give me a clue?) Steve Mapcar is used to perform an operation on a list of elements, hence, in this case, a list of VLA-OBJECTs (the objects that have been offset). Take a look at Ron's code - you will see that he has handled each offset object separately, hence no use of mapcar. Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 That convert lisp (rdmark3) is very useful indeed. I am very much a beginner when it comes to writing lisps, I have few E-Books and reference guides but still very very basic level myself. "Need more practice" I will look over your coding and try to piece together the methodology...(looks a bit advanced at first glance) I am using a combination of AutoLISP and Visual LISP here, (hence all the vlax- functions...), I would suggest you start with a bit of AutoLISP and teach yourself with maybe a mixture of tutorial sites such as: http://www.afralisp.net/ http://www.jefferypsanders.com/autolisptut.html http://ronleigh.info/autolisp/ And if you get stuck, just post a thread on the forum, and I'm sure we can lend a hand Lee Quote
CAB Posted June 21, 2009 Posted June 21, 2009 Your flexibility with LISP has grown so fast, Keep it up. Seems like only a month or so ago I heard you say you didn't want to get into visualLISP just yet. Quote
Lee Mac Posted June 21, 2009 Posted June 21, 2009 Your flexibility with LISP has grown so fast, Keep it up.Seems like only a month or so ago I heard you say you didn't want to get into visualLISP just yet. Thanks Alan, I remember posting that thread in here talking about my first VL program... and how I'd always wanted to avoid it - but it really does make life so much easier, with so much more flexibility than the standard AutoLISP. The learning curve has indeed been extremely steep, all the methods seem to follow from each other, and, once you have grasped the properties of such things as variants and safearrays, things become a lot clearer. But, I've got to admit, I haven't used any tutorial sites to learn VL, only this site and TheSwamp. Just learning from code posted by others is priceless. Thanks for your continued help and guidance, Lee EDIT: end of January this year in fact... 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.