subodh_gis Posted December 8, 2014 Posted December 8, 2014 Can we extend inside polylines and Trim outside polylines to selected polyline boundary. See the attached Image Quote
Tharwat Posted December 8, 2014 Posted December 8, 2014 Use either the Extend or trim command with Shift button down to step through these two commands in one go . Quote
danghungxda300449 Posted October 24, 2023 Posted October 24, 2023 Please help me lisp to do it like his Quote
Steven P Posted October 24, 2023 Posted October 24, 2023 3 hours ago, danghungxda300449 said: Please help me lisp to do it like his What are your skills with lisp, that will determine what help we need to give you - might be you just need to know the relevant commands, might be that you know nothing of LISPs and want the finished thing... or anything in between. Will your LISP just be extending or trimming to a closed object (like the square above) or will it be to any object? 1 Quote
danghungxda300449 Posted October 25, 2023 Posted October 25, 2023 (edited) 15 hours ago, Steven P said: What are your skills with lisp, that will determine what help we need to give you - might be you just need to know the relevant commands, might be that you know nothing of LISPs and want the finished thing... or anything in between. Will your LISP just be extending or trimming to a closed object (like the square above) or will it be to any object? "I have a set S consisting of lines (or polylines) located within a bounding area (for example, Bbox), where S may have lines that intersect at one end or both ends, and it may also not intersect with the Bbox boundary. Now, I want a Lisp routine to select the bounding area (or possibly select additional lines from set S) to trim all the excess ends, and simultaneously extend the short ends of lines in set S that do not intersect with the Bbox boundary, as illustrated in the diagram. I have found a Lisp routine that can trim the excess ends of lines intersecting with the Bbox boundary, but it cannot extend the lines that do not intersect with the Bbox. Can you or someone else help me! Thanks You. Edited October 25, 2023 by danghungxda300449 Quote
Steven P Posted October 25, 2023 Posted October 25, 2023 Post your LISP as well, it might only need a simple modification 1 Quote
exceed Posted October 26, 2023 Posted October 26, 2023 https://www.theswamp.org/index.php?topic=3517.msg391379#msg391379 you can start with this 1 Quote
danghungxda300449 Posted October 26, 2023 Posted October 26, 2023 14 hours ago, Steven P said: Post your LISP as well, it might only need a simple modification This Lisp code already exists on the forum, but it only trims the excess heads of lines intersecting with the bounding area.: Do you have any ideas on how I can simultaneously trim the excess segments intersecting with the bounding box and extend the lines that don't intersect with the bounding box? Thanks you! Quote
danghungxda300449 Posted October 26, 2023 Posted October 26, 2023 38 minutes ago, exceed said: https://www.theswamp.org/index.php?topic=3517.msg391379#msg391379 you can start with this Thank you for sharing. I have also seen the Lisp code you provided on a forum. However, this Lisp code only allows selecting a cutting edge as an open line or polyline and only trims and extends lines at one end. I want the cutting edge to be a closed bounding area (e.g., a rectangle) and the lines to be simultaneously cut/extended at both ends (See the illustration for more details). Quote
BIGAL Posted October 26, 2023 Posted October 26, 2023 (edited) I thought that 2023 Autocad improved the extend, trim command to do what you want ? I don't have 2023. A custom lisp probably already exists do some googling, need a line intersects another line, adjust end points. Plines similar so long as no extra points between end and trim line. Extend is ok. Edited October 26, 2023 by BIGAL 1 Quote
danghungxda300449 Posted October 26, 2023 Posted October 26, 2023 7 hours ago, BIGAL said: I thought that 2023 Autocad improved the extend, trim command to do what you want ? I don't have 2023. A custom lisp probably already exists do some googling, need a line intersects another line, adjust end points. Plines similar so long as no extra points between end and trim line. Extend is ok. I want the code to be nested within another Lisp of mine, and the crucial part is that the number of line (or Polylines) will need to be simultaneously cut/extended to a boundray. Quote
Danielm103 Posted October 26, 2023 Posted October 26, 2023 Maybe you can just can just resize the inside lines. Use vla-IntersectWith to get the new coordinates 1 Quote
BIGAL Posted October 26, 2023 Posted October 26, 2023 Intersectwith is the way to go but need to be careful with plines with multiple vertices as reset start and end points. If the pline is like a line only 2 points then easy just get the 2 intersection points, note that intersectwith will return the 2 points as a list. (setq obj1 (vlax-ename->vla-object (car (entsel "\nPick object boundary ")))) (setq obj2 (vlax-ename->vla-object (car (entsel "\nPick object ")))) (setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity)) ; (431.980513473978 104.0 0.0 309.151716524031 -142.0 0.0) ; for a line can use this (vlax-put obj2 'startpoint (list (car intpt1)(cadr intpt1)(cadr intpt1))) ; for a pline use (vlax-put Obj 'coordinate 0 (list (nth 3 intpt1)(nth 4 intpt1)(nth 5 intpt1))) (vlax-put Obj 'coordinate 1 (list (nth 0 intpt1)(nth 1 intpt1)(nth 2 intpt1))) This should be enough help to put soething together have to go now. 1 Quote
Danielm103 Posted October 27, 2023 Posted October 27, 2023 (edited) If the polyline is longer than the distance between intersection points, and if the polyline has more than two vertexes, it may be possible to scale the polyline down, then set the end points. the first coordinate would be 0, the last would be at numverts -1 of course, this is starting to get into hack territory Edited October 27, 2023 by Danielm103 edit 1 Quote
danghungxda300449 Posted October 27, 2023 Posted October 27, 2023 1 hour ago, BIGAL said: Intersectwith is the way to go but need to be careful with plines with multiple vertices as reset start and end points. If the pline is like a line only 2 points then easy just get the 2 intersection points, note that intersectwith will return the 2 points as a list. (setq obj1 (vlax-ename->vla-object (car (entsel "\nPick object boundary ")))) (setq obj2 (vlax-ename->vla-object (car (entsel "\nPick object ")))) (setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity)) ; (431.980513473978 104.0 0.0 309.151716524031 -142.0 0.0) ; for a line can use this (vlax-put obj2 'startpoint (list (car intpt1)(cadr intpt1)(cadr intpt1))) ; for a pline use (vlax-put Obj 'coordinate 0 (list (nth 3 intpt1)(nth 4 intpt1)(nth 5 intpt1))) (vlax-put Obj 'coordinate 1 (list (nth 0 intpt1)(nth 1 intpt1)(nth 2 intpt1))) This should be enough help to put soething together have to go now. Thank you. Let me learn more about your method. Actually, I'm not very skilled in coding either... As I research, using a closed boundary in the form of a polyline seems quite challenging... Quote
danghungxda300449 Posted October 27, 2023 Posted October 27, 2023 I also referred to a Lisp code on the forum, but currently, it only trims/extends one side of the line with a closed boundary box (bbox) shape. Does anyone have a way to help me with this? (defun c:ExtendTrim ( / *error* LM:intersections :en->obj nVAR oVAR adoc sx ex ss en ) ;----- (defun *error* (errmsg) (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end")) (princ (strcat "\nError: " errmsg))) (mapcar 'setvar nVAR oVAR) (redraw) (vla-endundomark adoc) (princ)) ; Lee Mac (defun LM:intersections (ob1 ob2 mod / lst rtn) (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst))) (reverse rtn)) ; ---- (defun :en->obj (en /) (vlax-ename->vla-object en)) ;--------------------------------------------------------------------------------------- (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object)))) (setq oVAR (mapcar 'getvar (setq nVAR '(CMDECHO)))) (mapcar 'setvar nVAR '(0)) (princ "\n>> Select cutting edge, ") (while (not (setq sx (ssget "_+.:E:S" '((0 . "POLYLINE,ARC,CIRCLE,*LINE"))))) (princ "\n!! Wrong selection, try again !! ")) (if (and (= 1 (sslength sx)) (setq ex (ssname sx 0)) (not (vlax-invoke-method (:en->obj ex) 'Highlight :vlax-true)) (princ "\n>> Select object to trim or extend, ") (setq ss (ssget '((0 . "LWPOLYLINE,LINE,ARC"))))) (repeat (setq i (sslength ss)) (if (setq en (ssname ss (setq i (1- i))) int-rea (LM:intersections (:en->obj ex) (:en->obj en) acextendnone) int-app (LM:intersections (:en->obj ex) (:en->obj en) acextendotherentity)) (progn (setq pt (if (< (distance (vlax-curve-getStartPoint en) (cond ((car int-rea)) ((car int-app)))) (distance (vlax-curve-getEndPoint en) (cond ((car int-rea)) ((car int-app))))) (vlax-curve-getStartPoint en) (vlax-curve-getEndPoint en))) (cond (int-rea (command "_.TRIM" ex "" (list en (trans pt 0 1)) "")) (int-app (command "_.EXTEND" ex "" (list en (trans pt 0 1)) ""))) )))) (*error* "end") ) Quote
exceed Posted October 27, 2023 Posted October 27, 2023 Explode the boundary box, and then run that routine 2 times for both sides. 1 Quote
Danielm103 Posted October 27, 2023 Posted October 27, 2023 You don’t need to explode the boundary , you need to extend both ends with vla-IntersectWith, I’m not familiar with LM:intersections 1 Quote
danghungxda300449 Posted October 27, 2023 Posted October 27, 2023 18 minutes ago, Danielm103 said: You don’t need to explode the boundary , you need to extend both ends with vla-IntersectWith, I’m not familiar with LM:intersections So, is it possible to simultaneously trim and extend both ends?" Quote
Danielm103 Posted October 27, 2023 Posted October 27, 2023 (edited) Yes, in the example BIGAL posted intersectWith returns the intersection on both sides Edited October 27, 2023 by Danielm103 1 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.