tuantrinhdp Posted June 19, 2022 Share Posted June 19, 2022 Hello everyone. I have this problem and need help writing lisp, i want to choose color for polyline based on elevation. Example: - Polyline have elevation: 0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,.... i want to set color ( ex: color green) - Polyline have elevation: 1,2,3,4,6,7,8,9,11,12,13,14,16,17,18,19,21.... i want to set color ( ex: color megenta) test.dwg Quote Link to comment Share on other sites More sharing options...
Steven P Posted June 19, 2022 Share Posted June 19, 2022 (edited) Are all the polylines whole numbers (1 2 etc, not 1.34) and are they all 2d Polylines, not 3D? Second question is what are your abilities to write a LISP like? For example if we gave you a couple of hints would you be able to write this or would you need a nearly complete LISP to do the job Third question, did you search this forum? I am sure I saw similar in the last 2 or 3 months asking the same thing which can be a good starting point to modify7 to what you want. there will of course be someone out there with this as a complete solution, you might get lucky that they post you an answer with that as well -EDIT with the link:- I reckon if you look at this and change the line "(Command "Pline".... " to change the colour that might work but CAD is off today, Sunday you see so I can't check for you Edited June 19, 2022 by Steven P 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 20, 2022 Share Posted June 20, 2022 You would need to set major contour interval, minor contour interval, as the plines do have a Z its feasible, I will say though never had to do it multicoloured in like 40 years. So a bit one off. Will maybe try to find time. 1 Quote Link to comment Share on other sites More sharing options...
exceed Posted June 20, 2022 Share Posted June 20, 2022 (edited) ; ELPOLY - 2022.06.20 exceed ; https://www.cadtutor.net/forum/topic/75461-help-lisp-set-color-for-polyline-based-on-elevation/ ; change lwpolyline's color by it's elevation ; 0, 5, 10, 15, 20... - change to red ; 1, 2, 3, 4, 5, 6, 7... - change to purple ; 1.5, 2.5, 3.5, 4.5, 5.5 ... - change to green ; 1.xxx, 2.xxx, 3.xxx ..... - change to green anyway ; if you want to change 4th option, just change ; (t ; (princ " , so change to green anyway") ; (vlax-put-property obj 'color 3) ; ) ; "3" of this part's after 'color. ; this is autocad indexed color number (vl-load-com) (defun c:ELPOLY ( / ss ssl index obj objelevation ) (if (setq ss (ssget ":L" '((0 . "LWPOLYLINE")))) (progn (setq ssl (sslength ss)) (setq index 0) (repeat ssl (setq obj (vlax-ename->vla-object (ssname ss index))) (setq objelevation (vlax-get-property obj 'elevation)) (princ "\n it's elevation is = ") (princ objelevation) (cond ((= (rem objelevation 5) 0) (princ " , so change to red") (vlax-put-property obj 'color 1) ) ((= (rem objelevation 1) 0) (princ " , so change to purple") (vlax-put-property obj 'color 6) ) ((= (rem objelevation 0.5) 0) (princ " , so change to green") (vlax-put-property obj 'color 3) ) (t (princ " , so change to green anyway") (vlax-put-property obj 'color 3) ) ) (setq index (+ index 1)) ) ) (progn (princ "\n there's nothing to change") ) ) (princ) ) you can start with this Edited June 20, 2022 by exceed 1 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted June 20, 2022 Share Posted June 20, 2022 A quick modification to the link I posted, Same result, slightly different method to exceed - though a blatant copy here for the 'cond' part of his code. (defun c:layerElev ( / ss i pline elevation MyColour) (setq ss (ssget '((0 . "LWPOLYLINE")))) (if ss (progn (setq i -1) (repeat (sslength ss) (setq i (1+ i) pline (ssname ss i) elevation (cdr (assoc 38 (entget pline))) ) (cond ((= (rem elevation 5) 0)(setq MyColour 1)) ((= (rem elevation 1) 0)(setq MyColour 2)) ((= (rem elevation 0.5) 0)(setq MyColour 3)) (t (setq MyColour 1)) ) (command "chprop" pline "" "c" MyColour "") ) ) ) (princ) ) 1 1 Quote Link to comment Share on other sites More sharing options...
tuantrinhdp Posted June 22, 2022 Author Share Posted June 22, 2022 On 6/20/2022 at 11:22 AM, exceed said: ; ELPOLY - 2022.06.20 exceed ; https://www.cadtutor.net/forum/topic/75461-help-lisp-set-color-for-polyline-based-on-elevation/ ; change lwpolyline's color by it's elevation ; 0, 5, 10, 15, 20... - change to red ; 1, 2, 3, 4, 5, 6, 7... - change to purple ; 1.5, 2.5, 3.5, 4.5, 5.5 ... - change to green ; 1.xxx, 2.xxx, 3.xxx ..... - change to green anyway ; if you want to change 4th option, just change ; (t ; (princ " , so change to green anyway") ; (vlax-put-property obj 'color 3) ; ) ; "3" of this part's after 'color. ; this is autocad indexed color number (vl-load-com) (defun c:ELPOLY ( / ss ssl index obj objelevation ) (if (setq ss (ssget ":L" '((0 . "LWPOLYLINE")))) (progn (setq ssl (sslength ss)) (setq index 0) (repeat ssl (setq obj (vlax-ename->vla-object (ssname ss index))) (setq objelevation (vlax-get-property obj 'elevation)) (princ "\n it's elevation is = ") (princ objelevation) (cond ((= (rem objelevation 5) 0) (princ " , so change to red") (vlax-put-property obj 'color 1) ) ((= (rem objelevation 1) 0) (princ " , so change to purple") (vlax-put-property obj 'color 6) ) ((= (rem objelevation 0.5) 0) (princ " , so change to green") (vlax-put-property obj 'color 3) ) (t (princ " , so change to green anyway") (vlax-put-property obj 'color 3) ) ) (setq index (+ index 1)) ) ) (progn (princ "\n there's nothing to change") ) ) (princ) ) you can start with this thank you so much. 1 Quote Link to comment Share on other sites More sharing options...
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.