Author Topic: Break Line at Point or Intersection  (Read 5264 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Break Line at Point or Intersection
« on: August 17, 2009, 03:32:26 PM »
Doe anyone have a routine to break a line at point or intersection. The routine below no longer woks for 2010

Code: [Select]
(defun BPIT  (/ P1 P2)
  (setq OSM (GETVAR "OSMODE"))
  (setvar "OSMODE" 512)
  (setq EP (ENTSEL "\n* Select Element to Break *")
        P1 (CADR EP)
        EN (CAR EP))
  (REDRAW EN 3)
  (setvar "OSMODE" OSM)
  (setq P2 (getpoint "\n* Show Point to Divide *"))
  (command "BREAK" P1 "F" P2 P2)
  (princ))

Sometines I get this error:

Invalid point, polygon segment is zero length.
; error: Function cancelled
« Last Edit: August 17, 2009, 03:35:58 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Spike Wilbury

  • Guest
Re: Break Line at Point or Intersection
« Reply #1 on: August 17, 2009, 03:40:21 PM »
I still use this one on A2009....

Code: [Select]
(defun C:BRK  (/ osm pt ptlst ss num num1 count)

  (defun *error*  (msg)
    (if eco
      (setvar "cmdecho" eco))
    (if osm
      (setvar "osmode" osm))

    (setq *error* nil)

    (princ))

  (setq eco (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq osm (getvar "osmode"))
 
  (command "_.osnap" "_int")
  (setq pt (getpoint "\nSelect intersection to break objects: "))
  (setq ptlst (list (car pt) (cadr pt)))
  (setq ss (ssget "_C" ptlst ptlst))

  (setq num   (sslength ss)
num1  (sslength ss)
count 0)

  (if (= 1 num1)
    (progn (prompt "\nInvalid point"))
    (progn (repeat num
     (command "_.break" (ssname ss count) ptlst ptlst)
     (setq count (1+ count)))))

  (setvar "osmode" osm)
  (setvar "cmdecho" eco)

  (setq *error* nil)

  (princ))

(princ)

GDF

  • Water Moccasin
  • Posts: 2081
Re: Break Line at Point or Intersection
« Reply #2 on: August 17, 2009, 03:43:29 PM »
Perfect, thank you. My old routine just went into the trash can.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Spike Wilbury

  • Guest
Re: Break Line at Point or Intersection
« Reply #3 on: August 17, 2009, 03:55:18 PM »
Perfect, thank you. My old routine just went into the trash can.

not an elegant code, but appears that have been done the job for many years.... :)

KewlToyZ

  • Guest
Re: Break Line at Point or Intersection
« Reply #4 on: August 17, 2009, 04:27:11 PM »
There have been quite few interesting routines posted in here for this:

My favorite by CAB:
http://www.theswamp.org/index.php?topic=10370.0

Another with specialized requests
http://www.theswamp.org/index.php?topic=25808.0


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Break Line at Point or Intersection
« Reply #5 on: August 17, 2009, 04:45:16 PM »
Code: [Select]
;;  Break at intersection, modified by CAB
;;  Not that a circle will not be broken!
(defun C:BRK (/ *error* osm pt ptlst ss num num1 count)
  (defun *error* (msg)
    (and msg (print msg))
    (and eco (setvar "cmdecho" eco))
    (and osm (setvar "osmode" osm))
    (princ)
  )

  (setq eco (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq osm (getvar "osmode"))
  (command "._undo" "_begin")
  (setvar "osmode" 96)        ; int
  (if (and
        (setq pt (getpoint "\nSelect intersection to break objects: "))
        (setq ptlst (list (car pt) (cadr pt)))
        (setq ss (ssget "_C" ptlst ptlst))
      )
    (if (< (setq num (sslength ss)) 2)
      (prompt "\nInvalid point")
      (repeat num
        (command "_.break" (ssname ss (setq num (1- num))) ptlst ptlst))
    )
  )
  (command "._undo" "_end")
  (*error* nil)
  (princ)
)
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Break Line at Point or Intersection
« Reply #6 on: August 17, 2009, 04:51:53 PM »
Thanks Alan, I like the way this one works.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Break Line at Point or Intersection
« Reply #7 on: August 17, 2009, 04:54:21 PM »
Thanks, just a little cleanup and some added error checking.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.