Jump to content

Making a polyline box using lisp


Recommended Posts

Guest lesliematt
Posted

I am working on a lisp will start a polyline at coordinates that i choose. then it will automatically go in the direction of 90 degrees, input a distance, it automatically goes to 0 degrees, and again enter a distance, and then it will automatically finish the box.

 

so pretty much i want a program that will make a polyline box starting at a user specified location, and all i will have to input is a length and a width and it will make it. i need it to be a polyline and not a rectangle because i need to specify a global width. if there is an easier way, please help. lol

 

 

(defun C:plx()

 

(command "layer" "s" "Plate" "")

(command "pline" pause "

 

(princ))

 

 

M

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    13

  • alanjt

    7

  • Tharwat

    4

Top Posters In This Topic

Posted Images

Guest lesliematt
Posted

actually i realized i could make it with a rectangle and then us pedit to change it to a polyline.

Guest lesliematt
Posted

C:\Users\mleslie\Desktop\Project Polyline\block.jpg

 

I need to figure out how to make a poly line that will force angles, and all the user needs to do is put in lengths to make an object like this ^

Posted

Its not that hard to make , you need to know the varies lengths of your pose and with " polar " function you can create it easily.

 

Regards

 

Tharwat

Posted

Some fun :D

 

(defun c:rect ( / p1 p2 )
 ;; © Lee Mac 2010

 (if (and (setq p1 (getpoint "\nSpecify Pick Corner: "))
          (setq p2 (getcorner "\nSpecift Opposite Corner: " p1)))

   (LM:Rectangle p1 p2 (trans '(0. 0. 1.) 1 0 t))
 )
 (princ)
)


(defun LM:Rectangle ( ll ur norm )
 ;; © Lee Mac 2010
 (entmakex
   (append
     (list
       (cons 0 "LWPOLYLINE")
       (cons 100 "AcDbEntity")
       (cons 100 "AcDbPolyline")
       (cons 90 4)
       (cons 70 1)
       (cons 38 (caddr ll))
       (cons 210 norm)
     )
     (mapcar '(lambda ( p ) (cons 10 p))
       (
         (lambda ( data )
           (mapcar
             '(lambda ( funcs )
                (mapcar
                  '(lambda ( func )
                     ((eval func) data)
                   )
                  funcs
                )
              )
            '((caar   cadar) (caadr  cadar)
              (caadr cadadr) (caar  cadadr))
           )
         )
         (mapcar '(lambda ( p ) (trans p 1 norm))
           (list ll ur)
         )
       )
     )
   )
 )
)

Posted

Straight out of my toolbox...

 

(defun c:SQ (/ foo p1 pt w h p2 ent)
 ;; Draw square polygon at specified height and width (with option to rotate)
 ;; Alan J. Thompson
 (defun foo (p) (list 10 (car p) (cadr p)))

 (if (and (setq p1 (getpoint "\nSpecify NorthWest corner of rectangle: "))
          (setq w (getdist "\nSpecify width: "))
          (setq h (cond ((getdist (strcat "\nSpecify height <" (rtos w) ">: ")))
                        (w)
                  )
          )
     )
   (progn
     (setq p2 (polar (setq pt (trans p1 1 0)) 0. w))
     (if (setq ent (entmakex
                     (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
                                   '(90 . 4) '(70 . 1)
                                  )
                             (mapcar 'foo
                                     (list pt p2 (polar p2 (* 1.5 pi) h) (polar pt (* 1.5 pi) h))
                             )
                     )
                   )
         )
       (command "_.rotate" ent "" "_non" p1 "_r" "_non" p1 "_non" (trans p2 0 1))
     )
   )
 )
 (princ)
)

Posted

Oops, I didn't notice you posted something Lee. BTW, is there any difference in yours and the command Rectangle (other than it won't match the current UCS angle and always be parallel to view)?

Posted
Oops, I didn't notice you posted something Lee. BTW, is there any difference in yours and the command Rectangle (other than it won't match the current UCS angle and always be parallel to view)?

 

No difference - just experimenting. That's the problem with getcorner... :geek:

Posted
No difference - just experimenting. That's the problem with getcorner... :geek:

Right on. I figured you were just playing. :)

 

I know, it's sooooo aggravating.

Posted
I know, it's sooooo aggravating.

 

Yeah, and any imitation would lack OSnap rendering it useless.. :x

Posted
Yeah, and any imitation would lack OSnap rendering it useless.. :x

 

I know. I wish ADesk would be nice to the world and release an update of VLisp or something. I know I need to learn C, but you just can't fight the speed of LISP programming. That's why I use/write so many subs. I'll write quick stuff in the office to perform a very specific task for the day and I'll use 20 subs.

Posted
I know. I wish ADesk would be nice to the world and release an update of VLisp or something. I know I need to learn C, but you just can't fight the speed of LISP programming. That's why I use/write so many subs. I'll write quick stuff in the office to perform a very specific task for the day and I'll use 20 subs.

 

Exactly - that's why I'm struggling so hard to learn C++ or anything more advanced... its just too easy to slip back into the (relatively) easy world of LISP...

 

I hope that Swamp thread regarding VL being improved does materialise eventually - it would be fantastic for VL to be enhanced.

 

PS> Ooo.. Quantum Mechanic :P

Posted
Exactly - that's why I'm struggling so hard to learn C++ or anything more advanced... its just too easy to slip back into the (relatively) easy world of LISP...

 

I hope that Swamp thread regarding VL being improved does materialise eventually - it would be fantastic for VL to be enhanced.

 

PS> Ooo.. Quantum Mechanic :P

Yeah, I'm with you on learning a more powerful language. My issue is that I have a job/wife/kid where you have additional time to learn the language. I'll pick up a book soon, but I'll never be able to leave LISP behind for the amount of time a 5 min. routine can save.
Posted
My issue is that I have a job/wife/kid where you have additional time to learn the language.

 

Well - perhaps for this week, but I start my summer job in the next couple of weeks so I won't have the time either... :geek:

Posted
Well - perhaps for this week, but I start my summer job in the next couple of weeks so I won't have the time either... :geek:
HaHa, have a kid and see how little free time you have. :wink:

 

What're you doing for the summer?

Posted
What're you doing for the summer?

 

Hopefully some CAD work if all goes to plan :D

Posted
Hopefully some CAD work if all goes to plan :D
Come to Florida, you can work with me.:lol:
Guest lesliematt
Posted
Straight out of my toolbox...

 

(defun c:SQ (/ foo p1 pt w h p2 ent)
 ;; Draw square polygon at specified height and width (with option to rotate)
 ;; Alan J. Thompson
 (defun foo (p) (list 10 (car p) (cadr p)))

 (if (and (setq p1 (getpoint "\nSpecify NorthWest corner of rectangle: "))
          (setq w (getdist "\nSpecify width: "))
          (setq h (cond ((getdist (strcat "\nSpecify height <" (rtos w) ">: ")))
                        (w)
                  )
          )
     )
   (progn
     (setq p2 (polar (setq pt (trans p1 1 0)) 0. w))
     (if (setq ent (entmakex
                     (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
                                   '(90 . 4) '(70 . 1)
                                  )
                             (mapcar 'foo
                                     (list pt p2 (polar p2 (* 1.5 pi) h) (polar pt (* 1.5 pi) h))
                             )
                     )
                   )
         )
       (command "_.rotate" ent "" "_non" p1 "_r" "_non" p1 "_non" (trans p2 0 1))
     )
   )
 )
 (princ)
)

 

 

This works well. I am fairly new to using lisp tho. i will see how far i can get making the object i previously posted.

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