Selection of a rectangle instead of asking for two corners

Selection of a rectangle instead of asking for two corners

Anonymous
Not applicable
4,842 Views
31 Replies
Message 1 of 32

Selection of a rectangle instead of asking for two corners

Anonymous
Not applicable

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

(defun C:LRR (/ c1 c2 wid ht rows cols blk); = Lights in Rectangular [& orthogonal] Room

  (setq

    c1 (getpoint "\nCorner of room: ")

    c2 (getpoint "\nOpposite corner: ")

    wid (abs (- (car c1) (car c2)))

    ht (abs (- (cadr c1) (cadr c2)))

    rows (getint "\nNumber of rows (---): ")

    cols (getint "\nNumber of columns (|||): ")

    blk (cdr (assoc 2 (entget (car (entsel "\n Select Block")))))

  ); setq

  (command

    "_.minsert" blk

    (mapcar '+ ; insertion point

      (list (min (car c1) (car c2)) (min (cadr c1) (cadr c2))); lower left of room

 

      (list (/ wid cols 2) (/ ht rows 2)); fractions of width/height

    ); mapcar

    "" "" "" ; X, Y, rotation defaults -- edit if needed

    rows cols (/ ht rows) (/ wid cols); numbers and spacings

  ); command

  (princ)); defun

0 Likes
Replies (31)
Message 21 of 32

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

... the code should ask for block rotation and block scale. Because in some room locations I need other than default angle and also scale to be changed for some rooms. ….


 

You can just change this line:
  "_.insert" blk "_none" (mapcar '+ LL (list (/ colsp 2) (/ rowsp 2))) "" "" ""

to this:

  "_.insert" blk "_none" (mapcar '+ LL (list (/ colsp 2) (/ rowsp 2))) pause "" pause

Kent Cooper, AIA
Message 22 of 32

Anonymous
Not applicable

Dear Sir,

 

I have updated the existing code with your hint but it's not asking for rotation angle (in degrees) or scale factor as user input.

 

Thank you Sir.

0 Likes
Message 23 of 32

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... it's not asking for rotation angle (in degrees) or scale factor as user input. ….


 

Oh, yes -- that would be my fault -- I forgot it turns off command echoing.  Try changing it to this instead:

  "_.insert" blk

    "_none" (mapcar '+ LL (list (/ colsp 2) (/ rowsp 2))); insertion point

    (getreal "\nScale factor: "); for X

    "" ; Y scale factor = X scale factor

    (getangle "\nRotation: ")

Kent Cooper, AIA
Message 24 of 32

Anonymous
Not applicable

Dear Sir,

The code is working for Scale factor and not working with rotation angle. It's not taking User input. Please see how I have inserted your code in original code. Is there any mistake I have done while inserting your code into original code?

 

(vl-load-com)
(defun C:CRM ; = Array Block in Rectangle(s)
(/ *error* ABRia doc svnames svvals P1 rectss n P3)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
(princ (strcat "\nError: " errmsg))
); if
(if ucschanged (command-s "_.ucs" "_previous"))
; [change to (command ... if Acad version predates (command-s) function]
(mapcar 'setvar svnames svvals); reset System Variables
(vla-endundomark doc)
(princ)
); defun - *error*
(defun ABRia (/ delta LL NX NY colsp rowsp); = ABR Insert & Array
(setq
delta (mapcar 'abs (mapcar '- P3 P1)); differences in XYZ list
LL (mapcar 'min P1 P3)
; Lower Left regardless of pick order or Pline start or direction
colsp (/ (car delta) cols)
rowsp (/ (cadr delta) rows)
); setq
(command
"_.insert" blk "_none" (mapcar '+ LL (list (/ colsp 2) (/ rowsp 2))); insertion point
(getreal "\nScale factor: "); for X

"" ; Y scale factor = X scale factor

(getangle "\nRotation: ")
"_.array" "_last" "" "_r" rows cols rowsp colsp
); command
); defun -- ABRia
(vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(setq ; System Variable saving/resetting without separate variables for each:
svnames '(cmdecho ucsfollow osmode blipmode)
svvals (mapcar 'getvar svnames)
blk (cdr (assoc 2 (entget (car (entsel "\n Select Block")))))
rows (getint "\nNumber of columns (|||): ")
cols (getint "\nNumber of rows (---): ")
); setq
(mapcar 'setvar svnames '(0 0)); turn off command echoing, UCS follow
(initget "Select"); allows S as input to (getpoint) function, instead of point pick
(setq P1 (getpoint "\nFirst Corner of ortho-rectangular area for Blocks, or [Select]: "))
; [if in non-World UCS, returns in current UCS coordinates, not in WCS]
(if (= P1 "Select"); chose that option
(progn ; then
(prompt "\nTo Array Blocks in Rectangular Polyline(s),")
(if (setq rectss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&") (70 . 1))))
; multiple selection -- only 4-vertex closed [does not check for rectangularity]
(progn ; then
(mapcar 'setvar svnames '(0 0 0 0)); also turn off Osnap, blips
(repeat (setq n (sslength rectss)); step through selection
(setq rect (ssname rectss (setq n (1- n))))
(command "_.ucs" "_object" rect)
(setq
ucschanged T ; marker for resetting in *error*
P1 (trans (vlax-curve-getPointAtParam rect 0) 0 1); starting vertex
P3 (trans (vlax-curve-getPointAtParam rect 2) 0 1); third vertex [opposite corner]
); setq
(ABRia); run the subroutine to MINSERT
(command "_.ucs" "_previous")
(setq ucschanged nil); [turn off marker]
); repeat
); progn
(prompt "\nNo closed 4-vertex Polyline(s) selected."); else
); if
); progn
(progn ; else [picked a point]
(setq P3 (getcorner P1 "\nOpposite Corner: "))
(mapcar 'setvar svnames '(0 0 0 0)); also turn off Osnap, blips
(ABRia); run the subroutine to MINSERT
); progn
); if
(mapcar 'setvar svnames svvals); reset System Variables
(vla-endundomark doc)
(princ)
); defun -- C:CRM

0 Likes
Message 25 of 32

dbhunia
Advisor
Advisor
Accepted solution

Hi Brahmanandam,

 

Sorry for late reply...(Actually whatever you asked after 6:30 PM from Friday I was unable to give you any reply, because outside office I do not have Latest version of AutoCAD, I personally use AutoCAD 2007. So I was unable to test your drawing.)

 

Try this Modified code.......

 

Debashis


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 26 of 32

Anonymous
Not applicable

Dear Sir,

 

Thank you very much. It's working fine but suppose if I have 10 rooms with same requirement then the lisp code should not ask 10 times for scale factor and rotation angle for each room. The lisp should consider the same rotation angle and same scale factor for all rooms (Recangles). Thank you in advcnce

 

Regards,

T.Brahmanandam.

0 Likes
Message 27 of 32

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

Try this.......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 28 of 32

Anonymous
Not applicable

Dear Sir,

 

The rotation angle is not applying as uniform for all rooms, It's varying for all rooms depends upon their inclination. Please have a look on attachments.

0 Likes
Message 29 of 32

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

It's measuring the angle with respect to the each Rectangle which is "45 degree"...... as per your input angle.......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 30 of 32

Anonymous
Not applicable

Dear Sir,

 

Thank you for your clarification. But is it possible to take ignore to take angle from respective room?. It should take onlt user input angle not respective to room orientation. Thank you in advance Sir.

0 Likes
Message 31 of 32

dbhunia
Advisor
Advisor
Accepted solution

@Anonymous wrote:

Dear Sir,

 

Thank you for your clarification. But is it possible to take ignore to take angle from respective room?. It should take onlt user input angle not respective to room orientation. Thank you in advance Sir.


 

Hi,

 

Try this.....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 32 of 32

Anonymous
Not applicable

Thank you so much Sir,

 

Working fine. I appreciate your hard work towards my requirement. Thank you

0 Likes