Jump to content

Hatch squares from coordinates


Mobillosmanden

Recommended Posts

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.:D

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by pBe
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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) ""))

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...