Nikon Posted yesterday at 10:17 AM Posted yesterday at 10:17 AM (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 ) ;; Color setting (entmod (append newent '((62 . 84)))) (setq i (1+ i)) ) (prompt "Processing is completed.") ) (prompt "Objects are not selected.") ) (princ) ) Br2ptReplDash.dwg Edited 21 hours ago by Nikon Quote
CivilTechSource Posted 22 hours ago Posted 22 hours ago 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? Quote
mhupp Posted 22 hours ago Posted 22 hours ago (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 22 hours ago by mhupp 1 Quote
Nikon Posted 21 hours ago Author Posted 21 hours ago 44 minutes ago, mhupp said: Your entmod has to many ( ) I understand (), but the rest is not very clear... Quote
mhupp Posted 19 hours ago Posted 19 hours ago 1 hour ago, Nikon said: I understand (), but the rest is not very clear... You start the lisp with if this will only run once. changing the if to while will allow you to use the break command multiple of times with out having to type the command over and over. only draw back is if you only want to run the command once you have to right click or hit enter to exit the command. using ssget with the "_+.:E:S" acts like entsel and will only select entity's you define. eliminating the need to test the entity type. since you have the two break points defined you can use ssget with the window option to "select" that entity but could pick up other smaller unwanted items also. this is all moot because id recommend using Breakall by CAB. don't know if its on here but he posted it on theswamp.org many years ago. alot more features and error handling. 1 Quote
BlackBox Posted 19 hours ago Posted 19 hours ago 7 minutes ago, mhupp said: ... you can use ssget with the window option to "select" that entity but could pick up other smaller unwanted items also. Entlast & entnext may help to mitigate that. 7 minutes ago, mhupp said: this is all moot because id recommend using Breakall by CAB. don't know if its on here but he posted it on theswamp.org many years ago. alot more features and error handling. 1+ 1 Quote
GLAVCVS Posted 14 hours ago Posted 14 hours ago (edited) Hi As @mhupp mentioned, there are extra 'quotes' marks in your code. Also, as Mhupp suggested, you can use the filter "_+.:E:S" to select the object to be cropped in a single step, and then implement it within a 'while' loop to repeat the operation as many times as needed. Putting all of this together, your code could look something like this: (defun c:Br2ptReplDash (/ ss pt1 pt2 ent entdata newent entUlt) (while (setq ss (SETVAR "NOMUTT" 1) ss (princ "\nSelect object to trim (RIGH CLICK to EXIT)...") ss (ssget "_+.:E:S" '((0 . "*LINE,POLYLINE,CIRCLE,ARC"))) ) (SETVAR "NOMUTT" 0) (setq entUlt (entlast)) (princ "\nSelect the object to split: ") (setq ent (ssname ss 0)) ;; Entering the first break point (setq pt1 (getpoint "\nSelect the first break point: ")) ;; Entering the second break point (setq pt2 (getpoint "\nSelect the second break point: ")) ;; Checking the object type and performing the split (cond ((= (cdr (assoc 0 (entget ent))) "LWPOLYLINE") ;; break the LWPOLYLINE (command "_.BREAK" ent pt1 pt2) ) ((= (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.") ) ) (command "_.LINE" pt1 pt2 "") (if (not (equal entUlt (entlast))) (progn (entmod (append (ENTGET (ENTLAST)) '((8 . "0") ; the default layer (6 . "DASHED2") ; line type ;'(70 . 0) ;(40 . 0.25) ; thickness ;(47 . 20) (62 . 84) ) ) ; LTSCALE ) (princ "\nProcess completed for these objects") (vlr-beep-reaction) ) (princ "\n*** The operation could not be performed ***") ) ) (if (not entUlt) (princ "\nObjects are not selected.")) (princ) ) Edited 14 hours ago by GLAVCVS Quote
GLAVCVS Posted 14 hours ago Posted 14 hours ago PS: Note that I have disabled (40 . 0.25) and (47 . 20) because they are rejected by most objects in your filter, and I haven't taken the time to find out which objects they actually apply to. 1 Quote
mhupp Posted 12 hours ago Posted 12 hours ago (edited) 4 hours ago, GLAVCVS said: PS: Note that I have disabled (40 . 0.25) and (47 . 20) because they are rejected by most objects in your filter So went ahead and joined my first part of mine and what Blackbox & Glavcvs posted. Can either run it by typing BD or BreakDash ;;----------------------------------------------------------------------------;; ;; Break Entities and changed layer, linetype, color (defun C:BD () (C:BreakDash) (princ)) (defun C:BreakDash (/ SS1 SS2 SS3 pt1 pt2 ent entdata newent) (setq SS2 (ssadd)) (while (setq SS1 (ssget "_+.:E:S" '((0 . "*LINE,CIRCLE,ARC")))) (setq ent (ssname SS1 0) pt1 (getpoint "Select the first break point: ") pt2 (getpoint "Select the second break point: ") LastEnt (entlast) ) (command-s "_.BREAK" ent pt1 pt2) (while (setq LastEnt (entnext LastEnt)) (ssadd LastEnt SS2) ) (setq SS3 (ssget "_W" pt1 pt2 '((0 . "LINE")))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS3))) (if (ssmemb ent SS2) (progn (entmod (append ent '((8 . "0") '(6 . "DASHED2") '(62 . 84)))) (entupd ent) ) ) ) ) (princ) ) And found Cab's post for break all objects Edited 10 hours ago by mhupp 1 Quote
BIGAL Posted 9 hours ago Posted 9 hours ago (edited) For me if you have an object and use Break. When selecting the first point you get an entity name ie ent1 Select 2nd point and run break pt1 pt2 Ok the second entity is (entlast) so no need for ssget's etc When you break say line pline the new object is created in the same direction so the gap is join endpoint ent1 to startpoint ent2. But as mentioned a circle and an arc need a slight variation on this. But still have a start and endpoint. Oh yeah a circle needs to be selected in an anti clockwise direction. Clockwise gives a big arc. Yes a break in the arc of a pline is an interesting problem. Or worse a part arc and straight. ; https://www.cadtutor.net/forum/topic/98693-break-an-object-at-2-points-and-replace-the-properties-of-the-line/ ; Break an object and use a different linetype ; Bu AlanH Sept 20205 (defun c:brkobj ( /cenpt end1 end2 ent ent1 ent2 obj1 obj2 pt1 pt2 rad st1 st2 type ) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 512) (setq ent (entsel "\nPick object 1st point to break at ")) (setq ent1 (car ent)) (setq pt1 (cadr ent)) (setq pt2 (getpoint "\nPick second point ")) (command "break" pt1 pt2) (setq ent2 (entlast)) (setq type (cdr (assoc 0 (entget ent1)))) (setq obj1 (vlax-ename->vla-object ent1)) (setq st1 (vlax-curve-getstartPoint obj1)) (setq end1 (vlax-curve-getendPoint obj1)) (setq obj2 (vlax-ename->vla-object ent2)) (setq st2 (vlax-curve-getstartPoint obj2)) (setq end2 (vlax-curve-getendPoint obj2)) (if (or (= type "LINE")(= type "LWPOLYLINE")) (progn (command "line"end1 st2 "") (command "chprop" (entlast) "" "LT" "DASHED" "s" 10 "") ) ) (if (= type "ARC") (progn (setq rad (vlax-get obj1 'radius)) (setq cenpt (vlax-get obj1 'center)) (command "arc" end1 "C" cenpt st2) (command "chprop" (entlast) "" "LT" "DASHED" "s" 10 "") ) ) (if (= type "CIRCLE") (progn (setq rad (vlax-get obj1 'radius)) (setq cenpt (vlax-get obj1 'center)) (command "arc" end1 "C" cenpt st1) (command "chprop" (entlast) "" "LT" "DASHED" "s" 10 "") ) ) (princ) ) (c:brkobj) Edited 5 hours ago by BIGAL 1 Quote
Nikon Posted 4 hours ago Author Posted 4 hours ago 10 hours ago, GLAVCVS said: Hi As @mhupp mentioned, there are extra 'quotes' marks in your code. Also, as Mhupp suggested, you can use the filter "_+.:E:S" to select the object to be cropped in a single step, and then implement it within a 'while' loop to repeat the operation as many times as needed. Putting all of this together, your code could look something like this: Thank The code works perfectly for straight sections. For circles and arcs, I would like to simply change the properties of the lines between points pt1 and pt2. There is no need to connect these points with a straight line. How can I set the scale for the line (LTSCALE 20)? Quote
Nikon Posted 4 hours ago Author Posted 4 hours ago 7 hours ago, mhupp said: So went ahead and joined my first part of mine and what Blackbox & Glavcvs posted. Can either run it by typing BD or BreakDash Thank This code deletes the line between points pt1 and pt2. But I need to leave this line between the points pt1 and pt2 and change the properties of the line to a dashed line... Quote
Nikon Posted 4 hours ago Author Posted 4 hours ago 5 hours ago, BIGAL said: Oh yeah a circle needs to be selected in an anti clockwise direction. Clockwise gives a big arc. Thank You're absolutely right. I added _ (command "_.break" pt1 pt2) ............... (command "_.line" end1 st2 "") (command "_.chprop" (entlast) "" "_LT" "DASHED" "_s" 20 "") Unfortunately, I was unable to verify the operation of the code. ; error: too few arguments Quote
BIGAL Posted 4 hours ago Posted 4 hours ago Sorry my fault it has a typo I fixed code above There should be a space after the "/" was missing in code posted, I sort the variable names and put in code missed the needed space. (defun c:brkobj ( / cenpt end1 end2 ent ent1 ent2 obj1 obj2 pt1 pt2 rad st1 st2 type ) It has a linetype, and Linetype Scale so change both of those to suit. 1 Quote
Nikon Posted 3 hours ago Author Posted 3 hours ago 36 minutes ago, BIGAL said: Sorry my fault it has a typo I fixed code above There should be a space after the "/" was missing in code posted, I sort the variable names and put in code missed the needed space. (defun c:brkobj ( / cenpt end1 end2 ent ent1 ent2 obj1 obj2 pt1 pt2 rad st1 st2 type ) It has a linetype, and Linetype Scale so change both of those to suit. Unfortunately, the error remains ; error: too few arguments Maybe I messed up with localization? ; https://www.cadtutor.net/forum/topic/98693-break-an-object-at-2-points-and-replace-the-properties-of-the-line/ ; Break an object and use a different linetype ; Bu AlanH Sept 2025 (defun c:brkobjLocal ( /cenpt end1 end2 ent ent1 ent2 obj1 obj2 pt1 pt2 rad st1 st2 type ) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 512) (setq ent (entsel "\nPick object 1st point to break at ")) (setq ent1 (car ent)) (setq pt1 (cadr ent)) (setq pt2 (getpoint "\nPick second point ")) (command "_.break" pt1 pt2) (setq ent2 (entlast)) (setq type (cdr (assoc 0 (entget ent1)))) (setq obj1 (vlax-ename->vla-object ent1)) (setq st1 (vlax-curve-getstartPoint obj1)) (setq end1 (vlax-curve-getendPoint obj1)) (setq obj2 (vlax-ename->vla-object ent2)) (setq st2 (vlax-curve-getstartPoint obj2)) (setq end2 (vlax-curve-getendPoint obj2)) (if (or (= type "LINE")(= type "LWPOLYLINE")) (progn (command "_.line"end1 st2 "") (command "_.chprop" (entlast) "" "_LT" "DASHED" "_s" 10 "") ) ) (if (= type "ARC") (progn (setq rad (vlax-get obj1 'radius)) (setq cenpt (vlax-get obj1 'center)) (command "_.arc" end1 "_C" cenpt st2) (command "_.chprop" (entlast) "" "_LT" "DASHED" "_s" 10 "") ) ) (if (= type "CIRCLE") (progn (setq rad (vlax-get obj1 'radius)) (setq cenpt (vlax-get obj1 'center)) (command "_.arc" end1 "_C" cenpt st1) (command "_.chprop" (entlast) "" "_LT" "DASHED" "_s" 10 "") ) ) (princ) ) (c:brkobjLocal) Quote
Recommended Posts
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.