Simple Lisp for Cross lines between rectangle.

Simple Lisp for Cross lines between rectangle.

zaid.k3112
Contributor Contributor
4,461 Views
23 Replies
Message 1 of 24

Simple Lisp for Cross lines between rectangle.

zaid.k3112
Contributor
Contributor

Hello, I need a simple lisp which lets me select a 2 points i.e. a rectangle in which it will make cross lines in a desired layer with line type. 

0 Likes
Accepted solutions (1)
4,462 Views
23 Replies
Replies (23)
Message 2 of 24

ВeekeeCZ
Consultant
Consultant

Ok, and what exactly do you need to help with? You did not post any code so... nothing to help with.

0 Likes
Message 3 of 24

zaid.k3112
Contributor
Contributor

I was wondering if such lisp exists. Its very simple. But i cannot find in the forums

0 Likes
Message 4 of 24

ВeekeeCZ
Consultant
Consultant

Well... dunno. Frankly, from your explanation I'm not sure what you want... better post some dwg ....

0 Likes
Message 5 of 24

Sea-Haven
Mentor
Mentor

You mean a X on a rectang just get co-ordinates of the rectang, draw line pt1 pt3 and pt2 pt4.

0 Likes
Message 6 of 24

-didier-
Advisor
Advisor

Bonjour @zaid.k3112 

 

First I would like to know if you want to learn AutoLisp,

or if you want someone to write you a program to do this work.

If you are learning, give us the code already written, and we will correct it to make it work properly.

If you want a program from scratch, thank you for giving a specific example of what needs to be done, and from which it needs to be done.

It’s a matter of respect for people who want to help others.

Either way, we should find a solution.

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 7 of 24

Kent1Cooper
Consultant
Consultant

@zaid.k3112 wrote:

Hello, I need a simple lisp which lets me select a 2 points i.e. a rectangle in which it will make cross lines in a desired layer with line type. 


If "a rectangle" means a closed Polyline such as is made by the RECTANG command, then you don't need to select 2 points, but a routine would be able to find the points from just a single pick of the Polyline [see Message 5].  And that could work whether the rectangle is orthogonally oriented or at any angle, or just a quadrilateral [not necessarily rectangular].

 

If "a rectangle" might be something else [e.g. 4 Lines, perhaps not even ending at the corners but, for example, in a space within a grid of Lines or Xlines, etc.], and if they would always be orthogonal, that would also not be difficult if you are sure to select two diagonally opposite corners [a Line between the 2 points, and one from X-of-one-and-Y-of-the-other to Y-of-one-and-X-of-the-other].  But that won't work if the rectangle or grid is not orthogonally oriented.

 

So what's the expected situation?

 

There are routines out there, such as >this< that includes the drawing of the rectangle as a Polyline, and others on the same Topic that use Lines, from which you can take the diagonal-Line-drawing parts only.

Kent Cooper, AIA
0 Likes
Message 8 of 24

Sea-Haven
Mentor
Mentor

Waiting for OP the other option is want X or +

0 Likes
Message 9 of 24

zaid.k3112
Contributor
Contributor

I have attached drawing. Suppose you have a rectangle (named as 1 in drawing). And I want the desired cross lines as shown in the 2nd rectangle (named as 2 in drawing), I will have to manually do it. I need to find a lisp where I click 2 points as mentioned in the drawing so that the desired result is achieved 

0 Likes
Message 10 of 24

zaid.k3112
Contributor
Contributor

Hey, the lisp you mentioned is what i need to do. But i dont need the rectangle itself, just the lines inside. Apart from that, I need it in a specific layer, linetype scale, line type etc. This is secondary. I am a noob in lisp. Can i tell me which line to remove in the mentioned lisp so that it does what i need to do?

0 Likes
Message 11 of 24

zaid.k3112
Contributor
Contributor

Hello, I was wondering if such lisp exists, as it is very simple one.

0 Likes
Message 12 of 24

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this. Fix *.lin file if it's different.

 

(defun c:XSteps ( / p1 p2 gn lt)

  (and (setq gn (list '(0 . "LINE") '(8 . "02-Steps") (cons 6 (setq lt "Dash Dash 1")) '(48 . 0.01)))
       (or (tblsearch "ltype" lt)
	   (command "._-linetype" "_load" lt "acadiso.lin" "")
	   (tblsearch "ltype" lt)
	   (prompt (strcat "\n'" lt "' LT loading failed.")))
       (setq p1 (getpoint "\nSpecify first point: "))
       (setq p2 (getpoint p1 "\nSpecify second point: "))
       (entmake (append gn (list (cons 10 (trans p1 1 0))
				 (cons 11 (trans p2 1 0)))))
       (entmake (append gn (list (cons 10 (trans (list (car p1) (cadr p2)) 1 0))
				 (cons 11 (trans (list (car p2) (cadr p1)) 1 0))))))
  (princ)
  )

 

0 Likes
Message 13 of 24

zaid.k3112
Contributor
Contributor
Hey bro.. thanks a lot. this is exactly what i needed. Thanks bro ❤️
0 Likes
Message 14 of 24

Sea-Haven
Mentor
Mentor

My 2 pt $0.05 version

 

 

(defun c:xmarksthespot ( / pt1 pt2 mp )
(setq pt1 (getpoint "\nPick point 1 ") pt2 (getpoint "\nPick point 2 "))
(setq mp (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5)))
(command "line" pt1 pt2 "")
(command "Mirror" "l" "" mp (setq mp (mapcar '+ mp '(1.0 0.0 0.0))) "N")
)
(c:xmarksthespot)

 

0 Likes
Message 15 of 24

Kent1Cooper
Consultant
Consultant

Here's another way to draw the Lines, given that p1 and p2 are established:

 

  (command "_.line" p1 p2 "" "_.line" ".x" p1 p2 ".y" p1 p2 "")

Kent Cooper, AIA
0 Likes
Message 16 of 24

Kent1Cooper
Consultant
Consultant

@zaid.k3112 wrote:

Hello, I need a simple lisp which lets me select a 2 points i.e. a rectangle in which it will make cross lines .... 


How about one pick inside any four-sided closed area [rather than two picks at opposite corners], and the ability to do that in as many of them as you want in one running of the command?  In simplest terms:

 

 

(defun C:Xit (/ pt bnd)
  (command "_.layer" "_thaw" "YourLayer" "_make" "YourLayer" "_ltype" "YourLinetype" "" "")
  (while (setq pt (getpoint "\nPick inside four-sided area: "))
    (command "_.boundary" pt "")
    (setq bnd (entlast))
    (command
      "_.line" (vlax-curve-getPointAtParam bnd 0) (vlax-curve-getPointAtParam bnd 2) ""
      "_.line" (vlax-curve-getPointAtParam bnd 1) (vlax-curve-getPointAtParam bnd 3) ""
    )
    (entdel bnd)
  ); while
  (command "_.layerp")
  (princ)
)

 

 

Edit the "YourLayer" [twice] and "YourLinetype" names as desired.  [One advantage of using a Layer command is that if the linetype is in the acad.lin / acadiso.lin file, it is not necessary for it to be already loaded in the drawing -- the Layer command will find it.]

 

It's up to you to pick only within the right kind of bounded area, but it could be expanded to verify certain things before trying to draw the Lines [e.g. success in the BOUNDARY command, four sides, all-straight-edges if you like, etc.).

 

It works in any shape of quadrilateral area, even if non-rectangular or non-orthogonal [either of which a MIRROR-based command or a two-points approach would get wrong].

Kent Cooper, AIA
0 Likes
Message 17 of 24

rbischoffatsr
Participant
Participant

Draws single polyline rectangle with X by picking two points.

(defun c:xbox (/ P1 P2 P3 P4)

;set rectangle points
(setq P1 (getpoint "\nPick corner: "))
(setq P3 (getcorner P1 "\nPick opposite corner: "))
(setq P2 (list (car P1) (cadr P3)))
(setq P4 (list (car P3) (cadr P1)))

(command ".PLINE" P1 P2 P3 P4 P2 P3 P1 P4 "")

(princ))

0 Likes
Message 18 of 24

Kent1Cooper
Consultant
Consultant

@rbischoffatsr wrote:

Draws single polyline rectangle with X by picking two points.

....

(command ".PLINE" P1 P2 P3 P4 P2 P3 P1 P4 "")

....


[That really doesn't do what they asked for, namely with the X of a different layer/linetype than the perimeter -- see the wording of Message 1 and the sample drawing at Message 9.]

Kent Cooper, AIA
0 Likes
Message 19 of 24

john.uhden
Mentor
Mentor

@zaid.k3112 

I guess I'm late for the party AND didn't read your request very well.

But, anyway, here's something you might want to use in the future...

(defun c:CrissCross ( / *error* vars vals ss i ent layer p1 p2 p3 p4)
  ;; John F. Uhden, Sea Girt, NJ, USA
  ;; Program adds crossing lines from opposite corners of multiple
  ;; closed rectangular lightweight polylines
  ;; v1.0 (4-14-22)
  (gc)
  (vl-load-com)
  (princ "\nCrissCross v1.0 (c)2022, John F. Uhden")
  (defun *error* (error)
    (mapcar 'setvar vars vals)
    (vla-endundomark *doc*)
    (cond
      ((not error))
      ((wcmatch (strcase error) "*QUIT*,*CANCEL*"))
      (1 (princ (strcat "\nERROR: " error)))
    )
    (princ)
  )
  (setq vars '("cmdecho"))
  (setq vals (mapcar 'getvar vars))
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (or *doc* (setq *doc* (vla-get-ActiveDocument *acad*)))
  (vla-endundomark *doc*)
  (vla-startundomark *doc*)
  (mapcar 'setvar vars '(0))
  (command "_.expert" (getvar "expert")) ;; dummy command
  (and
    (princ "\nSeclect rectangles...")
    (setq ss (ssget '((0 . "LWPOLYLINE")(90 . 4)(-4 . "&")(70 . 1))))
    (repeat (setq i (sslength ss))
      (setq ent (entget (ssname ss (setq i (1- i))))
            layer (assoc 8 ent)
      )
      (mapcar 'set '(p1 p2 p3 p4)(mapcar 'cdr (vl-remove-if-not '(lambda (x)(= (car x) 10)) ent)))
      (entmake (list '(0 . "LINE")(cons 10 p1)(cons 11 p3) layer))
      (entmake (list '(0 . "LINE")(cons 10 p2)(cons 11 p4) layer))
    )
  )
  (*error* nil)
)
(defun c:CC ()(c:CrissCross))

John F. Uhden

0 Likes
Message 20 of 24

ronjonp
Mentor
Mentor

@john.uhden  FWIW ..  😀

ronjonp_0-1649993990696.png

The 'dummy' command' and the setvars are not useful. Even more so when command calls are not used and you're not resetting it to the original value. 

0 Likes