Jump to content

How to Trim the intersected line between Mline & Polyline ?


John Camper

Recommended Posts

I have multiple Mline that has a intersection with a Polyline.I want to trim the part where this intersection occurs.(See attached image below for clarification).

I am more of a VBA guy than LISP and i could not find a way to achieve it through VBA. But here are some of the ideas that i came through to achieve it :

i) Through Send Command in VBA : I could use Trim -> Fence through Send Command and input the Start Co-ordinates & End Co-ordinate of the Fence Trim Line. I feel it to be ineffective as Multiple iterations need to be done and Send Command is not reliable at all.

ii) I explode every Polyline and MLine then used BreakObjects.Lsp by Charles Alan Butler which breaks each and every intersected line. Then i used Qselect to select every line whose length is equal to 24. Then i erased those objects.

 

I could not find any other ways to achieve it so i am here asking you sir's for Ideas and help !

 

 

Capture.JPG

Capturae.JPG

Sample.dwg

Link to comment
Share on other sites

Manually trim select mline then pick point at midpoint of each side of red plines seems to work. So get all rectangs do a offset and get te co-ords of that new pline then use ssget "F" to get the touching mlines, the trim point is mid of the 2 mlines points.

; https://www.cadtutor.net/forum/topic/77526-how-to-trim-the-intersected-line-between-mline-polyline/
; Trim mlines touching plines 
; by AlanH May 2023

(defun c:cuts ( / )
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq ss (ssget '((0 . "lwpolyline"))))
(if ss
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (1- x))))
(setq obj (vlax-ename->vla-object ent))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))
(setq co-ord (cons (last co-ord) co-ord))
(command "offset" 10 ent (getvar 'extmax) "")
(setq co-ord2 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
(setq co-ord2 (cons (last co-ord2) co-ord2))
(entdel (entlast))
(setq ss2 (ssget "f" co-ord2 '((0 . "MLINE"))))
(setq mpts '())
(repeat (setq j (sslength ss2))
(setq ent2 (ssname ss2 (setq j (1- j))))
(setq obj2 (vlax-ename->vla-object ent2))
(setq intpts (vlax-invoke obj 'intersectWith obj2 acExtendThisEntity))
(setq mp (mapcar '* (mapcar '+ (list (nth 0 intpts) (nth 1 intpts) 0.0)(list (nth 3 intpts) (nth 4 intpts) 0.0)) '(0.5 0.5 0.5)))
(setq mpts (cons mp mpts))
)
(command "trim" ss2 "")
(foreach pt mpts
(command pt)
)
(command "")
)
(alert "no plines")
)
(princ)
)
(c:cuts)

 

  • Like 2
Link to comment
Share on other sites

Wow, I was starting to think if it would be possible at all. Thank you so much sir.😇

But It seems to works as expected only if there are no dimensions on the selected area. If there are dimensions on the selected area then the Line will not be trimmed. 

ie: a) If we select Multiple Closed Polylines at once (that have Dimensions) then on the side where dimension is, the line wont be trimmed.

b) If we select Single Closed Polyline (that have Dimensions) then only all the sides will be trimmed.

Please do check with the attached file below :

Drawing1.dwg

Link to comment
Share on other sites

Quick answer put the rectangs on another layer same with the mlines then use layiso so only correct objects are selected. Then the ssget can filter by layer also.

 

OR

(defun c:cuts ( / )
(command "chprop" (ssget "x" '((0 . "MLINE"))) "" "la" "Footlayer" "")
(command "-layer" "M" "DIMS" "")
(command "chprop" (ssget "x" '((0 . "DIMENSION"))) "" "la" "DIMS" "")
(setvar 'clayer "Footlayer")
(command "-layer" "OFF" "*" "n" "")
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq ss (ssget '((0 . "lwpolyline"))))
(if ss
(repeat (setq x (sslength ss))
  (setq ent (ssname ss (setq x (1- x))))
  (setq obj (vlax-ename->vla-object ent))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))))
  (setq co-ord (cons (last co-ord) co-ord))
  (command "offset" 10 ent (getvar 'extmax) "")
  (setq co-ord2 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))
  (setq co-ord2 (cons (last co-ord2) co-ord2))
  (entdel (entlast))
  (setq ss2 (ssget "f" co-ord2 '((0 . "MLINE"))))
  (setq mpts '())
  (repeat (setq j (sslength ss2))
    (setq ent2 (ssname ss2 (setq j (1- j))))
    (setq obj2 (vlax-ename->vla-object ent2))
    (setq intpts (vlax-invoke obj 'intersectWith obj2 acExtendThisEntity))
    (setq mp (mapcar '* (mapcar '+ (list (nth 0 intpts) (nth 1 intpts) 0.0)(list (nth 3 intpts) (nth 4 intpts) 0.0)) '(0.5 0.5 0.5)))
    (setq mpts (cons mp mpts))
  )
  (command "trim" ss2 "")
  (foreach pt mpts
    (command pt)
  )
 (command "")
)
(alert "no plines")
)
(command "Layer" "on" "*" "")
(princ)
)
(c:cuts)

 

 

 

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