Jump to content

Trim Extend to Polyline boundry


subodh_gis

Recommended Posts

  • 8 years later...
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?

  • Thanks 1
Link to comment
Share on other sites

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.

999_MINH HOA.png

Edited by danghungxda300449
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

38 minutes ago, exceed said:

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).image.png.6bd502583bf61b6e581583ea9560bace.png

Link to comment
Share on other sites

I thought that 2023 Autocad improved the extend, trim command to do what you want ? I don't have 2023. 

 

image.png.088eb6a388ee530b8c404f93d5a31a20.png

 

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 by BIGAL
  • Thanks 1
Link to comment
Share on other sites

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. 

 

image.png.088eb6a388ee530b8c404f93d5a31a20.png

 

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.

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 by Danielm103
edit
  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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")
  )

image.png

Link to comment
Share on other sites

You don’t need to explode the boundary , you need to extend both ends with vla-IntersectWith, I’m not familiar with LM:intersections

  • Like 1
Link to comment
Share on other sites

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?"

Link to comment
Share on other sites

Yes, in the example BIGAL posted intersectWith returns the intersection on both sides

 

 

inter.png

Edited by Danielm103
  • Like 1
Link to comment
Share on other sites

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