aaryan Posted June 15, 2012 Posted June 15, 2012 Hi, How can i sort elevations in different colors for every metres while importing in autocad as block attribute from csv files. eg. 500,200,23.1 200,300,23.5 400,700,24.2 350,240,25.3 In the above eg. my blocks when importing should have sorted (23.1,23.5 in as color 1) (24.2 in as color)...and so on. Any help would be highly appreciated. Regards Quote
MSasu Posted June 15, 2012 Posted June 15, 2012 Something like this? (setvar "CECOLOR" (itoa (- (fix theElevation) 22))) Quote
aaryan Posted June 15, 2012 Author Posted June 15, 2012 thanks MSasu I will do the same and let you know... Quote
MSasu Posted June 15, 2012 Posted June 15, 2012 The above example will give you successive colors; if need to use from a list of preferred colors, then may try: (setq colorElevations '("1" "23" "45" "67" "89")) (setvar "CECOLOR" (nth (- (fix theElevation) 23) colorElevations)) For sure, both examples consider 23.0 as reference elevation. Also, may want to add a validation to don't exceed 255 as color index. Quote
aaryan Posted June 15, 2012 Author Posted June 15, 2012 Hi Mircea, Need help again to fit your code in the routine i have... Quote
MSasu Posted June 15, 2012 Posted June 15, 2012 Need help again to fit your code in the routine i have... Then, you should post here the said code - please see the code posting guide. May be useful to mark with a different color the changes that you already did. Quote
aaryan Posted June 15, 2012 Author Posted June 15, 2012 thanks below is the code... (defun c:Bathy (/ tpath fd info Soundings Bs Bsc BSL Pdata data ipt ba tpt x y xs ys) (vl-load-com) (defun *error* (msg) (if msg (princ (strcat "\nError! " msg))) (princ) ) ;//pBe (defun _roundTruncated (a) (setq b (fix a) c (* (abs (- a b)) 10)) (if (= c 0) (setq d 0) (setq d (fix (+ c (/ c (abs c) 2.0)))))) (defun _HiLow (lev lev2 lst) (list (apply lev (mapcar 'car lst)) (apply lev2 (mapcar 'cadr lst)) )) ;// (defun colorelv (lev3 lst) (list (apply lev3 (mapcar 'caddr lst)))) (defun _errormsg ( lst / x ) (if (setq x (vl-some '(lambda ( x ) (if (null (eval (car x))) (cadr x))) lst)) (alert x) ) ) (setvar "cmdecho" 0) (graphscr) (if (and (setq Pdata nil tpath (getfiled "Select XYZ File" "*.*" "txt" 4)) (setq fsz (> (vl-file-size tpath) 0)) (setq Soundings (getfiled "Select Sounding Block" "*.*" "dwg" 4)) (progn (setq Bs (Getreal "\nScale factor for Bathymetry Block <1>:")) (if (= Bs Nil) (setq Bsc 1) (setq Bsc Bs))) ) (progn (setq fd (open tpath "r")) (setq Bsl (rtos Bsc 2 3)) (while (setq info (read-line fd)) (setq Pdata (cons (read (strcat "(" (vl-string-translate "," " " info) ")")) Pdata)) ) (close fd) (command "_.zoom" "w" (_HiLow 'min 'min Pdata)(_HiLow 'max 'max Pdata)) (foreach data Pdata (setq ipt (list (car data) (cadr data)) bat (atof (rtos (caddr data) 2 4)) tpt data) (if (< bat 0) (progn (setq ba (* -1 bat) x (fix ba) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (strcat "%%U" (itoa x)) ys (itoa y)) ) (progn (setq x (fix bat) y (_roundTruncated bat)) (if (= y 10) (progn (setq x (+ x 1) y 0)) (progn (setq x x y y))) (setq xs (itoa x) ys (itoa y)) )) (command "insert" Soundings "_scale" Bsl "_non" ipt 0 xs ys) ) ;(command "zoom" "e") (command "regen") ) (_errormsg '( (tpath "Failed to select Data File") (fsz "Bathy file is empty") (Soundings "Failed to select Block") ) ) ) (*error* nil) (princ) ) For making this routine workable Mr.pBe helped me a lot. If require i will insert the block drawing too.. Regards Aaryan Quote
MSasu Posted June 15, 2012 Posted June 15, 2012 Presuming that Pdata variable store a list of 3D points and the entities inside your block have their color set as ByBlock, then adjust your code: [color=magenta](if (> (setq theColor (- (fix (caddr data)) 22)) 255) (setq theColor 1))[/color] (command "[color=red]_[/color]insert" Soundings "_scale" Bsl "_non" ipt 0 xs ys [color=magenta]"_CHPROP" (entlast) "" "_C" theColor ""[/color]) If there are elevations bigger than 277, then their color will be always red; may need to refine a little the alocation procedure. Quote
MSasu Posted June 15, 2012 Posted June 15, 2012 This will restart the colors when exceed index 255: [color=magenta](setq elevReference 23) (setq theColor (- (fix (rem (caddr data) 254)) (1- elevReference))) [/color](command "[color=red]_[/color]insert" Soundings "_scale" Bsl "_non" ipt 0 xs ys [color=magenta]"_CHPROP" (entlast) "" "_C" theColor ""[/color]) Quote
aaryan Posted June 15, 2012 Author Posted June 15, 2012 Hey Thanks that worked Great... Only Last question what is this 22 belongs to? (- (fix (caddr data)) [b][color="red"]22[/color][/b])) And what if my elevation is 0 or less than zero. Quote
MSasu Posted June 15, 2012 Posted June 15, 2012 That 22 is to account for the case from your first post, where 23 was the starting elevation. Please check this updated solution that will work for any elevation, even negative, with 0 as reference: [color=magenta](setq theColor (1+ (fix (rem (abs (caddr data)) 255))))[/color] (command "_insert" Soundings "_scale" Bsl "_non" ipt 0 xs ys "_CHPROP" (entlast) "" "_C" theColor "") Quote
aaryan Posted June 15, 2012 Author Posted June 15, 2012 Thanks a Lot.. That's what I was looking for the reference start value should be 0. Thanks Again. Regards Aaryan Quote
stevesfr Posted June 15, 2012 Posted June 15, 2012 aaryan, please attach your block, I'd like to experiment with your program. I'm sure it can be useful to many of us. TIA Steve Quote
aaryan Posted June 16, 2012 Author Posted June 16, 2012 SORRY for being very late Steve. I hope you forgive it. I didnt see your post as it was very late last night in my country. Anyways Good Morning.. Please find attached block drawing and if you update this routine please post for me too... Bathymetry.dwg Thanks and Best Regards Aaryan Please do reply... Quote
BIGAL Posted June 16, 2012 Posted June 16, 2012 Didn't study the code to much but it would make sense to have maybe a step colour size say for a big range of elevations colours 10-250, a first pass would find min and max of the blocks and then assign a colour step size this way can not exceed 250, 251-255 a bit dull. eg z = 20 21 22 23 24 step would be say 40 eg2 z= 0-156 1000 pts step = 2 PS CIV3D has rainbow functions for contours not sure about MAP you pick colour range Quote
pBe Posted June 16, 2012 Posted June 16, 2012 Didn't study the code to much but it would make sense to have maybe a step colour size say for a big range of elevations colours 10-250, a first pass would find min and max of the blocks and then assign a colour step size this way can not exceed 250, 251-255 a bit dull. eg z = 20 21 22 23 24 step would be say 40 eg2 z= 0-156 1000 pts step = 2 Can you explain that a bit more Bigal. Quote
aaryan Posted June 16, 2012 Author Posted June 16, 2012 How about finding the minimum positive value from a file and starts color from 1 to the end of positive values and same for the negative values. 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.