Jump to content
Abdulellah

REQ : lisp to draw polyline rebar end hook side indecator

Recommended Posts

Abdulellah

hello .

i am new at this forum 

can you help me to write lisp  .

thanks for all worthily efforts 

abdulellah.alattab@gmail.com 

hook.JPG

Edited by Abdulellah

Share this post


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

hello .

i am new at this forum 

can you help me to write lisp  .

thanks for all worthily efforts 

-select polyline
-ask hook side at start point and it is length and angle (preferd 45 degree )
-ask hook side at end point and it is length and angle (preferd 45 degree )
 

abdulellah.alattab@gmail.com 

hook.JPG

image.thumb.png.d9b915383e8f6e8acc99d49262bf04b3.png

Share this post


Link to post
Share on other sites
BIGAL

This is a good time to start to learning lisp, without getting to smart about the task you want a extra line either left or right of a pline end.

 

This would be done using the endpoint and startpoint of a pline, then using the polar command working out a new point adding the line then to the pline.

 

So a start get the pline vertice points this allows you to work out the pline end segments angles. using polar command draw the new line +45 to the angle ask is it correct direction if not erase and use -45 to the angle.

 

Ok so some code 

 

(setq plent (entsel "Pick pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
; ((156.0 78.0) (307.957959107735 78.0) (307.957959107735 203.997487733392)) ; this is a L pline 3 points
(setq pt1 (nth 0 co-ord)) ; 1st point
(setq pt2 (nth 1 co-ord)) ; second point
(setq x (- (length co-ord) 1)) ; how many points- 1 as 1st point is 0
(setq pt3 (nth (- x 1) co-ord)) ; second last point
(setq pt4 (nth x  co-ord)) ; last point

(setq ang1 (angle pt2 pt1)) ; angle ofthe pline
(setq ang2 (angle pt3 pt4)) 

(setq add (getreal "Enter distance to add on"))

ok your turn 
Pt5 using polar command 
then line pt1 pt5
if wrong direction use mirror command note angle must be in radians so use (* 0.75 pi) for 135 degrees.

Please to others have to start at some point.

 

Complete code to do what you want it is short.

 

image.thumb.png.f493ac50ef8ff19d7639662bdb960dd5.png

Edited by BIGAL
  • Like 1

Share this post


Link to post
Share on other sites
Abdulellah

thanks BIGAL , i dont have any idea about auto lisp programming , i hope to help me if you can , please  

Share this post


Link to post
Share on other sites
Abdulellah

ok . we can reduce tasks to one task as this order 

- enter lisp command in prompt line like hook ( say hok )

- select point which  you want to add hook regardless if at poly line end  or not  

 

-  

Share this post


Link to post
Share on other sites
BIGAL

Yes there are more things to do with this code but I would like this to be a learning example, getint is the next step or see image below.

 

see last post

More advanced next step.

 

image.png.e1ff5714a3b1e35014857152c8f3c5db.pngimage.png.422d9d9d3bfa8180e211091c291ef5b3.png

Edited by BIGAL
  • Like 1

Share this post


Link to post
Share on other sites
Abdulellah
21 hours ago, BIGAL said:

Yes there are more things to do with this code but I would like this to be a learning example, getint is the next step or see image below.

 


(defun c:plhook ( / plent pt1 pt2 pt3 x pt5 add ang1 ang2)
(setq plent (entsel "Pick pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))

(setq pt1 (nth 0 co-ord)) ; 1st point
(setq pt2 (nth 1 co-ord) ; second point
(setq x (- (length co-ord) 1)) ; how many points- 1 as 1st point is 0
(setq pt3 (nth (- x 1) co-ord)) ; second last point
(setq pt4 (nth x  co-ord)) ; last point

(setq ang1 (angle pt2 pt1)) ; angle ofthe pline
(setq ang2 (angle pt3 pt4)) 

(setq add (getreal "Enter distance to add on"))
(setq pt5 (polar pt1 (+ (* 0.75 pi)) add)) ; 135 degrees
(command "line" pt1 pt5 "") ; new line
(setq ans (getstring "is line ok Y or N")) ; is it in correct direction
(if (= "Y" (strcase ans)) ; y or Y
(princ "ok")
(command "mirror" "Last" "" pt1 pt2 "Y") ; flip line
)
(setq pt5 (polar pt4 (+ (* 0.75 pi)) add)) ; other end
(command "line" pt4 pt5 "")
(setq ans (getstring "is line ok Y or N"))
(if (= "Y" (strcase ans))
(princ "ok")
(command "mirror" "Last" "" pt1 pt2 "Y")
)
)
)
(c:plhook)

More advanced next step.

 

image.png.e1ff5714a3b1e35014857152c8f3c5db.pngimage.png.422d9d9d3bfa8180e211091c291ef5b3.png

 

التقاط.JPG

Edited by Abdulellah

Share this post


Link to post
Share on other sites
Abdulellah

i am unfortunate , the lisp code did not work.

 

التقاط.JPG

Edited by Abdulellah

Share this post


Link to post
Share on other sites
BIGAL

Re doing was typo in code.

(defun c:plhook ( / plent pt1 pt2 pt3 x pt5 add ang1 ang2)
(while (setq plent (entsel "Pick pline Enter to exit"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(setq pt1 (nth 0 co-ord)) ; 1st point
(setq pt2 (nth 1 co-ord)) ; second point
(setq x (- (length co-ord) 1)) ; how many points- 1 as 1st point is 0
(setq pt3 (nth (- x 1) co-ord)) ; second last point
(setq pt4 (nth x  co-ord)) ; last point
(setq ang1 (angle pt2 pt1)) ; angle ofthe pline
(setq ang2 (angle pt3 pt4)) 
(setq add (getreal "Enter distance to add on"))
(setq pt5 (polar pt1 (+ (* 0.25 pi) ang1) add)) ; 135 degrees
(command "line" pt1 pt5 "") ; new line
(setq ans (getstring "is line ok Y or N")) ; is it in correct direction
(if (= "Y" (strcase ans)) ; y or Y
    (princ "ok")
    (command "mirror" "Last" "" pt1 pt2 "Y") ; flip line
)
(setq pt5 (polar pt4 (+ (* 0.25 pi) ang2) add)) ; other end
(command "line" pt4 pt5 "")
(setq ans (getstring "is line ok Y or N"))
(if (= "Y" (strcase ans))
    (princ "ok")
    (command "mirror" "Last" "" pt4 pt3 "Y")
)
)
)
(c:plhook)

 

Edited by BIGAL
  • Thanks 1

Share this post


Link to post
Share on other sites
Abdulellah
On 11/28/2019 at 6:23 AM, BIGAL said:

Re doing was typo in code.


(defun c:plhook ( / plent pt1 pt2 pt3 x pt5 add ang1 ang2)
(while (setq plent (entsel "Pick pline Enter to exit"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(setq pt1 (nth 0 co-ord)) ; 1st point
(setq pt2 (nth 1 co-ord)) ; second point
(setq x (- (length co-ord) 1)) ; how many points- 1 as 1st point is 0
(setq pt3 (nth (- x 1) co-ord)) ; second last point
(setq pt4 (nth x  co-ord)) ; last point
(setq ang1 (angle pt2 pt1)) ; angle ofthe pline
(setq ang2 (angle pt3 pt4)) 
(setq add (getreal "Enter distance to add on"))
(setq pt5 (polar pt1 (+ (* 0.25 pi) ang1) add)) ; 135 degrees
(command "line" pt1 pt5 "") ; new line
(setq ans (getstring "is line ok Y or N")) ; is it in correct direction
(if (= "Y" (strcase ans)) ; y or Y
    (princ "ok")
    (command "mirror" "Last" "" pt1 pt2 "Y") ; flip line
)
(setq pt5 (polar pt4 (+ (* 0.25 pi) ang2) add)) ; other end
(command "line" pt4 pt5 "")
(setq ans (getstring "is line ok Y or N"))
(if (= "Y" (strcase ans))
    (princ "ok")
    (command "mirror" "Last" "" pt4 pt3 "Y")
)
)
)
(c:plhook)

 

greate job herro , very usefull lisp , one more  thing for maximum benifit , can you do that with *. dcl window at right select hook side at start point , at left select hook side at end point . 

 

after add hooks , can join both hooks to be with polyline as one object .

 

then select new connected polyline and fillet all poly segment together with predefined redius.

 

i am have confident to do that .

 

 

 

Share this post


Link to post
Share on other sites
BIGAL

Multi GETVALS.lspTry this

 

(defun c:plhook ( / plent pt1 pt2 pt3 x pt5 add ang1 ang2)
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but nil)(setq but 1))
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(while (setq plent (entsel "Pick pline Enter to exit"))
(if (/= plent nil) 
(progn
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))
(setq pt1 (nth 0 co-ord)) ; 1st point
(setq pt2 (nth 1 co-ord)) ; second point
(setq x (- (length co-ord) 1)) ; how many points- 1 as 1st point is 0
(setq pt3 (nth (- x 1) co-ord)) ; second last point
(setq pt4 (nth x  co-ord)) ; last point
(setq ang1 (angle pt2 pt1)) ; angle ofthe pline
(setq ang2 (angle pt3 pt4)) 
(setq ans (AH:getvalsm (list "Enter length" "Hook length " 5 4 "30" "Radius" 5 4 "25" )))
(setq add (atof (nth 0 ans)))
(setq rad (atof (nth 1 ans)))
(setq pt5 (polar pt1 (+ (* 0.25 pi) ang1) add)) ; 135 degrees
(command "line" pt1 pt5 "") ; new line
(setq ans (ah:butts but "V" '("Flip  " "Yes" "No")))
(if (= "No"  ans)
    (princ "ok")
    (command "mirror" "Last" "" pt4 pt3 "Y")
)
(command "pedit" (car plent) "join" (entlast) "" "")
(setq pt5 (polar pt4 (+ (* 0.25 pi) ang2) add)) ; other end
(command "line" pt4 pt5 "")
(setq ans (ah:butts but "V" '("Flip  " "Yes" "No")))
(if (= "No"  ans)
    (princ "ok")
    (command "mirror" "Last" "" pt4 pt3 "Y")
)
(command "pedit" (car plent) "join" (entlast) "" "")
(command "fillet" "Polyline" "r" rad  (car plent))
)
)
)
)
(c:plhook)

Multi radio buttons.lsp

 

Edited by BIGAL
  • Thanks 1

Share this post


Link to post
Share on other sites
BIGAL
Just now, BIGAL said:

Try this

 

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Abdulellah

Very embarrassing, for your extra generosity, really you are a wonderful human 

 

On 11/28/2019 at 6:23 AM, BIGAL said:

Re doing was typo in code.


(defun c:plhook ( / plent pt1 pt2 pt3 x pt5 add ang1 ang2)
(while (setq plent (entsel "Pick pline Enter to exit"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(setq pt1 (nth 0 co-ord)) ; 1st point
(setq pt2 (nth 1 co-ord)) ; second point
(setq x (- (length co-ord) 1)) ; how many points- 1 as 1st point is 0
(setq pt3 (nth (- x 1) co-ord)) ; second last point
(setq pt4 (nth x  co-ord)) ; last point
(setq ang1 (angle pt2 pt1)) ; angle ofthe pline
(setq ang2 (angle pt3 pt4)) 
(setq add (getreal "Enter distance to add on"))
(setq pt5 (polar pt1 (+ (* 0.25 pi) ang1) add)) ; 135 degrees
(command "line" pt1 pt5 "") ; new line
(setq ans (getstring "is line ok Y or N")) ; is it in correct direction
(if (= "Y" (strcase ans)) ; y or Y
    (princ "ok")
    (command "mirror" "Last" "" pt1 pt2 "Y") ; flip line
)
(setq pt5 (polar pt4 (+ (* 0.25 pi) ang2) add)) ; other end
(command "line" pt4 pt5 "")
(setq ans (getstring "is line ok Y or N"))
(if (= "Y" (strcase ans))
    (princ "ok")
    (command "mirror" "Last" "" pt4 pt3 "Y")
)
)
)
(c:plhook)

 

 

Share this post


Link to post
Share on other sites
Abdulellah

Sorry, if you can explain how to run attachments in the last reply, you only  can help me . 

Share this post


Link to post
Share on other sites
BIGAL

You need to save the two files in a Autocad supported path or edit the "Load path.

 

(if (not AH:Butts)(load "c:\\myprograms\\lisps\\Multi Radio buttons.lsp"))

(if (not AH:Butts)(load "c:\\put your path here\\Multi Radio buttons.lsp"))

 

 

  • Thanks 1

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