Jump to content

Lisp to draw a straight line between two polylines?


Recommended Posts

Posted

Hello

 

I was wondering if there is a lisp routine out there or a variation that draws a line in the middle of two polylines.

 

In this example, The green polylines are what is there and the blue line is what I hope to be the generated outcome of the lisp routine

 

Thank you very much for your help!

lines.jpg

Posted

Actually even better is if this code can stretch the green polylines to center distance would be awesome!

lines.JPG

Posted

This won't do what you want it to do, but I think it may be a start. All that this does is offset the objects a specified distance on either side then removes the object with the smallest length, hence, it should create a rectangle outside the existing ones. If you specify the distance to one-half of the width of the corridor, you can then explode the offset rectangles and run the express tool OVERKILL to clean everything up.

 

Try that out, and if it works, I could probably streamline it a bit for you.. otherwise, what you're asking might be out of my league :( though I'm sure Lee will jump in momentarily with a snappy solution, as he always does...

 

(defun c:oo2( / e o a )
 (setq o (getreal (strcat "\nSpecify offset distance <" (if #oo_dist (rtos #oo_dist 2 2) "1.0") ">: " )))
 (setq #oo_dist (if o o 1.0))
 (setq e (car (entsel "\nSelect object: ")))
 (if e
   (progn
     (setq a (mapcar '(lambda (x) (vla-offset (vlax-ename->vla-object e) x)) (list #oo_dist (* -1.0 #oo_dist))))
     (setq b (mapcar '(lambda (x) (car (vlax-safearray->list (vlax-variant-value x)))) a))
     (entdel (vlax-vla-object->ename (nth (vl-position (apply 'min (setq c (mapcar 'vla-get-length b))) c) b)))
     )
   )
 )

Posted
though I'm sure Lee will jump in momentarily with a snappy solution, as he always does...

 

Don't count on it... :roll:

Posted

Hey freerefill, thanks for giving it a shot but yeah I've attempted that before but I think if I can adjust side to side it would be good. Reason being is that I'm trying to polyline rooms following a standard so some rooms take up the area of a wall in between and some don't. Basically what I've been doing instead is deleting all the area polylines and redrawing lines where the middle of the walls or not is...then hatching them but retaining a polyline around the hatched area and turning those newly formed polylines into new room area counts. It's not the fastest way to do it but it's all I've got

 

I would really appreciate any further help with this.

Posted

Ok, I was slightly bored this evening...

 

Merge.gif

 

(defun c:test ( / e1 e2 pt ptLst )
 ;; © Lee Mac  ~  16.06.10
 (vl-load-com)

 (if (apply 'and
       (append
         (mapcar 'set '( e1 e2 )
           (mapcar
             '(lambda ( s )
                (LM:SelectifFoo
                  (lambda ( x )
                    (eq "LWPOLYLINE" (cdr (assoc 0 (entget x))))
                  )
                  s
                )
              )
             '("\nSelect First Polyline: " "\nSelect Second Polyline: ")
           )
         )
         (list (setq pt (getpoint "\nPick Mid Point: ")))
       )
     )
   (progn
     (setq pt (trans pt 1 0))
     
     (setq ptLst
       (apply 'append
         (mapcar 'LM:GetLWPolylineVerts (list e1 e2))
       )
     )
     (mapcar 'set '( ll ur )
       (mapcar
         '(lambda ( foo )
            (apply 'mapcar (cons foo ptLst))
          )
         '(min max)
       )
     )
     (mapcar
       '(lambda ( entity points )
          (entmod
            (append
              (reverse
                (member (assoc 39 (entget entity))
                  (reverse (entget entity))
                )
              )
              (mapcar '(lambda ( p ) (cons 10 p)) points)
            )
          )
        )
       (list e1 e2)
       (list
         (list ll
           (list (car ll) (cadr ur))
           (list (car pt) (cadr ur))
           (list (car pt) (cadr ll))
         )
         (list ur
           (list (car ur) (cadr ll))
           (list (car pt) (cadr ll))
           (list (car pt) (cadr ur))
         )
       )
     )
   )
 )
 (princ)
)

(defun LM:GetLWPolylineVerts ( entity )
 ;; © Lee Mac  ~  12.06.10
 (mapcar 'cdr
   (vl-remove-if-not
     '(lambda ( x ) (= 10 (car x))) (entget entity)
   )
 )
)

(defun LM:SelectifFoo ( foo str / sel ent )
 ;; © Lee Mac  ~  12.06.10
 (while
   (progn
     (setq sel (entsel str))
     
     (cond
       (
         (vl-consp sel)

         (if (not (foo (setq ent (car sel))))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 ent
)

Posted
Ok, I was slightly bored this evening...

 

Hah! I called that one. :P

Posted

Hiya Lee,

This lisp is pretty good thank you!

 

The only issues I've had with it is when the rooms aren't rectangular or square, let's say a L shaped room. But I still really happy with what was made so I'll have to move around those non rectangular rooms. I'll keep using this

 

Thank you so much, wish I knew as much as you!

Posted
You're very welcome - I had fun writing it :)

Two things:

  1. Why'd you switch back to defining a function with ' instead of function?
  2. While the apply 'and is really cool (had this very idea and tried it myself a while back), but it will not evaluate if all parameters have been filled until the last is evaluated. As a result, if the first object is not selected, the user is still prompted for the second object and/or the mid point. Just some food for thought, since I've seen you use this method a few times.

Posted
1. Got fed up of typing it

Right on. I never noticed much of a difference and bounce b/w the two myself.

 

2. Ok

Just thought you might like to know. Execute the routine once, miss the first pick and you'll see what I'm talking about.

  • 2 months later...
Posted

Hey, can you show me a lisp to do as suggested in the first post of this thread? Here is an example of how I would use it: Ramp Center Line.gif

 

Thanks!!

Posted
Offset command?

Yeah, that is the easiest solution for the example I posted. I found another thread - http://www.cadtutor.net/forum/showthread.php?49709-Centre-Line-between-two-Polylines&p=349383#post349383 - that illustrates a scenario where offset wouldn't be adequate. Alanjt is posting the code when he gets a chance.

 

My lisp programming abilities seem to be on the brink of understanding right now. I can do basic stuff fairly well, but anything that requires gathering information prior to running a command or responding to a set of parameters stops me in my tracks. Oh the joy of self learning :?

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