Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Making a groove in line or polyline.

8 REPLIES 8
Reply
Message 1 of 9
2e4lite
605 Views, 8 Replies

Making a groove in line or polyline.

   I want a lisp can achive the result as the right of graph to following. The original 's angle  is arbitrary in work .The dimension can also be marked in the end.Who can help me to achive it?Thanks!

8 REPLIES 8
Message 2 of 9
_Tharwat
in reply to: 2e4lite

Try this code for lines .

 

(defun c:Test (/ _line ss sn en 1p 2p co lt ly an 3p 4p 5p 6p bs i nd)
  ;;    Tharwat 21. May. 2014        ;;
  (if (setq ss (ssget "_:L" '((0 . "LINE"))))
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i)))
            en (entget sn)
            co (cdr (assoc 62 en))
            1p (cdr (assoc 10 en))
            2p (cdr (assoc 11 en))
            ly (cdr (assoc 08 en))
            lt (cdr (assoc 06 en))
            an (angle 1p 2p)
      )
      (if (> (distance 1p 2p) 25.45)
        (progn (defun _line (a b l y c)
                 (entmakex (list (cons 0 "LINE")
                                 (cons 8 l)
                                 (if y
                                   (cons 6 y)
                                   '(6 . "BYLAYER")
                                 )
                                 (if c
                                   (cons 62 c)
                                   '(62 . 256)
                                 )
                                 (cons 10 a)
                                 (cons 11 b)
                           )
                 )
               )
               (if (or (and (eq (car 1p) (car 2p)) (< (cadr 1p) (cadr 2p))) (< (car 1p) (car 2p)))
                 (setq bs 1p
                       nd 2p
                 )
                 (setq bs 2p
                       nd 1p
                       an (+ an pi)
                 )
               )
               (setq 3p (polar bs an 21.95)
                     4p (polar 3p (+ an (* pi 1.5)) 1.2)
                     5p (polar 4p an 3.5)
                     6p (polar 5p (+ an (* pi 0.5)) 1.2)
               )
               (mapcar '(lambda (j k) (_line j k ly lt co)) (list bs 3p 4p 5p 6p) (list 3p 4p 5p 6p nd))
               (entdel sn)
        )
      )
    )
  )
  (princ)
)

 Note: Polylines are not included becuase I am not sure if that complete shape is made of one polyline or just the upper line is a polyline .

 

Try it and let me know .

Message 3 of 9
2e4lite
in reply to: _Tharwat

  Hey,Tharwat,Thank you for the quick reply!

  I think It should specify the direction for the groove, otherwise there will be wrong result as the image attached. As is shown in the previous image, the size values need to input by the user (because sometimes need to change), and those require a permanent memory as default values.

If the original is Polyline,It usually is complete shape ,you can such do and add the error handling and tips.Finally, I hope the result is joined.thanks!

Message 4 of 9
2e4lite
in reply to: 2e4lite

Tharwat,I know you proficient to me,Can you give me a reply?

Message 5 of 9
_Tharwat
in reply to: 2e4lite


@2e4lite wrote:

Tharwat,I know you proficient to me,


Thank you for the nice compliment .

 


@2e4lite wrote:

Can you give me a reply?


Try this and let me know ...

 

(defun c:Test (/ _line ss sn en 1p 2p co lt ly an 3p 4p 5p 6p bs i nd)
  ;;    Tharwat 24. May. 2014        ;;
  (if (and (setq *GrvLength*
                  (cond
                    ((getdist
                       (strcat "\n Specify START Distance of Groove "
                               (rtos (if *GrvLength*
                                       *GrvLength*
                                       (setq *GrvLength* 21.95)
                                     )
                                     2
                                     2
                               ) " :"
                       )
                     )
                    )
                    (*GrvLength*)
                  )
           )
           (setq *GrvDipth*
                  (cond
                    ((getdist
                       (strcat "\n Specify DIPTH of Groove "
                               (rtos (if *GrvDipth*
                                       *GrvDipth*
                                       (setq *GrvDipth* 1.20)
                                     )
                                     2
                                     2
                               ) " :"
                       )
                     )
                    )
                    (*GrvDipth*)
                  )
           )
           (setq *GrvWidth*
                  (cond
                    ((getdist
                       (strcat "\n Specify WIDTH of Groove "
                               (rtos (if *GrvWidth*
                                       *GrvWidth*
                                       (setq *GrvWidth* 3.50)
                                     )
                                     2
                                     2
                               ) " :"
                       )
                     )
                    )
                    (*GrvWidth*)
                  )
           )
           (princ (strcat "\n Select Lines that longer than < "
                          (rtos *GrvLength* 2 2)
                          " > :"
                  )
           )
           (setq ss (ssget "_:L" '((0 . "LINE"))))
      )
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i)))
            en (entget sn)
            co (cdr (assoc 62 en))
            1p (cdr (assoc 10 en))
            2p (cdr (assoc 11 en))
            ly (cdr (assoc 08 en))
            lt (cdr (assoc 06 en))
            an (angle 1p 2p)
      )
      (if (> (distance 1p 2p) (+ *GrvLength* *GrvWidth*))
        (progn
          (defun _line (a b l y c)
            (entmakex (list (cons 0 "LINE")
                            (cons 8 l)
                            (if y
                              (cons 6 y)
                              '(6 . "BYLAYER")
                            )
                            (if c
                              (cons 62 c)
                              '(62 . 256)
                            )
                            (cons 10 a)
                            (cons 11 b)
                      )
            )
          )
          (if (or (and (eq (car 1p) (car 2p)) (< (cadr 1p) (cadr 2p)))
                  (< (car 1p) (car 2p))
              )
            (setq bs 1p
                  nd 2p
            )
            (setq bs 2p
                  nd 1p
                  an (+ an pi)
            )
          )
          (setq 3p (polar bs an *GrvLength*)
                4p (polar 3p (- an (* pi 1.5)) *GrvDipth*)
                5p (polar 4p an *GrvWidth*)
                6p (polar 5p (- an (* pi 0.5)) *GrvDipth*)
          )
          (mapcar '(lambda (j k) (_line j k ly lt co))
                  (list bs 3p 4p 5p 6p)
                  (list 3p 4p 5p 6p nd)
          )
          (entdel sn)
        )
        (princ (strcat "\n Length of line is Shorter than < " (rtos *GrvLength* 2 2) " > :"))
      )
    )
  )
  (princ)
)

 

Message 6 of 9
2e4lite
in reply to: _Tharwat

. Thank much for your reply! I tested it many times,The memory values is very good!

   Problems also exist in run:

   1.It not effect on polylines.(If the primitive objects not a line ,only a polylines?),

   2.I need the objects are joined(connected) polylines in the end.(pe-m-ssget-J...)

Message 7 of 9
_Tharwat
in reply to: 2e4lite

I mentioned before that the codes work only with lines .

Message 8 of 9
2e4lite
in reply to: _Tharwat

If it can 't also work with polylines.I'm afraid it can't widely applied.Thanks
Message 9 of 9
2e4lite
in reply to: 2e4lite

Tharwat,look!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost