Jump to content
oturk1

Arrow Lisp

Recommended Posts

oturk1

HI All,

 

I'm trying to create a set of lisp routines which will create a polyline arrow.

 

for example:

 

Id like to draw a polyline with a width of 400 at any given length, but once the length is determined, id like it to insert an arrow head which has a starting width of 2.5x the width narrowing to 0. the length of the arrowhead should also be 2.5x the width of the polyline. id also like the arrow head to carry on at the same angle the polyline has been drawn at.

 

im at a complete loss as to how to lisp this into a routine with variable polyline widths.

 

any help would be most appreciated.

Share this post


Link to post
Share on other sites
Jonathan Handojo

There was a similar topic posted here, except that the post there was that there were different scales that the user needs to draw the polyline at. In that post, I proposed a solution that has settings available that the user can add and edit (such as the linetype, scale, width, layer, etc...), but it's just the arrowhead that needs to be changed. Let me know if that's something close to what you want and I'll tweak it a bit.

Share this post


Link to post
Share on other sites
oturk1
1 minute ago, Jonathan Handojo said:

There was a similar topic posted here, except that the post there was that there were different scales that the user needs to draw the polyline at. In that post, I proposed a solution that has settings available that the user can add and edit (such as the linetype, scale, width, layer, etc...), but it's just the arrowhead that needs to be changed. Let me know if that's something close to what you want and I'll tweak it a bit.

 

I'm pretty open to ideas, i was going to just call each lisp by pa200, pa400, pa600 etc.then type the command based on what sized line and arrow was required - the arrowhead size would always be 2.5x the width and length of the polyline width so could effectively just create a new routine for each size for ease - i assume that would remove the requirement for bespoke user input?

 

i have added the two separate parts to a tool palette (polyline with a set width and a polyline with starting width/end width), however it isn't the quickest method to have to insert both separately, and it doesn't allow for the arrowhead to be drawn at the exact same angle as the PL.

 

im sure it seems trivial, but im creating some social distancing plans for a few clients and am drawing a lot of one directional corridors (most of which are angular and not straight lines). im finding its taking a lot of effort to keep the arrowheads in perfect line and want to finesse it to make life easier!

 

thank you for your reply.

 

Share this post


Link to post
Share on other sites
hanhphuc
Posted (edited)
On 5/16/2020 at 8:14 PM, oturk1 said:

 

I'm pretty open to ideas, i was going to just call each lisp by pa200, pa400, pa600 etc.then type the command based on what sized line and arrow was required - the arrowhead size would always be 2.5x the width and length of the polyline width 

 

 

test 

(defun pa#width (lst / $ sym)
  ;hp 16.05.2020
  (foreach x lst
    
   (if (setq $ (strcat "pa" (itoa x))
          sym (read $)
       )
      (vlax-remove-cmd $)
      )
   
   (set sym
         (list '(/ p1 p2 w)  (list 'setq 'w x) ;(cons 'setq (list 'w x))
               (list 'and
                     '(setq p1 (getpoint "\nSpecify P1 "))
                     '(setq p2 (getpoint p1 "\nSpecify P2 "))
                     '(mapcar '(lambda (p) (set p (trans (eval p) 1 0))) '(p1 p2))
                     '(entmakex
                        (vl-list* '(0 . "LWPOLYLINE")
                                  '(100 . "AcDbEntity")
                                  '(100 . "AcDbPolyline")
                                  '(70 . 0)
                                  '(90 . 3)
                                  (apply 'append
                                         (mapcar '(lambda (a b c) (list (cons 10 a) (cons 40 b) (cons 41 c)))
                                                 (list p1 (polar p1 (angle p1 p2) (- (distance p1 p2) (* 2.5 w))) p2)
                                                 (list w (* 2.5 w) 0.0)
                                                 (list w 0.0 0.0)
                                         )
                                  )
                        )
                      )
               )
               '(princ)
         )
    )
    (vlax-add-cmd $ sym)
  )
  (princ)
)

 

setup width (integer only & not -ve)

( pa#width '(200 400 600) )

 

then try these command

pa200

pa400

pa600

 

p/s: This is not a new idea, inspired by Lee & BIGAL who implemented in acad command. eg: F100 = Fillet 100 here

 

 

 

Edited by hanhphuc
typo AcDbPolyline

Share this post


Link to post
Share on other sites
BIGAL

Nice one of having different sizes as commands, I would have done old fashioned using my multi radio buttons for size choice.

 

(setq ans  (ah:butts but "V"   '("Choose Size " "  100" "  200" "  300" "  400" "  500" "  600" "  700")))

Share this post


Link to post
Share on other sites
oturk1
On 5/16/2020 at 4:50 PM, hanhphuc said:

 

test 


(defun pa#width (lst / $ sym)
  ;hp 16.05.2020
  (foreach x lst
    
   (if (setq $ (strcat "pa" (itoa x))
          sym (read $)
       )
      (vlax-remove-cmd $)
      )
   
   (set sym
         (list '(/ p1 p2 w)  (list 'setq 'w x) ;(cons 'setq (list 'w x))
               (list 'and
                     '(setq p1 (getpoint "\nSpecify P1 "))
                     '(setq p2 (getpoint p1 "\nSpecify P2 "))
                     '(mapcar '(lambda (p) (set p (trans (eval p) 1 0))) '(p1 p2))
                     '(entmakex
                        (vl-list* '(0 . "LWPOLYLINE")
                                  '(100 . "AcDbEntity")
                                  '(100 . "AcDbLWPolyline")
                                  '(70 . 0)
                                  '(90 . 3)
                                  (apply 'append
                                         (mapcar '(lambda (a b c) (list (cons 10 a) (cons 40 b) (cons 41 c)))
                                                 (list p1 (polar p1 (angle p1 p2) (- (distance p1 p2) (* 2.5 w))) p2)
                                                 (list w (* 2.5 w) 0.0)
                                                 (list w 0.0 0.0)
                                         )
                                  )
                        )
                      )
               )
               '(princ)
         )
    )
    (vlax-add-cmd $ sym)
  )
  (princ)
)

 

setup width (integer only & not -ve)


( pa#width '(200 400 600) )

 

then try these command

pa200

pa400

pa600

 

p/s: This is not a new idea, inspired by Lee & BIGAL who implemented in acad command. eg: F100 = Fillet 100 here

 

 

 

Hi, thanks very much for tis, i added as a lisp in applaod but getting unknown command in CAD? am i missing a command to call the lisp?

 

Share this post


Link to post
Share on other sites
oturk1
10 minutes ago, oturk1 said:

Hi, thanks very much for tis, i added as a lisp in applaod but getting unknown command in CAD? am i missing a command to call the lisp?

 

 

i now get "error - too few arguments"?

Share this post


Link to post
Share on other sites
oturk1

sorry to be pain, pretty new to all of this, i have managed to get the commands working.

 

However - it asks for P1 and P2 but after selecting the point for P2 the command ends and no polyline (with arrowhead) is drawn?

Share this post


Link to post
Share on other sites
hanhphuc
1 hour ago, oturk1 said:

sorry to be pain, pretty new to all of this, i have managed to get the commands working.

 

However - it asks for P1 and P2 but after selecting the point for P2 the command ends and no polyline (with arrowhead) is drawn?

 

 

oops.. 😝 sorry there was typo

 

'(100 . "AcDbPolyline")

 

Share this post


Link to post
Share on other sites
oturk1

no problem, now ive lost the pa200 functionality again - should i be doing something with this?

( pa#width '(200 400 600) )

Share this post


Link to post
Share on other sites
Jonathan Handojo
3 hours ago, oturk1 said:

no problem, now ive lost the pa200 functionality again - should i be doing something with this?


( pa#width '(200 400 600) )

 

I think that simply adds the command. First, run that once, and then you'll have separate command "pa200", "pa400", "pa600"...

 

The more you put (for example, (pa#width '(500 700 800 900 1000 …)), the more commands you'll have. Just initialize it first.

 

Correct me if I'm wrong @hanhphuc

Share this post


Link to post
Share on other sites
BIGAL

Add the (pa#width '(200 400 600)) as the very last line in your saved lisp then it will set up the paxxx commands

 

  )
  (princ)
)

(pa#width '(200 400 600))

 

 

Share this post


Link to post
Share on other sites
hanhphuc

 

 

4 hours ago, BIGAL said:

Add the (pa#width '(200 400 600)) as the very last line in your saved lisp then it will set up the paxxx commands

 


  )
  (princ)
)

(pa#width '(200 400 600))

 

 

5 hours ago, Jonathan Handojo said:

 

I think that simply adds the command. First, run that once, and then you'll have separate command "pa200", "pa400", "pa600"...

 

The more you put (for example, (pa#width '(500 700 800 900 1000 …)), the more commands you'll have. Just initialize it first.

 

Correct me if I'm wrong @hanhphuc

 

yes, that's the add cmd concept esp draftmen like it.

however for coders, i don't suggest adding too many repeatative commands which spam to global

for me, iniget getdist or getreal is always preferrable which is more generic it allows decimal as well :)

 

 

 

Share this post


Link to post
Share on other sites
hanhphuc

 

 

 

13 hours ago, oturk1 said:

sorry to be pain, pretty new to all of this, i have managed to get the commands working.

 

However - it asks for P1 and P2 but after selecting the point for P2 the command ends and no polyline (with arrowhead) is drawn?

 

i'll fix my previous code to echo/princ in the command line

(pa#width '( 200 400 600 )) ; you can add more sizes in the list, eg: 800 1000 etc.. as long as separated by space

pa200

pa400

pa600

 

now you can see it displayed in command line

you can then input command as pa200 pa400 etc.. 

please read the comments by BIGAL & Jonathan Handojo

 

 

 

okay, here's another back to school (simpler code)

load & run the PARR.lsp below, simply pick 2 points, it creates an arrow with constrain 1:5 width vs length

i.e: if pick distance p1->p2= 2000, so the arrow has width 400 (2000/5)

eg1: pick any 2 points for any random size

command: PARR
Specify P1: 
Specify P2: 

 

eg2: if you wanna draw pline width 200,  always mutiply by 5 to get length. i.e: 200 x 5 = 1000 length

command: PARR
Specify P1:  
Specify P2: 1000  ;<--  200x5 
 

(defun c:parr ( / p1 p2 w)
  ;;PARR.lsp
  ;; 1:5 factor, eg: width 200 x 5 = length 1000
  (ai_sysvar '("OSNAPZ" . 1) )
       (and 
       (setq p1 (getpoint "\nSpecify P1: "))
       (setq p2 (getpoint p1 "\nSpecify P2: "))
       (setq w (* 0.2 (distance p1 p2)))
       (mapcar '(lambda (p) (set p (trans (eval p) 1 0))) '(p1 p2))
       (entmakex
         (vl-list* '(0 . "LWPOLYLINE")
                   '(100 . "AcDbEntity")
                   '(100 . "AcDbPolyline")
                   '(70 . 0)
                   '(90 . 3)
                   (apply 'append
                          (mapcar '(lambda (a b c) (list (cons 10 a) (cons 40 b) (cons 41 c)))
                                  (list p1 (polar p1 (angle p1 p2) (- (distance p1 p2) (* 2.5 w))) p2)
                                  (list w (* 2.5 w) 0.0)
                                  (list w 0.0 0.0)
                          )
                   )
         )
       )
  )
  (ai_sysvar nil )
  (princ)
)

 

 

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
oturk1

Perfect, thats cracked it - thank you so much to you all who posted. i am eternally grateful!

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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