Results 1 to 6 of 6

Thread: LISP to draw cross

  1. #1
    100 Club
    Join Date
    2015-11
    Location
    Dallas, Texas
    Posts
    142
    Login to Give a bone
    0

    Default LISP to draw cross

    Is there a LISP out there that can draw a cross for an opening? I want to be able to select a rectangle, and then have a LISP automatically draw a line from one corner to the other (diagonally), and the same with the opposite corner. (See attached for clarification)

    Is this even possible? I'm not familiar with LISP. Would this be a good one to try to learn on?

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: LISP to draw cross

    Yes - this is a simple application for which lisp is perfect.

    I'll check back later when I have to time and contribute to the solution if necessary.
    R.K. McSwain | CAD Panacea |

  3. #3
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: LISP to draw cross

    Give this piece of code a try. I'm sure it is not the cleanest or shortest way of writing a program to perform the task, but it makes a cross in a rectangle.

    Code:
    (defun c:cross (/ pnt1 pnt2 pnt3 pnt4  lst e len n e1)
    
    	(setq e (entget (car (entsel))))
    	;get the entity list
    
    	(setq len (length e))
    	;get the length of the list
    
    	(setq n 0)
    	;set counter to zero
    	(setq lst nil)
    	(repeat len
    	;repeat for the length of the entity list
    
    	  (setq e1 (car (nth n e)))
    	  ;get each item in the entity list
    	  ;and strip the entity code number
    
    	  (if (= e1 10)
    	  ;check for code 10 (vertex)
    
    	    (progn
    	    ;if it's group 10 do the following
    
    		(terpri)
    		  ;new line
    		(setq lst (if lst (append lst (list(cdr (nth n e))))(list(cdr (nth n e)))))	  
    	    );progn
    
    	  );if
    	  (setq n (1+ n))
    	  ;increment the counter
    
    	);repeat
      (mapcar 'set '(pnt1 pnt2 pnt3 pnt4) lst)
      
    	        (setq pnt1 (strcat(rtos(car pnt1))"," (rtos(cadr pnt1)) ",0"))
    	      
    		(setq pnt2 (strcat(rtos(car pnt2)) ","(rtos(cadr pnt2))",0"))
    
    		(setq pnt3 (strcat(rtos(car pnt3)) ","(rtos(cadr pnt3))",0"))
    
    		(setq pnt4 (strcat(rtos(car pnt4)) ","(rtos(cadr pnt4))",0"))
    
    (command "line" pnt1 pnt3 "")
    (command "line" pnt2 pnt4 "")
      (princ)
    );defun
    (princ)
    Note this only works on rectangles drawn with the rectangle command or polylines converted to LWPOLYLINES. I did not put anythign in the code to check for this at the beginning.
    Last edited by Lions60; 2009-01-30 at 07:59 PM.

  4. #4
    Member
    Join Date
    2005-01
    Posts
    42
    Login to Give a bone
    0

    Default Re: LISP to draw cross

    Hi-
    Here is a simple routine that uses entmake to draw lines to form a cross in a rectangle. As long as you pick a rectangle or four sided polyline it should work.

    Code:
    (defun c:cross (/ osm ent pt1 pt2 pt3 pt4)
    
    (setq osm (getvar "osmode"))
    (setvar "osmode" 0)
    
    (while (setq ent (entsel "\nSelect a rectangle: "))
      (setq pt1 (vlax-curve-getPointAtParam (car ent) 1))
      (setq pt2 (vlax-curve-getPointAtParam (car ent) 2))
      (setq pt3 (vlax-curve-getPointAtParam (car ent) 3))
      (setq pt4 (vlax-curve-getPointAtParam (car ent) 4))
      (entmake (list (cons 0 "LINE")(cons 10 pt1)(cons 11 pt3) ))
      (entmake (list (cons 0 "LINE")(cons 10 pt2)(cons 11 pt4) ))
    )
    
    (setvar "osmode" osm)
    (princ)
    
    )
    One other thing. You could add a little more code and it would draw the lines on a given layer. ex. (cons 8 "MyLayer")
    Add it in the line of code that starts with entmake after (cons 0 "LINE"). Add color or linetype. Have fun with it.

    Jim

  5. #5
    100 Club
    Join Date
    2015-11
    Location
    Dallas, Texas
    Posts
    142
    Login to Give a bone
    0

    Default Re: LISP to draw cross

    Thank you both so much. They work great. I was even able to add the layer that I wanted the cross on into the LISP.

    I have another question. In this example of code, is the ";get the entity list" just a description of what the code above it does? Just trying to start learning LISP and I appreciate your help.

    (setq e (entget (car (entsel))))
    ;get the entity list

  6. #6
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: LISP to draw cross

    Yes, it is just a commented description that is ignored by autocad when executing the program and gives the user a description of what that line of code is actually doing.

Similar Threads

  1. Iwant a lisp: draw a CIRCLE
    By hass11533092 in forum AutoLISP
    Replies: 0
    Last Post: 2014-02-02, 08:40 PM
  2. Draw line lisp
    By rphillips.137763 in forum AutoLISP
    Replies: 3
    Last Post: 2012-06-21, 02:05 PM
  3. Cross Section>Draw Template in C3D?
    By SRBalliet in forum AutoCAD Civil 3D - General
    Replies: 5
    Last Post: 2008-11-14, 04:38 PM
  4. Replies: 7
    Last Post: 2007-09-05, 03:41 AM
  5. lisp to draw multiple polylines
    By stephen.coff in forum AutoLISP
    Replies: 8
    Last Post: 2007-08-01, 11:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •