Jump to content

Room dimension lisp


rose sr

Recommended Posts

hello everyone , hope u all doing so great 🙏... i am new to this cad tutor ,tried searching lisp what i wanted but could not found. so please can any one help me with lisp of room dimension. following step i need from it.

 

1.selection diagonal points of the rectangular room.

2 .asking for room name to type

3.placing M-TEXT in side room,

final outcome is 

LIVING ROOM

3000X5000

hope somebody could help me in this ... thanks in advance

Link to comment
Share on other sites

How is your LISP programming? Would I be telling you what you know if I wrote this all out fully or would it all be new to you?

 

I'll meet you half way and give you the basics of what I think you'll need - mostly because the other night I posted what is below (plus a few other bits) just deleted what you don't want so try this (from 

 

 

try this:

(defun c:testthis ( / a b c d scpt1 mywidth myheight)
  (setq
    spt1 (getpoint "\nPick the first point")
    spt3 (getcorner "\Pick the next corner" spt1)
    a (if (< (car spt1)(car spt3))(car spt1)(car spt3)) ;;Lower Left X coord
    b (if (> (car spt1)(car spt3))(car spt1)(car spt3)) ;;Upper Right X coord
    c (if (< (cadr spt1)(cadr spt3))(cadr spt1)(cadr spt3)) ;;Lower Left y Coord
    d (if (> (cadr spt1)(cadr spt3))(cadr spt1)(cadr spt3)) ;;Upper Right Y Coord
  )

  (setq mywidth (abs (- a b)))
  (setq myheight (abs (- c d)))

  ;;center points
  (setq
    scpt1 (list (/ (+ a b) 2) (/ (+ c d) 2))
  )

(command "text" scpt1 2.5 0 "Text Here" "")

)

 

 

You'll need to work out the text input yourself and the final text but this will give you the basics - if you struggle with the other parts just shout and we can fill in the rest of the details

 

 

 

  • Like 1
Link to comment
Share on other sites

Create your Mtext with contents with respect to alignments Middle Center if required then move it via specifying the two points diagonally.

Link to comment
Share on other sites

OK So it you might have made something like this if you got it to work:

 

(defun c:testthis ( / spt1 spt2 roomname a b c d scpt1 mywidth myheight) ;; after the '/' are local variable names
  (setq                                                                  ;;setq: Tells LISP you are setting a variable
    spt1 (getpoint "\nPick the first point")                             ;;should be obvious what this does
    spt3 (getcorner "\nPick the next corner" spt1)                       ;;should be obvious what this does
    roomname (getstring "\nEnter Room Name: " T)                         ;;T allows spaces, else space acts as a return
    a (if (< (car spt1)(car spt3))(car spt1)(car spt3)) ;;Lower Left X coord car gives first item in a list, here x coord
    b (if (> (car spt1)(car spt3))(car spt1)(car spt3)) ;;Upper Right X coord
    c (if (< (cadr spt1)(cadr spt3))(cadr spt1)(cadr spt3)) ;;Lower Left y Coord cadr gives second item in a list, here y coord
    d (if (> (cadr spt1)(cadr spt3))(cadr spt1)(cadr spt3)) ;;Upper Right Y Coord
  )

  (setq mywidth (abs (- a b)))                                           ;;abs for absolute value (witohut = or -), (- is subtract
  (setq myheight (abs (- c d)))

  ;;center points
  (setq scpt1 (list (/ (+ a b) 2) (/ (+ c d) 2)) )                       ;;create a coordinate which is a list (/ for divide (+ for add

  (command "mtext" scpt1 "J" "MC" scpt1 (strcat roomname "\n" (rtos mywidth 2 2) " x " (rtos myheight 2 2 )) "")
                              ;;Command echos what you'd type in command line, anything in "" is a fixed value in else it is calculated
)

 

Put a few notes in if you want to learn how it does what it does

  • Like 4
Link to comment
Share on other sites

@Steven P

You can also subtract the X's and the Y's to get W and H.

(and (setq p1 (getpoint))
     (setq p2 (getcorner p1))
     (setq r (mapcar 'abs (mapcar '- p1 p2)))
     (mapcar 'print r)
)
  • Like 1
Link to comment
Share on other sites

And easy midpoint of two points add them up and divide x y and z by 2

(setq mpt (mapcar '/ (mapcar '+ pt1 pt2) '(2 2 2)))

 

  • Like 2
Link to comment
Share on other sites

And easy midpoint of two points add them up and divide x y and z by 2

inverse answer

(setq mpt (mapcar '* (mapcar '+ pt1 pt2) '(0.5  0.5  0.5)))

  • Like 2
Link to comment
Share on other sites

  • 1 year later...
On 5/20/2022 at 6:48 PM, Steven P said:

OK So it you might have made something like this if you got it to work:

 

(defun c:testthis ( / spt1 spt2 roomname a b c d scpt1 mywidth myheight) ;; after the '/' are local variable names
  (setq                                                                  ;;setq: Tells LISP you are setting a variable
    spt1 (getpoint "\nPick the first point")                             ;;should be obvious what this does
    spt3 (getcorner "\nPick the next corner" spt1)                       ;;should be obvious what this does
    roomname (getstring "\nEnter Room Name: " T)                         ;;T allows spaces, else space acts as a return
    a (if (< (car spt1)(car spt3))(car spt1)(car spt3)) ;;Lower Left X coord car gives first item in a list, here x coord
    b (if (> (car spt1)(car spt3))(car spt1)(car spt3)) ;;Upper Right X coord
    c (if (< (cadr spt1)(cadr spt3))(cadr spt1)(cadr spt3)) ;;Lower Left y Coord cadr gives second item in a list, here y coord
    d (if (> (cadr spt1)(cadr spt3))(cadr spt1)(cadr spt3)) ;;Upper Right Y Coord
  )

  (setq mywidth (abs (- a b)))                                           ;;abs for absolute value (witohut = or -), (- is subtract
  (setq myheight (abs (- c d)))

  ;;center points
  (setq scpt1 (list (/ (+ a b) 2) (/ (+ c d) 2)) )                       ;;create a coordinate which is a list (/ for divide (+ for add

  (command "mtext" scpt1 "J" "MC" scpt1 (strcat roomname "\n" (rtos mywidth 2 2) " x " (rtos myheight 2 2 )) "")
                              ;;Command echos what you'd type in command line, anything in "" is a fixed value in else it is calculated
)

 

Put a few notes in if you want to learn how it does what it does

THIS WORKS PERFECTLY IN METRIC DRAWING, HOW CAN I USE THE IN IMPERIAL DRAWING?

LIKE -

BEDROOM

12'-0"x14'-0"

Link to comment
Share on other sites

4 hours ago, faizur said:

THIS WORKS PERFECTLY IN METRIC DRAWING, HOW CAN I USE THE IN IMPERIAL DRAWING?

LIKE -

BEDROOM

12'-0"x14'-0"

 

Barely an inconvenience..... if you look through the code near the end you should find a line or 2 to create some mtext (command "mtext"......

 

change

(command "mtext" scpt1 "J" "MC" scpt1 (strcat roomname "\n" (rtos mywidth 2 2) " x " (rtos myheight 2 2 )) "")

 

to

(command "mtext" scpt1 "J" "MC" scpt1 (strcat roomname "\n" (rtos mywidth 3 2) " x " (rtos myheight 3 2 )) "")

 

the difference is the RTOS mode for mywidth and myheight. That should do it.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...