Mobillosmanden Posted November 20, 2012 Posted November 20, 2012 Hi all I was wondering if anyone knows of a lisp code to hatch squares, i have a textfile with xyz coordinates and a color code, the coordinates are in the center of all the squares. what i would like is to hatch the squares with a specific color, defined in the text file. Can anyone help to make this. (theres a lot of squares that needs to colored) thanks in advance. Quote
pBe Posted November 20, 2012 Posted November 20, 2012 post a line from the text file mobillosmanden. Welcome to CADTutor Quote
Mobillosmanden Posted November 20, 2012 Author Posted November 20, 2012 The text file looks like this Pkt nr.,Y,X,Z,Kode,HzAcc,VAcc,Sat 1,117565.462,249849.358,10.777,180,0.024,0.032,4 2,117525.462,249869.358,10.777,140,0.024,0.032,4 where kode is the color. hope this makes it easier and thank you for the nice welcome Quote
Mobillosmanden Posted November 20, 2012 Author Posted November 20, 2012 No pattern just solid color if its possible naming the layer after the color no scale just 1:1 Quote
pBe Posted November 20, 2012 Posted November 20, 2012 Dont have CAD now. Set pattern name : (setvar 'HPNAME "Solid") Zoom Extents : Zoom E Read the file : read-line Parse the data : from string to list (search this forum) Here ->> http://www.cadtutor.net/forum/showthread.php?61040-Routine-to-copy-data-from-one-ATTRIBUTE-to-another LM:str->lst Use Bhatch : point from parsed data list Quote
Mobillosmanden Posted November 20, 2012 Author Posted November 20, 2012 hmm im just a simple noob, regarding lisp i will try and see if i can figure this out. but if someone is willing too help assemple this code i will be great full. Quote
Tharwat Posted November 20, 2012 Posted November 20, 2012 You mentioned earlier that the number in red is indicated to the number of the color , so what about the rest of line ? can you divide the numbers into x y and z and Color code and SO ON ? 1,117565.462,249849.358,10.777,180,0.024,0.032,4 And finally , what about the squares to be selected ? Thanks Quote
pBe Posted November 20, 2012 Posted November 20, 2012 hmm im just a simple noob, regarding lisp i will try and see if i can figure this out. but if someone is willing too help assemple this code i will be great full. I'll get back to you tomorrow. Quote
Mobillosmanden Posted November 20, 2012 Author Posted November 20, 2012 Tharwat the line is divided, seperator is comma the first number is the point number, the second is Y coordinate, the next one is X coordinate, the next is Z coordinate, and the one in red is color number, the rest of the numbers is from the GPS device, they are not in use. the squares varies in size, but the point number(coordinates) is allways placed in the center of the squares pBe i will look forward to that Quote
MSasu Posted November 20, 2012 Posted November 20, 2012 You can build a script in Excel using instructions given by @pBe. However this may not be a feasible solution if the zoom level resulted from zooming to drawings extents will be very low and therefore the picked point may be wrongly interpreted. In my opinion, a better approach will be to perform one zoom operation centered on each control point at such level to ensure that the current processed rectangle is entirely visible on screen prior to call the hatch command. Quote
irneb Posted November 20, 2012 Posted November 20, 2012 OK, are the boundaries of these squares already drawn? Otherwise such hatch by picking a point isn't going to work. If not, then what do you mean by the size of the squares vary? That would mean that there are either overlaps or gaps between (at least) some of the adjacent squares. Or do you refer to squares as not strictly square ... i.e. something like site boudaries. Sorry the GPS seems to indicate something like such. Quote
Mobillosmanden Posted November 20, 2012 Author Posted November 20, 2012 OK, are the boundaries of these squares already drawn? Otherwise such hatch by picking a point isn't going to work. If not, then what do you mean by the size of the squares vary? That would mean that there are either overlaps or gaps between (at least) some of the adjacent squares. Or do you refer to squares as not strictly square ... i.e. something like site boudaries. Sorry the GPS seems to indicate something like such. the boundaries are drawn , coordinates are still in the center of each square Quote
irneb Posted November 20, 2012 Posted November 20, 2012 In that case it's exactly as pBe suggested: Use something like Lee's string to list function to convert the comma separated string into a list of values. Then send those to the bhatch and layer commands. Only possible issue is as per MSasu's post: zoom too far out and hatching might fail. Quote
pBe Posted November 21, 2012 Posted November 21, 2012 Only possible issue is as per MSasu's post: zoom too far out and hatching might fail. Yup, I thought about that too. It would be interesting to see what these "Boundaries" look like, I'm guessing its a Lot Boundary, All we need to do now is the use maximum size of the lot as a zoom factor. (command "_zoom" "_c" pt factor) Quote
irneb Posted November 21, 2012 Posted November 21, 2012 Wonder if one could load all the points into a list, then find the 4 closest to any one point to determine the extents of the surrounding "tiles". Might take long and needs some special treatment for tiles on endges, but at least that would be a decent area to zoom to. Alternatively, find the 4 closest points for each then get the max X & Ydistances accross those. Then zoom to any one point as center of view with max-X as the width of view (max-Y as height). Might work better and slightly faster. Quote
pBe Posted November 21, 2012 Posted November 21, 2012 (edited) Alternatively, find the 4 closest points for each then get the max X & Ydistances accross those. Then zoom to any one point as center of view with max-X as the width of view (max-Y as height). Might work better and slightly faster. A grid, set of 4 or 5 points, zoom into those , do the hatch thingy. then move onto the next set. EDIT: I'm giving the OP a chance to speak up and show us what drawing looks like . Edited November 21, 2012 by pBe Quote
pBe Posted November 22, 2012 Posted November 22, 2012 A grid, set of 4 or 5 points, To demonstrate what i mean by set of 4 (defun c:phat (/ *error* _delFinder _HiLow four Layer fn fl data a run pts ls) (vl-load-com) (defun *error* (msg) (command "._undo" "_end") (setvar 'osmode old_os) (setvar 'cmdecho cmde) (setvar 'hpname hpt) (setvar 'clayer cly) ) (defun _delFinder (str md / d l str) (while (setq d (vl-string-position md str nil T)) (setq l (cons (substr str (+ 2 d)) l) str (substr str 1 d))) (cons str l) ) (defun _HiLow (lev lev2 lst) (list (apply lev (mapcar 'car lst)) (apply lev2 (mapcar 'cadr lst)) )) (defun [b][color="blue"]four[/color][/b] (ls dat) (if (and (< (length ls) 4) (setq b (car dat))) (progn (setq ls (cons (list (mapcar '(lambda (K) (read (nth k b))) '(1 2 3)) (nth 4 b)) ls) dat (cdr dat)) (four ls dat) ) (list ls dat) ) ) (defun Layer (Nme col) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 62 col) (cons 70 0)))) (setq old_os (getvar 'osmode) cmde (getvar 'cmdecho) cly (getvar 'clayer) hpt (getvar 'hpname)) (setvar 'cmdecho 0) (setvar 'hpname "solid")(setvar 'osmode 0) (command "._undo" "_begin") (command "_view" "_save" "tmp") (if (and (setq fn (getfiled "Select source file" (getvar 'Dwgprefix) "txt" 16)) (setq data nil fl (open fn "r") ) ) (progn (while (setq a (read-line fl)) (if (not (eq a ""));;<--- why? because nobody's perfect (setq data (cons (_delfinder a 44) data)))) (setq data (reverse data) ls nil) (close fl) (while data (setq run (four ls data) pts (car run) data (last run)) (if ( = (length pts) 1) (command "_zoom" "_c" (caar pts) 5);; why 5? the question is why not? (command "_zoom" "_w" (_hilow 'min 'min (mapcar 'car pts)) (_hilow 'max 'max (mapcar 'car pts))) ) (foreach itm pts (if (not (tblsearch "layer" (setq lyr (last itm)))) (layer lyr (atoi lyr))) (setvar 'Clayer lyr) (command "_bhatch" (car itm) "") ) ) ) ) (command "_view" "_restore" "tmp" ) (*error* "") (princ) ) sample.dwg sample.txt Quote
irneb Posted November 22, 2012 Posted November 22, 2012 My version: Portion 1 - reading the CSV file: (defun SplitString (source split / p) (setq p 0) (while (setq p (vl-string-search split source p)) (setq source (vl-string-subst "\" \"" split source p) p (+ p 3))) (read (strcat "(\"" source "\")"))) (defun ReadCSV (filename / file str data) (if (setq file (open filename "r")) (progn (while (setq str (read-line file)) (setq data (cons (SplitString str ",") data))) (close file) (reverse data)))) (defun GetPt+Col-fromCCSV (filename) (mapcar '(lambda (row) (list (mapcar 'read (list (cadr row) (caddr row) (cadddr row))) (read (car (cddddr row))))) (ReadCSV filename))) (setq filename (getfiled "Select CSV Text file" "" "txt" data (GetPt+Col-fromCCSV filename)) Portion2 - finding the maximum distance between 4 surrounding points (to figure out the zoom distance): (defun GetClosest-NPoints (pt points N / closest) (setq closest (mapcar '(lambda (pt2) (cons (distance pt pt2) pt2)) points)) (while (> (length closest) N) (setq closest (vl-remove (assoc (apply 'max (mapcar 'car closest)) closest) closest))) closest) (defun GetMaxDist-of-Closest-NPoints (points N) (apply 'max (apply 'append (mapcar 'car (mapcar '(lambda (pt) (GetClosest-NPoints pt (vl-remove pt points) N)) points))))) (setq zoomDist (GetMaxDist-of-Closest-NPoints (mapcar 'car data) 4)) And then finally making the hatches (defun SetLayer (name col) (command "_.LAYER" "_Make" name "_Color" col "" "")) (foreach item data (SetLayer (strcat "Hatch_" (itoa (cadr item))) (cadr item)) (command "_.ZOOM" "_Extents" "_.ZOOM" (mapcar '(lambda (v) (- v zoomDist)) (car item)) (mapcar '(lambda (v) (+ v zoomDist)) (car item))) (command "_.BHATCH" "_Properties" "_Solid" "_Non" (car item) "")) Quote
Mobillosmanden Posted November 22, 2012 Author Posted November 22, 2012 Thanks pBe must say fine work, works like a charm irneb i havent tried the code you provided but i will try it when i get home to the office. looking forward to try it thanks again for the great support:D 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.