Jump to content

Autolisp routine problem


aswad

Recommended Posts

Hi Guys

 

as you can see , this is the coding for doing rectangle routine by put the length of rec .. the problem is ,

 

i want to put the circle in the rectangle in a row which is i need to specify how much the circle i want ..

 

the length between circle must be 109.00 inch

 

 

 

(defun c:SREC ( / pt h)

 

(princ " RECTANGLE ")

 

(if (and (setq pt (getpoint "\nSpecify rectangle start point: "))

 

(setq h (getreal "\nEnter the rectangle length: ")))

 

(command "._rectang" pt "_dimensions" ( + 0 h) h pt)

 

(prompt "\n** Invalid input ** "))

 

(princ))

 

 

 

: the example is attached :

 

 

 

I really appreciate for those who willing to help me :):):D:D

2750 , 109.dwg

Link to comment
Share on other sites

As you have already started here is some advice rather than code, hopefully it makes sense, if your stuck post again, a good example for learning lisp. I would like to think you can learn from here rather than others just post code answer.

 

You can do this in a couple of ways but look at the math

length =L

Offset = 109.0

Num = divide L/109 (set num (/ L offset))

Remainder (* L (- num (fix num)))

Pt x (car pt) pt y (cadr pt)

Is remainder > 2*circ dia (if (> (* 2.0 dia... if yes then continue if no num=num-1 circle to close to edge (setq num (- num 1))

Work out now 1st circle placement (set q newpt (polar pt ....(polar pt .. X across y up a double polar

then copy and repeat num times across (repeat (fix num)....

do again for top row you could use array also rather than copy or circle command

Edited by BIGAL
Link to comment
Share on other sites

Assuming height is constant and the length varies you could create a dynamic block that would add or remove circles depending on the length. It could also be done easily in lisp, just a suggestion in case you might be more comfortable doing it that way.

Link to comment
Share on other sites

Hi,

 

The Dynamic Block is the best choice with this trick as recommended by tombu but here is my lisp program if you don't want to go with Dynamic Block option .

 

(defun c:Test (/ _C rad spc len pt r p d)
 ;;    Tharwat 04.07.2015    ;;
 (setq rad 3.5 spc 109.0 )
 (if
   (and (setq len (getdist "\nSpecify Length of Rectangle :"))
        (if (< 109 len)
          t
          (progn (princ "\nLength of rectangle is smaller than 109.0 !") nil )
        )
        (setq pt (getpoint "\nSpecify Rectangle Base point :"))
   )
    (progn
      (defun _C (n _p)
        (repeat n
          (entmakex (list '(0 . "CIRCLE") (cons 10 _p) (cons 40 rad)))
          (setq _p (polar _p 0. spc))
        )
      )
      (setq r (1+ (fix (/ len 109.0)))
            p (polar (polar pt 0. (setq d (/ (- len (* (fix r) 109.)) 2.))) (* pi 1.5) 12. )
      )
      (command "_.rectang" "_none" pt "_none" (polar (polar pt 0. len) (* pi 1.5) len))
      (_C r p)
      (_C r (setq p (polar (polar pt (* pi 1.5) (- len 12.)) 0. d))
      )
    )
 )
 (princ)
)

Link to comment
Share on other sites

  • 3 weeks later...

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...