Jump to content

Recommended Posts

Posted

Hello All,

 

I could really use some help. Im trying to standardize some CAD items in the office and one thing I came across that I would like to add is break distance. I have no idea how to write the code for a LISP and would really appreciate it if someone could assist me with this. I want the command to break a line at an intersection (obviously to show which duct or pipe would be on top of another) of two lines using the intersection as the midpoint of the break. I would like to prompt you to input a distance (similar to the fillet or chamfer command) and store that value for repeated use. My idea is:

 

Type "brk"

The first prompt asks you to pick a line.

Second prompt asks you to pick the intersection.

If "d" is typed, it would prompt you to input a distance and store it.

 

Thanks guys,

Tony

Posted

Try this and hope it would perform as needed :)

 

(defun c:brk (/ s ss p st nd)
 ;;-- Tharwat 16. May. 2013 ---;;
 (if
   (and (setq s (car (entsel "\n Select line :")))
        (if (not (eq (cdr (assoc 0 (entget s))) "LINE"))
          (progn
            (alert "Your pickis not a LINE <!>")
            nil
          )
          t
        )
        (setq ss (car (entsel "\n Select any line object :")))
        (if (not (member (cdr (assoc 0 (entget ss)))
                         '("LWPOLYLINE" "LINE" "SPLINE" "ARC" "XLINE")
                 )
            )
          (progn
            (alert "Invalid selection <!>")
            nil
          )
          t
        )
        (if (setq p (vlax-invoke
                      (vlax-ename->vla-object s)
                      'IntersectWith
                      (vlax-ename->vla-object ss)
                      AcExtendNone
                    )
            )
          t
          (progn
            (alert (strcat "Line is not Intersecting with the "
                           (cdr (assoc 0 (entget ss)))
                           " <!>"
                   )
            )
            nil
          )
        )
        (progn (initget 6)
               (setq *MyDistance*
                      (cond
                        ((getdist (strcat "\n Specify the Distance "
                                          (if *MyDistance*
                                            (strcat " < "
                                                    (rtos *MyDistance* 2)
                                                    " > :"
                                            )
                                            " :"
                                          )
                                  )
                         )
                        )
                        (t *MyDistance*)
                      )
               )
        )
   )
    (if (< *MyDistance*
           (distance (setq st (cdr (assoc 10 (entget s))))
                     (setq nd (cdr (assoc 11 (entget s))))
           )
        )
      (command "_.Break"
               (polar p (angle nd st) (/ *MyDistance* 2.))
               (polar p (angle st nd) *MyDistance*)
      )
      (alert
        "Distance must be smaller than the Length of the first selected line "
      )
    )
 )
 (princ)
)
(vl-load-com)

Posted

Thanks a lot for our help! Right before you sent that i had found this :oops:...http://www.cadforum.cz/cadforum_en/download.asp?fileID=682....Just in case anyone is looking for this as well.

Posted
Thanks a lot for our help! Right before you sent that i had found this :oops:...http://www.cadforum.cz/cadforum_en/download.asp?fileID=682....Just in case anyone is looking for this as well.

 

No worries. I'd check the link I posted. It will have the latest version.

Posted

I forgot about him, was such a nice guy. I hope he's doing well.

Posted
I forgot about him, was such a nice guy. I hope he's doing well.

 

I learnt such a great deal from ASMI, I owe him a lot.

Posted
I learnt such a great deal from ASMI, I owe him a lot.

 

Likewise. I studied a lot of his code closely.

  • 9 years later...
Posted
On 5/17/2013 at 12:56 AM, Tharwat said:

Try this and hope it would perform as needed :)

 

 

(defun c:brk (/ s ss p st nd)
 ;;-- Tharwat 16. May. 2013 ---;;
 (if
   (and (setq s (car (entsel "\n Select line :")))
        (if (not (eq (cdr (assoc 0 (entget s))) "LINE"))
          (progn
            (alert "Your pickis not a LINE <!>")
            nil
          )
          t
        )
        (setq ss (car (entsel "\n Select any line object :")))
        (if (not (member (cdr (assoc 0 (entget ss)))
                         '("LWPOLYLINE" "LINE" "SPLINE" "ARC" "XLINE")
                 )
            )
          (progn
            (alert "Invalid selection <!>")
            nil
          )
          t
        )
        (if (setq p (vlax-invoke
                      (vlax-ename->vla-object s)
                      'IntersectWith
                      (vlax-ename->vla-object ss)
                      AcExtendNone
                    )
            )
          t
          (progn
            (alert (strcat "Line is not Intersecting with the "
                           (cdr (assoc 0 (entget ss)))
                           " <!>"
                   )
            )
            nil
          )
        )
        (progn (initget 6)
               (setq *MyDistance*
                      (cond
                        ((getdist (strcat "\n Specify the Distance "
                                          (if *MyDistance*
                                            (strcat " < "
                                                    (rtos *MyDistance* 2)
                                                    " > :"
                                            )
                                            " :"
                                          )
                                  )
                         )
                        )
                        (t *MyDistance*)
                      )
               )
        )
   )
    (if (< *MyDistance*
           (distance (setq st (cdr (assoc 10 (entget s))))
                     (setq nd (cdr (assoc 11 (entget s))))
           )
        )
      (command "_.Break"
               (polar p (angle nd st) (/ *MyDistance* 2.))
               (polar p (angle st nd) *MyDistance*)
      )
      (alert
        "Distance must be smaller than the Length of the first selected line "
      )
    )
 )
 (princ)
)
(vl-load-com)
 

 

 

Hi,

Can u modify this routine that break polyline at the insertion of block

Posted (edited)

update the lisp with or it might not break in the right spots.

(command "_.break" ent "_non" ins "_non" ins)

 

Quote

in case you have running Object Snap modes on that don't include INSert or anything else that might occur in the Block at its insertion point, and that therefore could take the breaking point elsewhere.  The "usual enhancements" mentioned, that are not in the routine yet, would typically include controlling for that, but it's easy enough to add that element as above rather than by changing the Osnap setting.

 

Edited by mhupp

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