LISP Help

LISP Help

Anonymous
Not applicable
1,083 Views
12 Replies
Message 1 of 13

LISP Help

Anonymous
Not applicable

Hello good people,

 

I would like some help to write a LISP routine that can draw a 200mm vertically line down at the intersection of two horizontal lines.

I would also like to create a similar routine to draw a 200mm vertically line up at the intersection of two horizontal lines.

 

Unfortunately I don’t not have the skills required to write this LISP so any help given would be highly appreciated.

 

This routine is to aid in drawing a retaining walls which highly time consuming and frustrating.

 

Please find attached DWG file with a basic outline of how I wish it to work.

 

If you need any more information please do hesitate to ask.

 

Thank you.

0 Likes
Accepted solutions (1)
1,084 Views
12 Replies
Replies (12)
Message 2 of 13

doglips
Advocate
Advocate

Maybe something like this?...

I can't seem to get past the smiley face but that should say c colon DL()

 

(defun c:DL()
  (setq ansr (getstring "Vertivel or Horizontal? [U/D]:"))
    
  (setq ansr (strcase ansr))
  (setq direct (strcase direct))
 
  (setq OrigOsmode (getvar "osmode"))
  (setvar "osmode" 33)
  (setq LinLoc (getpoint "Pick Intersection: "))
  (if (= ansr "U")
     (setq direct "200")
     (setq direct "-200")
  );;if
        (command "line" LinLoc (strcat "@0,"direct) "")
  (setvar "osmode" origosmode)
 );;defun

0 Likes
Message 3 of 13

doglips
Advocate
Advocate
 
0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Hello good people,

 

I would like some help to write a LISP routine that can draw a 200mm vertically line down at the intersection of two horizontal lines.

I would also like to create a similar routine to draw a 200mm vertically line up at the intersection of two horizontal lines.

 


I guess you want to draw those green lines...

Spoiler
(defun c:d200 ( / ensel)
  (while (setq ensel (entsel "\nSelect object closer to particular end <exit>: "))
    (command "_.LINE" "_end" (cadr ensel) "_none" "@0,-200" ""))
  (princ)
)

(defun c:u200 ( / ensel)
  (while (setq ensel (entsel "\nSelect object closer to particular end <exit>: "))
    (command "_.LINE" "_end" (cadr ensel) "_none" "@0,200" ""))
  (princ)
)
0 Likes
Message 5 of 13

Anonymous
Not applicable

Yes you are correct about the lines but they need to be drawn at the intersection of the construction line and the horizontal design export lines.

At this stage it seems to be picking the intersection of the Vertical and the design export lines.

The LISP below works fine but it is for a point not a line can this maybe be modified to suit?!

 

Thanks in advance.

 

(defun C:In2st ( / ss ptsa pt)
  (if (and (setq ss (ssget '(( 0 . "LINE,LWPOLYLINE"))))
    (= 2 (sslength ss))
    (setq int (vLa-intersectwith (vLax-ename->vLa-Object (ssname ss 0))
            (vLax-ename->vLa-Object (ssname ss 1))
                       acextendnone))
    (setq ptsa (vLax-safearray->List (vLax-variant-vaLue int))))
    (repeat (/ (length ptsa) 3)
      (setq pt (list (car ptsa)
       (cadr ptsa)
       (caddr ptsa)))
      (command "_insert" pt)
      (setq ptsa (cdddr ptsa))))
  (princ)
)

0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@doglips wrote:

...

I can't seem to get past the smiley face ....


[You can disable colon+character smileys/emoticons, whenever you're signed in, with the instructions here.]

Kent Cooper, AIA
0 Likes
Message 7 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

The LISP below works fine but it is for a point not a line can this maybe be modified to suit?!

....
      (command "_insert" pt)
....


Just change that Insert command line to:

 

    (command "_.line" "_none" pt "_none" "@0,200" ""); [for upward from the intersection]

 

or

 

    (command "_.line" "_none" pt "_none" "@0,-200" ""); [for downward]

 

[But is that quoted line missing something?  It doesn't include a Block name, nor answers to scale and rotation prompts.  It ought to work if that command were point instead of insert.]

Kent Cooper, AIA
0 Likes
Message 8 of 13

Anonymous
Not applicable

Thanks Kent that worked perfect!

I have changed it to be a Polyline.

How can I modify it to add polyline segments of 400 on the X axis for let's say 2000.

The four hundred is obviously to represent block lengths.

 

I played around with it but sorry I dont have the skills.

 

(defun C:VL200 ( / ss ptsa pt)
  (if (and (setq ss (ssget '(( 0 . "LINE,LWPOLYLINE"))))
    (= 2 (sslength ss))
    (setq int (vLa-intersectwith (vLax-ename->vLa-Object (ssname ss 0))
            (vLax-ename->vLa-Object (ssname ss 1))
                       acextendnone))
    (setq ptsa (vLax-safearray->List (vLax-variant-vaLue int))))
    (repeat (/ (length ptsa) 3)
      (setq pt (list (car ptsa)
       (cadr ptsa)
       (caddr ptsa)))
      (command "_.Pline" "_none" pt "_none" "@0,200" "");
      (setq ptsa (cdddr ptsa))))
  (princ)
)

0 Likes
Message 9 of 13

Anonymous
Not applicable

Any ideas Kent1Cooper ?!

 

Thanks in advance.

0 Likes
Message 10 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....

How can I modify it to add polyline segments of 400 on the X axis for let's say 2000.

....
      (command "_.Pline" "_none" pt "_none" "@0,200" "")
....


If always five 400-unit segments to the right:

....

      (command "_.Pline" "_none" pt "_none" "@0,200"

        "_none" "@400,0" "_none" "@400,0" "_none" "@400,0" "_none" "@400,0" "_none" "@400,0"

        ""

      )

....

 

or @-400,0 if to the left.  It may well be worth turning Osnap off to avoid all those "_none" calls.

 

It might even be possible to have it check on the X coordinate of the next intersection, and go in 400-unit steps until it gets there, or to the next 400-unit increment past there, or something.

Kent Cooper, AIA
0 Likes
Message 11 of 13

Anonymous
Not applicable

Thanks Kent1Cooper, works great!

 

How could we achieve this?

 

"It might even be possible to have it check on the X coordinate of the next intersection,

and go in 400-unit steps until it gets there, or to the next 400-unit increment past there, or something".

 

Sorry mate that is just above my skill level.

 

Thanks.

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

How could we achieve this?

 

"It might even be possible to have it check on the X coordinate of the next intersection,

and go in 400-unit steps until it gets there, or to the next 400-unit increment past there, or something".

.....


That would involve selecting the slope Polyline and all the coursing Lines, not just the slope and one Line.  A question:

 

Would the slope always be represented by a Polyline entity, and the coursing always represented by Line entities?  If so, presumably a routine could let you pick them all together, and it would be able to figure out which was which.  Otherwise, it would need to ask for selection of the slope object separately from the coursing lines.

 

It would involve running the (intersectwith) thing on the slope object in combination with each of the coursing lines, making a list of all intersection points, and sorting them by X coordinate.  Then it could work from one end, comparing the Y coordinate of each intersection with that of the next one to decide whether to go up or down, and stepping in 400-unit increments in the direction of that next one until another such step would overshoot it, etc. -- not trivial, but doable.  It could even be made to handle a slope object that changes direction [slopes down for a while and then back up, or vice versa].

Kent Cooper, AIA
0 Likes
Message 13 of 13

Anonymous
Not applicable

Ok great!

 

How can i get this routine started?

I think I could maybe get the Intersection with part working from seeing your previous teachings but that's about it.

Like I said I simply don't have the skills to achieve this.

 

Thanks

0 Likes