Results 1 to 7 of 7

Thread: Selection of a rectangle instead of asking for two corners

  1. #1
    Login to Give a bone
    0

    Default Selection of a rectangle instead of asking for two corners

    Dear all,
    I got a lisp code that can generate required no of rows and columns inside a two corners of a rectangle. But I need a change in that it should ask for selection for rectangle irrespective of the rectangle is in straight or in inclination position

    Selection of a rectangle instead of asking for two corners.dwg

    Code:
    (PROMPT "\n THIS PROGRAM FOR DISTRIBUTION LAMP")
    (PROMPT "\n START COMMAND by : ----DIL---- ")
    (DEFUN C:IL ()
    (SETVAR "CMDECHO" 0)
    (setq os (getvar "osmode"))
    (setvar "osmode" 0)
    (SETQ P1 (GETPOINT "\n ENTER FIRST POINT: "))
    (SETQ P3 (GETPOINT "\n ENTER SECOND POINT: "))
    (SETQ BB1 (cdr (assoc 2 (entget (car (entsel "\n Select Block"))))))
    (setq x1 (car p1))
    (setq y1 (car (cdr p1)))
    (setq x3 (car p3))
    (setq y3 (car (cdr p3)))
    (setq p2 (list x1 y3))
    (setq p4 (list x3 y1))
    (setq disx (distance p1 p4))
    (setq disy (distance p1 p2))
    (SETQ NX (GETINT "\n NUMBER OF X DIR."))
    (SETQ XXN (/ disx (* NX 2)))
    (SETQ DS1 (* XXN 2))
    (SETQ NY (GETINT "\n NUMBER OF Y DIR."))
    (SETQ YYN (/ disy (* NY 2)))
    (SETQ DS2 (* YYN 2))
    (setq xx1 (+ (car p1) XXN))
    (setq yy1 (+ (car (cdr p1)) YYN))
    (setq pp2 (list xx1 yy1))
    (COMMAND "-layer" "m" "M-FIRE-SYMB-P" "c" "2" "" "")
    (COMMAND "INSERT" BB1 pp2 "" "" "")
    ;(COMMAND "ARRAY" "L" "" "R" NY NX DS2 DS1)
    (if (eq NX 1) (COMMAND "ARRAY" "L" "" "R" NY NX DS2))
    (if (eq NY 1) (COMMAND "ARRAY" "L" "" "R" NY NX DS1))
    (if (AND (/= NX 1) (/= NY 1))(COMMAND "ARRAY" "L" "" "R" NY NX DS2 DS1))
    (setvar "osmode" os)
    (PRIN1)
    (PRIN1)
    (PROMPT "\n")
    (PROMPT "\n CREATED by :")
    (PROMPT "\n ********* M.SAIED. ********* ")
    (PRINC)
    );DEFUN
    Last edited by brahmanandam.thadikonda762224; 2018-10-05 at 02:08 PM. Reason: added [CODE] tags

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

    Default Re: Selection of a rectangle instead of asking for two corners

    PLEASE use code tags for your lisp code postings!
    R.K. McSwain | CAD Panacea |

  3. #3
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Selection of a rectangle instead of asking for two corners

    You really need to Wrap Code tags around any code you post.

    Clicking the [Go Advanced] button at the bottom puts a toolbar at the top and the # icon in that toolbar places code tags around selected text for you or simply paste your code inside.

    Untested, but try:
    Code:
    (defun C:LRR ( / ent obj c1 c2 wid ht rows cols blk); = Lights in Rectangular [& orthogonal] Room
     (if  (setq ss (ssget "+.:E:S" '((0 . "*POLYLINE"))))
      (progn
    	(setq ent (ssname ss 0)
    		  obj (vlax-ename->vla-object ent)
    	); setq
    	(vla-GetBoundingBox obj 'minpt 'maxpt)
    	(setq c1 (vlax-safearray->list minpt)
    		  c2 (vlax-safearray->list maxpt)
    		  rows (getint "\nNumber of rows (---): ")
    		  cols (getint "\nNumber of columns (|||): ")
    		  wid (/ (- (car c2) (car c1))cols)
    		  ht (/ (- (cadr c2) (cadr c1))rows)
    		  blk (cdr (assoc 2 (entget (car (entsel "\n Select Block")))))
    		  c1 (list(+(car c1)(/ wid 2))(+(cadr c1)(/ ht 2)))
    	); setq
    	(command "_.minsert" blk c1 "" "" "" rows cols ht wid); command
      ); progn
     ); if
     (princ)
    ); defun
    Last edited by Tom Beauford; 2018-10-05 at 02:02 PM. Reason: Replaced Code

  4. #4
    Login to Give a bone
    0

    Default Re: Selection of a rectangle instead of asking for two corners

    I have tried your code but not working, showing as "; error: syntax error"

  5. #5
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Selection of a rectangle instead of asking for two corners

    Quote Originally Posted by brahmanandam.thadikonda762224 View Post
    I have tried your code but not working, showing as "; error: syntax error"
    I updated the code, and tested it this time. Should work now. Don't see MINSERT used that often.

  6. #6
    Login to Give a bone
    0

    Default Re: Selection of a rectangle instead of asking for two corners

    Thank you So much Sir,

    If you dont' mind, could you please update following code for multiple rectngles. It saves me lot of time, thank you in advance.


    Code:
    HTML Code:
    [PHP](PROMPT "\n THIS PROGRAM FOR DISTRIBUTION LAMP")
    (PROMPT "\n START COMMAND by : ----DIL---- ")
    (DEFUN C:IL ()
    (SETVAR "CMDECHO" 0)
    (setq os (getvar "osmode"))
    (setvar "osmode" 0)
    (SETQ P1 (GETPOINT "\n ENTER FIRST POINT: "))
    (SETQ P3 (GETPOINT "\n ENTER SECOND POINT: "))
    (SETQ BB1 (cdr (assoc 2 (entget (car (entsel "\n Select Block"))))))
    (setq x1 (car p1))
    (setq y1 (car (cdr p1)))
    (setq x3 (car p3))
    (setq y3 (car (cdr p3)))
    (setq p2 (list x1 y3))
    (setq p4 (list x3 y1))
    (setq disx (distance p1 p4))
    (setq disy (distance p1 p2))
    (SETQ NX (GETINT "\n NUMBER OF X DIR."))
    (SETQ XXN (/ disx (* NX 2)))
    (SETQ DS1 (* XXN 2))
    (SETQ NY (GETINT "\n NUMBER OF Y DIR."))
    (SETQ YYN (/ disy (* NY 2)))
    (SETQ DS2 (* YYN 2))
    (setq xx1 (+ (car p1) XXN))
    (setq yy1 (+ (car (cdr p1)) YYN))
    (setq pp2 (list xx1 yy1))
    (COMMAND "-layer" "m" "M-FIRE-SYMB-P" "c" "2" "" "")
    (COMMAND "INSERT" BB1 pp2 "" "" "")
    ;(COMMAND "ARRAY" "L" "" "R" NY NX DS2 DS1)
    (if (eq NX 1) (COMMAND "ARRAY" "L" "" "R" NY NX DS2))
    (if (eq NY 1) (COMMAND "ARRAY" "L" "" "R" NY NX DS1))
    (if (AND (/= NX 1) (/= NY 1))(COMMAND "ARRAY" "L" "" "R" NY NX DS2 DS1))
    (setvar "osmode" os)
    (PRIN1)
    (PRIN1)
    (PROMPT "\n")
    (PROMPT "\n CREATED by :")
    (PROMPT "\n ********* M.SAIED. ********* ")
    (PRINC)
    );DEFUN[/PHP]
    Last edited by brahmanandam.thadikonda762224; 2018-10-06 at 08:11 AM. Reason: added [CODE] tags

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

    Default Re: Selection of a rectangle instead of asking for two corners

    Once again - PLEASE wrap your lisp code in [CODE] tags!

    This is considered good forum etiquette and makes the thread easier to read. Thank you.
    R.K. McSwain | CAD Panacea |

Similar Threads

  1. 2011: Sweeps - Mitered Corners vs. Radiused Corners
    By chazkelly in forum Revit - Platform
    Replies: 1
    Last Post: 2011-09-14, 11:30 AM
  2. Point insertion from Rectangle-Nodes/Corners
    By matthew.barry591410 in forum AutoCAD General
    Replies: 2
    Last Post: 2011-07-30, 06:57 PM
  3. Replies: 3
    Last Post: 2009-04-15, 07:30 PM
  4. round corners
    By clog boy in forum Revit - Gallery
    Replies: 0
    Last Post: 2008-03-14, 10:25 AM
  5. Replies: 9
    Last Post: 2006-04-14, 07:19 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
  •