Author Topic: Help to complete my routine...  (Read 5168 times)

0 Members and 1 Guest are viewing this topic.

antistar

  • Guest
Help to complete my routine...
« on: September 24, 2012, 08:27:26 AM »
Hi to all,
I'm trying to create a routine that:
- draws a polyline box with user-defined dimensions;
- applies offset=3 inside;
- place two texts from the bottom right corner of the box (BOX1 + dimensions of box below).
I work with centimeters.

Any help will be appreciated.
Thanks in advance.

Code: [Select]
(defun c:BoxTxt ()
   (setq b1 (getstring "Horizontal dimension:"))
   (setq b (atof b1))
   (setq h1 (getstring "Vertical dimension:"))
   (setq h (atof h1))
   (setq na (getint "Insertion point <1/2/3/4/5 - CCW>:"))
   (cond
       ((= na 1) (setq dx 0.0)
                 (setq dy 0.0))
       ((= na 2) (setq  dx (- b))
                 (setq dy 0.0))
       ((= na 3) (setq dx (- b))
                 (setq dy (- h)))
       ((= na 4) (setq dx 0.0)
                 (setq dy (- h)))
       ((= na 5) (setq dx (/ (- b) 2))
                 (setq dy (/ (- h) 2)))
)
   (list (setq pt (getpoint " Point:")))
   (setq pt1 (list (+ (car pt) dx) (+ (cadr pt) dy)))
   (command "pline" pt1
                 (setq p (polar pt1 0 b))
                 (setq p (polar p (/ pi 2) h))
                 (setq p (polar p   0 (- b)))
                  "close")
   (setq m (+ (car pt1) (/ b 2)))
   (setq n (+ (cadr pt1) (/ h 2)))
   (princ)
)
« Last Edit: October 01, 2012, 11:27:06 AM by antistar »

kruuger

  • Swamp Rat
  • Posts: 637
Re: Help to complete my routine...
« Reply #1 on: September 24, 2012, 08:34:12 AM »
why not dynamic block ?
kruuger

antistar

  • Guest
Re: Help to complete my routine...
« Reply #2 on: September 24, 2012, 08:49:18 AM »
why not dynamic block ?
kruuger

I do not know how.  :-(

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Help to complete my routine...
« Reply #3 on: September 24, 2012, 08:57:33 AM »
Quote
I do not know how.

Would you like to learn?

Start by hitting F1 and search for dynamic blocks.  Read up, write down some questions, and come back here - we're here to help.

From what you've described, a dynamic block, from a users standpoint, is easier to edit - manipulate than a static object created by lisp.  Let us know how you would like to proceed . . ..

jb
James Buzbee
Windows 8

kruuger

  • Swamp Rat
  • Posts: 637
Re: Help to complete my routine...
« Reply #4 on: September 24, 2012, 09:05:16 AM »
why not dynamic block ?
kruuger

I do not know how.  :(
attach your drawing here. maybe i can do something.
k.

antistar

  • Guest
Re: Help to complete my routine...
« Reply #5 on: September 24, 2012, 09:22:53 AM »
why not dynamic block ?
kruuger

I do not know how.  :(
attach your drawing here. maybe i can do something.
k.

Thanks kruuger.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Help to complete my routine...
« Reply #6 on: September 24, 2012, 09:50:04 AM »
why not dynamic block ?
kruuger

I do not know how.  :(
attach your drawing here. maybe i can do something.
k.

Thanks kruuger.
try this. during insert the block click CTRL on keyboard to change insertion point.
kruuger

EDIT: try again. now it's a little better
« Last Edit: September 24, 2012, 10:20:30 AM by kruuger »

antistar

  • Guest
Re: Help to complete my routine...
« Reply #7 on: September 24, 2012, 10:38:14 AM »
why not dynamic block ?
kruuger

I do not know how.  :(
attach your drawing here. maybe i can do something.
k.

Thanks kruuger.
try this. during insert the block click CTRL on keyboard to change insertion point.
kruuger

EDIT: try again. now it's a little better

Kruuger,
Thanks a lot for your attention and work.
Dynamic Blocks not serve because I need to move the texts sometimes.
I prefer to create a LISP with simple texts without attributes, as I described in the first post.
If you can help me would be very grateful.

kruuger

  • Swamp Rat
  • Posts: 637
Re: Help to complete my routine...
« Reply #8 on: September 24, 2012, 12:59:48 PM »
why not dynamic block ?
kruuger

I do not know how.  :(
attach your drawing here. maybe i can do something.
k.

Thanks kruuger.
try this. during insert the block click CTRL on keyboard to change insertion point.
kruuger

EDIT: try again. now it's a little better

Kruuger,
Thanks a lot for your attention and work.
Dynamic Blocks not serve because I need to move the texts sometimes.
I prefer to create a LISP with simple texts without attributes, as I described in the first post.
If you can help me would be very grateful.
still can be acheive with dynamic block.
added visibility to turn on/off text.
added move action to change location of text.
is it ok ?
kruuger

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help to complete my routine...
« Reply #9 on: September 24, 2012, 01:11:23 PM »
This ... ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ a b p lw p1 p2 p3)
  2. ;;; Tharwat 24. Sep. 2012 ;;;
  3.   (if (and (setq a (getdist "\n Specify length of Box :"))
  4.            (setq b (getdist "\n Specify width of Box :"))
  5.            (setq p (getpoint "\n Specify Left Bottom corner of Box :"))
  6.       )
  7.     (progn
  8.       (setq
  9.         lw (entmakex (list '(0 . "LWPOLYLINE")
  10.                            '(100 . "AcDbEntity")
  11.                            '(100 . "AcDbPolyline")
  12.                            '(70 . 1)
  13.                            '(90 . 5)
  14.                            '(62 . 6)
  15.                            (cons 10 p)
  16.                            (cons 10 (setq p1 (polar p 0. a)))
  17.                            (cons 10 (setq p2 (polar p1 (/ pi 2.) b)))
  18.                            (cons 10 (setq p3 (polar p2 pi a)))
  19.                            (cons 10 (polar p3 (* pi 1.5) b))
  20.                      )
  21.            )
  22.       )
  23.       (vl-cmdf "_.offset"
  24.                3
  25.                lw
  26.                (mapcar '(lambda (a b) (/ (+ a b) 2.)) p1 p3)
  27.                ""
  28.       )
  29.       (vl-cmdf "_.chprop" (entlast) "" "color" 3 "")
  30.       (entmakex
  31.         (list '(0 . "TEXT")
  32.               (cons 7 (getvar 'textstyle))
  33.               (cons 10 (polar (polar p1 0. 10.) (* pi 1.5) 25.))
  34.               '(1 . "BOX1")
  35.               '(40 . 10.)
  36.         )
  37.       )
  38.       (entmakex
  39.         (list '(0 . "TEXT")
  40.               (cons 7 (getvar 'textstyle))
  41.               (cons 10 (polar (polar p1 0. 10.) (* pi 1.5) 40.))
  42.               (cons 1 (strcat (rtos a 2) " x " (rtos b 2)))
  43.               '(40 . 10.)
  44.         )
  45.       )
  46.     )
  47.     (princ)
  48.   )
  49.   (princ)
  50. )

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Help to complete my routine...
« Reply #10 on: September 24, 2012, 01:27:20 PM »
Not to detract from kruuger's excellent dynamic block work, but here is a very simple way to code it:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mybox ( / a b p1 p2 )
  2.     (if (and
  3.             (setq a (getpoint "\nSpecify first corner: "))
  4.             (setq b (getcorner a "\nSpecify opposite corner: "))
  5.         )
  6.         (progn
  7.             (setq p1 (mapcar 'min a b)
  8.                   p2 (mapcar 'max a b)
  9.             )
  10.             (mypbox p1 p2)
  11.             (mypbox (mapcar '- p1 '(3 3)) (mapcar '+ p2 '(3 3)))
  12.             (mytext (list (+ (car p2) 13) (- (cadr p1) 28)) "BOX1")
  13.             (mytext (list (+ (car p2) 13) (- (cadr p1) 45))
  14.                 (strcat (rtos (- (car p2) (car p1))) " x " (rtos (- (cadr p2) (cadr p1))))
  15.             )
  16.         )
  17.     )
  18.     (princ)
  19. )
  20.  
  21. (defun mypbox ( a b )
  22.     (entmakex
  23.         (list
  24.            '(0 . "LWPOLYLINE")
  25.            '(100 . "AcDbEntity")
  26.            '(100 . "AcDbPolyline")
  27.            '(90 . 4)
  28.            '(70 . 1)
  29.             (list 10 (car a) (cadr a))
  30.             (list 10 (car b) (cadr a))
  31.             (list 10 (car b) (cadr b))
  32.             (list 10 (car a) (cadr b))
  33.         )
  34.     )
  35. )
  36.        
  37. (defun mytext ( p s )
  38.     (entmakex
  39.         (list
  40.            '(0 . "TEXT")
  41.             (cons 10 p)
  42.             (cons 07 (getvar 'textstyle))
  43.             (cons 40 (getvar 'textsize))
  44.             (cons 01 s)
  45.         )
  46.     )
  47. )

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help to complete my routine...
« Reply #11 on: September 24, 2012, 01:40:50 PM »
Good job kruuger .

I am sorry i did not see your attached drawing , and that's why i wrote a few lines of code to help the OP .  :-(

antistar

  • Guest
Re: Help to complete my routine...
« Reply #12 on: September 24, 2012, 02:07:09 PM »
why not dynamic block ?
kruuger

I do not know how.  :(
attach your drawing here. maybe i can do something.
k.

Thanks kruuger.
try this. during insert the block click CTRL on keyboard to change insertion point.
kruuger

EDIT: try again. now it's a little better

Kruuger,
Thanks a lot for your attention and work.
Dynamic Blocks not serve because I need to move the texts sometimes.
I prefer to create a LISP with simple texts without attributes, as I described in the first post.
If you can help me would be very grateful.
still can be acheive with dynamic block.
added visibility to turn on/off text.
added move action to change location of text.
is it ok ?
kruuger


Kruuger,
Excellent work.
Thanks a lot for your help.

antistar

  • Guest
Re: Help to complete my routine...
« Reply #13 on: September 24, 2012, 02:16:52 PM »
This ... ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ a b p lw p1 p2 p3)
  2. ;;; Tharwat 24. Sep. 2012 ;;;
  3.   (if (and (setq a (getdist "\n Specify length of Box :"))
  4.            (setq b (getdist "\n Specify width of Box :"))
  5.            (setq p (getpoint "\n Specify Left Bottom corner of Box :"))
  6.       )
  7.     (progn
  8.       (setq
  9.         lw (entmakex (list '(0 . "LWPOLYLINE")
  10.                            '(100 . "AcDbEntity")
  11.                            '(100 . "AcDbPolyline")
  12.                            '(70 . 1)
  13.                            '(90 . 5)
  14.                            '(62 . 6)
  15.                            (cons 10 p)
  16.                            (cons 10 (setq p1 (polar p 0. a)))
  17.                            (cons 10 (setq p2 (polar p1 (/ pi 2.) b)))
  18.                            (cons 10 (setq p3 (polar p2 pi a)))
  19.                            (cons 10 (polar p3 (* pi 1.5) b))
  20.                      )
  21.            )
  22.       )
  23.       (vl-cmdf "_.offset"
  24.                3
  25.                lw
  26.                (mapcar '(lambda (a b) (/ (+ a b) 2.)) p1 p3)
  27.                ""
  28.       )
  29.       (vl-cmdf "_.chprop" (entlast) "" "color" 3 "")
  30.       (entmakex
  31.         (list '(0 . "TEXT")
  32.               (cons 7 (getvar 'textstyle))
  33.               (cons 10 (polar (polar p1 0. 10.) (* pi 1.5) 25.))
  34.               '(1 . "BOX1")
  35.               '(40 . 10.)
  36.         )
  37.       )
  38.       (entmakex
  39.         (list '(0 . "TEXT")
  40.               (cons 7 (getvar 'textstyle))
  41.               (cons 10 (polar (polar p1 0. 10.) (* pi 1.5) 40.))
  42.               (cons 1 (strcat (rtos a 2) " x " (rtos b 2)))
  43.               '(40 . 10.)
  44.         )
  45.       )
  46.     )
  47.     (princ)
  48.   )
  49.   (princ)
  50. )

Tharwat,
Great work, it's almost as requested.
I would add the option to enter the box by 5 points in CCW.
Is this possible?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help to complete my routine...
« Reply #14 on: September 24, 2012, 02:18:54 PM »
Good code examples Lee & Tharwat.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.