Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

generate segments (pline or line/arc) of less than a max length.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jggerth
472 Views, 8 Replies

generate segments (pline or line/arc) of less than a max length.

I've got a drawing with 13 miles of roadway centerlines, 9  to 12 or more lanes, and need to generate a dxf for post procesing.  the application doing the processing chokes if start/end of a segment are more than 2000 units apart.

 

Any one have a routine that can process all the centerlines, and  if length is greater than 1800 add a vertex at the midpoint?  arc radius is critical and would have to be maintained, so I can explode plines ahead of running the routine.

 

 

8 REPLIES 8
Message 2 of 9
hmsilva
in reply to: jggerth


@jggerth wrote:

...

Any one have a routine that can process all the centerlines, and  if length is greater than 1800 add a vertex at the midpoint?  arc radius is critical and would have to be maintained, so I can explode plines ahead of running the routine.


Hi JGerth,

 

do you need the centerlines after running the code as LWPOLYLINES or can be LINES an ARCS?

 

Henrique

EESignature

Message 3 of 9
stevor
in reply to: jggerth

Or, just BREAK the LWPOLYLINE, POLYLINE,

or whatever it is, at a midpoint?

 

If you attach a DWG, for more results:

try to make it small,

without REACTORs or special FONTs,

and Release 2000 or so.

S
Message 4 of 9
jggerth
in reply to: hmsilva

lines and arcs are fine -- the lane cl will end up as a dxf file to be processed by a 3rd party noise program (DOS based -- so somewhat of an antique  🙂 )

 

Breaking manually is a possibility, but there are over 2, 149 miles of centerline in this section if interstate highway, so it's not something I really want to do

Message 5 of 9
hmsilva
in reply to: jggerth

A quick one, minimally tested:

 

(vl-load-com)
(defun c:demo (/ HND I LGT LGT1 LST LSTOBJ N OBJ OLD_OSM PT REP SS SS1 SSN ST X) (if (setq ss1 (ssget "_:L" '((0 . "LWPOLYLINE")))) (progn (command "UNDO" "G") (command "_.zoom" "_E") (setq old_osm (getvar 'OSMODE)) (setvar 'OSMODE 0) (repeat (setq n (sslength ss1)) (setq ssn (ssname ss1 (setq n (1- n))) ss (ssadd) obj (entlast) lstobj (entlast) ) (command "explode" ssn) (while (setq obj (entnext obj)) (ssadd obj ss) ) (if ss (progn (repeat (setq i (sslength ss)) (setq hnd (ssname ss (setq i (1- i))) obj (vlax-ename->vla-object hnd) lgt (vlax-curve-getdistatparam obj (vlax-curve-getendparam obj) ) ) (if (and (> lgt 1800.0) (setq rep (fix (/ lgt 1800.0)) x (1+ rep) lgt1 (/ lgt x) st 0.0 ) ) (progn (repeat rep (setq pt (vlax-curve-getPointAtDist obj (setq st (+ st lgt1))) lst (cons pt lst) ) ) (foreach pt lst (command "_.break" pt "_f" "@" "@") ) (setq lst nil) ) ) ) ) ) ) (setvar 'OSMODE old_osm) (command "_.zoom" "_P") (command "UNDO" "E") ) ) (princ) )

 

HTH

Henrique

EESignature

Message 6 of 9
Kent1Cooper
in reply to: jggerth


@jggerth wrote:

.... 

Breaking manually is a possibility, but there are over 2, 149 miles of centerline in this section if interstate highway, so it's not something I really want to do



You certainly don't need to do it manually.  I had this underway before hmsilva's went up, so here's my take on it.  It leaves them as Polylines, which should save considerable memory, as well as preserving non-zero width(s) if present.  It can still use error handling, command echo suppression, undo begin/end wrapping, etc., but see if it does what you want.  It could also be made to remember your maximum length and offer it as a default on subsequent use, and probably some other enhancements.  Or it could be done as a function with an argument for the maximum length, rather than as a command that prompts for that.  [And by all means really use 2000 rather than 1800 if that's the limit.]

Kent Cooper, AIA
Message 7 of 9
jggerth
in reply to: jggerth

thanks gents!

 

much appreciated.  Maybe someday I'll get back into doing more with Lisp than command line 1-liners.

Message 8 of 9
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:

....

....
	      (setq hnd	(ssname ss (setq i (1- i)))
		    obj	(vlax-ename->vla-object hnd)
		    lgt	(vlax-curve-getdistatparam
			  obj
			  (vlax-curve-getendparam obj)
....
		    (command "_.break" pt "_f" "@" "@")
....

....


Just in case you weren't aware:

 

It's not true of all (vla... functions, but all the (vlax-curve-... functions will work with entity names the same as they do with VLA objects, so since those are the only type of (vla-... functions you're using on them, there's no need to make that conversion.  You could use the 'hnd' variable in place of the 'obj' variable, and skip the latter [in this part of the routine].  Or better yet, use the 'obj' name in place of the 'hnd' name and eliminate 'hnd' altogether -- the former approach wouldn't let you eliminate 'obj' altogether, because you use that earlier.  [Personally, just for my own clarity in looking back into something later, I like to use something more like 'ent' for an entity name, and would do so both in this part and earlier in the routine, and reserve something like 'hnd' for when I'm saving something's handle specifically, and 'obj' for a VLA object when I do need something to be converted to one.]

 

Also, in a Break command, if you give it an entity name instead of a selection point, it automatically knows you're going to need to give it two points, since the entity name doesn't supply one.  So the "first" option does not need to be specified, but "happens" on its own.  You can do:

 

(command "_.break" ent pt "@")

 

However, in this particular routine, that may not be the better way to go, because doing so would also require resetting what's in the 'ent' variable.  If you're Breaking something more than once, after the first Break, the thing you want to Break next is now not the same entity you just Broke, but (entlast).

 

In my routine that keeps the Polylines as Polylines and joins them after each Break, it is always breaking the same entity name, so that's not an issue, but that approach also has an added advantage [for general application -- it sounds like this doesn't apply to this OP's situation if Exploding is acceptable to them]:  If a Polyline has width, selecting it for a Break command by a point on its center-line route may not "see" it -- you may need to select it along an edge, depending on where you are along it, or on how the width compares to the Pickbox size at the current Zoom level -- whereas it will always be able to "find" the entity name.

Kent Cooper, AIA
Message 9 of 9
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:

Just in case you weren't aware:

It's not true of all (vla... functions, but all the (vlax-curve-...


As usual, very useful comments.
Thank you.

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost