Jump to content

Automating my GPS data clean up process


Jakes

Recommended Posts

Hi everyone, long time listener first time caller.

 

A little bit background...
I am a pipe and cable locator and use a GPS to survey lines in the real world (that represent underground services (power, comms, water, gas etc etc)) and use CAD to create scale and detailed plans of services.
The GPS I use spits out raw data in dwg format which I process to clean it up for readability and presentaion. 

It is this process I have been trying to automcate using some lisp routines as the bulk of the initial cleanup process is repeated for every drawing.

The GPS is configured with multiple "preset" layer names for all the different services, and I use a dwg template which already contains the same layer names. 

In my template each services layer is configured a linetype so when I drop the GPS data into my template, Electricity lines show up with a -----E----- linetype, comms -----C------ and on and on.
One of the things about GPS'ing lines in real life is that when dropped into my template and the linetypes appear, some are right way up, some are upside down. Obviously depending when I start and finish surverying the line.

Before lisp, I would go through and manually rotate each line that looked upside down.
Yeah. Painful.

Then I found (sorry can't remember where otherwise i would cite), altered to my needs the below lisp routine:

 

(defun c:flipit ()
	(setq sset (ssget)) ;manually select objects and store selection set in variable "sset" 
	(setq num (sslength sset) itm 0) ; count objects in the selection set "sset" and assign this to variable "num". Also set variable "itm" to 0.
		(while (< itm num) ;while "itm" is less than "num", do:
			(setq hnd (ssname sset itm)) ;set the name of the xth entity in the selection set "sset" to the variable "hnd"
			(setq ent (entget hnd)) ;retrieve the entity data for the entity stored in "hnd" and store in variable "ent"
				(if (= (cdr (assoc 0 ent)) "LINE")  ;search the entity data stored on "hnd" for association list group code '0' (Text string indicating the entity type (fixed))
													;cdr: Returns a list containing all but the first element of the specified list
													;if first entity data in new list = "line" (true), do:
					(progn ;Evaluates each expression sequentially and returns the value of the last expression
						(setq pt1 (cdr (assoc 10 ent)))
						(setq pt2 (cdr (assoc 11 ent)))
						(setq ent (subst (cons 10 pt2)(assoc 10 ent) ent))
						(setq ent (subst (cons 11 pt1)(assoc 11 ent) ent))
						(entmod ent)
					)
				) ;end if (if false skip here)
			(setq itm (1+ itm)) ;increment varialbe "itm"
		);end while
	(princ)
)


I tired to comment it up to attempt to undertand it fully, but got stuck at the progn section.
Anyway, basically this rouinte allows me to preselect everything that needs rotating, and run this routine and it flips them 180 degrees instantly (by swapping their start and finish coords).
I was able to come up with this code (below) which replaces the second line of the above code, and is a fast way of automatically selecting every line on any layer that has "service" in the name. Great...

 

	(setq sset (ssget "_X" '((8 . "*service*") (0 . "*LINE")))) ;automatically select all lines on service layers


What I am now stuck on, is how to alter the code to automatically flip anything that needs flipping while leaving lines the write way up untouched.
I have  attached an image that shows when not to flip and when to flip based on the x&y values.
In summary:

IF

StartX = EndX & StartY < EndY = No flip
StartX < EndX & StartY < EndY = No flip
StartX < EndX & StartY = EndY = No flip
StartX < EndX & StartY > EndY = No flip
StartX = EndX & StartY > EndY = Flip
StartX > EndX & StartY > EndY = Flip
StartX > EndX & StartY = EndY = Flip
StartX > EndX & StartY < EndY = Flip

 

Thank you for any input.
I have a few other things I want to achieve in the process of automing the GPS data clean up process, but this is the first. 

Capture.PNG

Link to comment
Share on other sites

If you were using a more up to date version of AutoCAD, you could edit the linetype definitions to give Upright text and your troubles would be vastly simplified.

  • Like 1
Link to comment
Share on other sites

If you look at line angle is it >90 < 270 note angle is actually (/pi 2) (* pi 1.5) as (angle p1p2) returns an answer in radians, then its upside down or use some other angle range. Similar approach to make text readable.

 

If you use (setq mp (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5 0.5))) this is mid pt so can rotate obj 180, hint Pi around mp.

 

 

Link to comment
Share on other sites

Thanks Eldon learn something new every day, works ok in Bricscad also. Just updated one of my custom.lin

 

Replace R=0.0 etc with U=0.0, need min  acad 2011 so no go in 2007, Jakes maybe have a look at Bricscad and update.

Link to comment
Share on other sites

BigAl suggests line angle which works, but you could also flip the lines if pt1 x coordinate is larger than pt2 x coordinate since you all ready have pt1 and pt2 

(if (< (nth 0 pt1) (nth 0 pt2) ) ..... )

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