Jump to content

Break an object at 2 points and replace the properties of the line


Recommended Posts

Posted (edited)

The code should draw a dotted new line between the points, but the line is not drawn.
Would it be easier to change the properties of the line between two points?
Thanks...

;; AutoLISP, which allows you to select objects (line, polyline, circle, arc),
;; break them at two points and replace the selected section with a dashed line with the specified parameters

(defun c:Br2ptReplDash (/ ss pt1 pt2 ent entdata newent)
  (setq ss (ssget '((0 . "LINE,POLYLINE,CIRCLE,ARC"))))
  (if ss
    (progn
      (prompt "Select the object to split: ")
(setq ent (ssname ss 0))
      
      ;; Entering the first break point
      (setq pt1 (getpoint "
Select the first break point: "))
      
      ;; Entering the second break point
      (setq pt2 (getpoint "
Select the second break point: "))
      
      ;; Checking the object type and performing the split
      (cond
        ((= (cdr (assoc 0 (entget ent))) "LINE")
;; break the line
         (command "_.BREAK" ent pt1 pt2)
        )
        ((= (cdr (assoc 0 (entget ent))) "POLYLINE")
;; break polyline
         (command "_.BREAK" ent pt1 pt2)
        )
        ((= (cdr (assoc 0 (entget ent))) "CIRCLE")
;; break the circle
         (command "_.BREAK" ent pt1 pt2)
        )
        ((= (cdr (assoc 0 (entget ent))) "ARC")
         ;; break the arc
         (command "_.BREAK" ent pt1 pt2)
        )
        (T (prompt "An object of an unsupported type.")
)
      )
      
      ;; Get new objects after splitting
      (setq ss (ssget "_N" '((0 . "LINE POLYLINE CIRCLE ARC"))))
      
      ;; Sorting through objects and replacing the section with a dotted line
      (setq i 0)
(repeat (sslength ss)
(setq ent (ssname ss i))
(setq entdata (entget ent))
;; Create a new line between the break points
        (setq newent (command "_.LINE" pt1 pt2 ""))

        ;; Setting up line properties
        (entmod (append newent
                         '((8 . "0")) ; the default layer
                         '((6 . "DASHED2")) ; line type
                         '((70 . 0))
'((40 . 0.25)) ; thickness
                         '((47 . 20)) ; LTSCALE
                         '((6 . "DASHED2"))))
        )
        ;; Color setting
        (entmod (append newent '((62 . 84))))
        
        (setq i (1+ i))
      )
      
      (prompt "Processing is completed.")
)
    (prompt "Objects are not selected.")
)
  (princ)
)

 

 

 

Br2ptReplDash1.png

Br2ptReplDash.dwg

Edited by Nikon
Posted

few issues with the lisp.

1) The ssget does not seem to work.

2) Creating a new line between breakpoints will not work for circles as you need to create an arc. It will also not work on curved polylines.

Maybe a better way to approach it, is to select the object copy it. Trim it to pt1 & pt2 and then, break the selected objected between pt1 & pt2?

Posted (edited)

This is a bit more streamlined.

;; AutoLISP, which allows you to select objects (line, polyline, circle, arc),
;; break them at two points and replace the selected section with a dashed line with the specified parameters
(defun c:Br2ptReplDash (/ SS pt1 pt2 ent entdata newent)
  ;while instead of if allows this command to be repated as long as you select an entity.
  (while (setq SS (ssget "_+.:E:S" '((0 . "LINE,POLYLINE,CIRCLE,ARC")))) ;Will emulate an entsel selection behaviour and only allows the entity types listed
    (progn
      ;no need for cond check now
      (setq ent (ssname SS 0))
      (setq pt1 (getpoint "Select the first break point: "))
      (setq pt2 (getpoint "Select the second break point: "))

 

 Using the two points create a selection set window to pick up created break line

(ssget "_W" pt1 pt2 '((0 . "LINE")))

 

 

Your entmod has to many ( )

        (entmod (append newent
                         '((8 . "0") 		; the default layer
                          '(6 . "DASHED2") 	; line type
                          '(40 . 0.25) 		; thickness
                          '(47 . 20)   		; LTSCALE
                          '(62 . 84)        ; Add here instead of 2nd (entmod (append newent '((62 . 84))))
                          )
                 ) 		
        )

;removed 2nd '(6 . "DASHED2")


 

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