Author Topic: Trim routine  (Read 5616 times)

0 Members and 1 Guest are viewing this topic.

ozimad

  • Guest
Trim routine
« on: May 26, 2010, 08:11:11 AM »
Hi!
Need help to create lisp to break objects.
White line is one i need to break around red objects.

1. Get red objects
2. Get white objects
3. Find intersection points
4. Sort intersection points to be in growing order from white line start to end.
5. Break objects between red objects. => I now the routine till now, how can i find is the the right pair of int. points to cut the white line from one red object to another.

Thanks a lot!

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Trim routine
« Reply #1 on: May 26, 2010, 08:31:45 AM »
The example you have provided seems trivial.  If you already have the intersection points in order then the correct points are P1-P2 then P3-P4 etc...  Or is there a more complex application that will cause an exception.  Unless I am misunderstanding I think you need to provide a little more information.

ozimad

  • Guest
Re: Trim routine
« Reply #2 on: May 26, 2010, 08:52:35 AM »
But if the start point is in the centre of red object, this mean i have have to take p1-p2 p3-p4, but if not then p2-p3 p4-5...

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Trim routine
« Reply #3 on: May 26, 2010, 10:19:51 AM »
Maybe you could modify this to do what you want:

http://www.theswamp.org/index.php?topic=21324.msg258512#msg258512

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ozimad

  • Guest
Re: Trim routine
« Reply #4 on: May 26, 2010, 10:57:48 AM »
Very nice but i did not worked on my machine  :cry:
I need inverted result, i need lines in the object, not out of it.

ozimad

  • Guest
Re: Trim routine
« Reply #5 on: May 26, 2010, 11:05:07 AM »
End of the day and i am here.  :ugly:
Need to get the points in two lists with one intersection point nad 2 intersection points =>

Still do not understand why the ipp return the results only when the result is printed in ipp function. Took it from cabs lisp  :mrgreen:


(defun c:trim2 ()

  ;;funi

  (defun ipp (obj1 obj2 / iplist)
    (if   (not (vl-catch-all-error-p
          (setq iplist (vl-catch-all-apply
               'vlax-safearray->list
               (list
            (vlax-variant-value
              (vla-intersectwith obj1 obj2 0)
            )
               )
             )
          )
        )
   )
      (princ)
      (setq iplist nil)
    )
    (print iplist)
;;;ubratj potom
  )


  (defun ipp-corection (p / r)
    (if   (= (length p) 3)
      (setq r p)
      (princ)
    )
    (if   (= (length p) 6)
      (progn
   (setq p1 (list
         (car p)
         (cadr p)
         (caddr p)
       )
   )
   (setq p (cdr (cdr (cdr p))))
   (setq p2 (list
         (car p)
         (cadr p)
         (caddr p)
       )
   )
   (setq r (list p1 p2))
      )
      (setq r nil)
    )

  )

;;;voood

  (setq ss1 (ssget));;;break
  (setq ss2 (ssget));;;boundary

;;;rabota

  (repeat (setq i1 (sslength ss1))
;;;;1
    (setq e1 (vlax-ename->vla-object (ssname ss1 (setq i1 (1- i1)))))
    (print i1)

    (repeat (setq i2 (sslength ss2))
      (print i2)
      (setq pl0
        (ipp-corection
          (ipp e1
          (vlax-ename->vla-object (ssname ss2 (setq i2 (1- i2))))
          )
        )
      )
    )
  )
;;;1
 
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Trim routine
« Reply #6 on: May 26, 2010, 03:02:31 PM »
Give this a shot ... it works with the example you provided.

Code: [Select]
(defun c:chopchop (/ f lyr pt pts ss x)
(vl-load-com)
  (if (and (setq f (car (entsel "\nSelect fence: ")))
  (setq f (vlax-ename->vla-object f))
  (setq lyr (vla-get-layer f))
  (setq ss (ssget '((0 . "lwpolyline,circle"))))
      )
    (progn ;;get intersections
  (setq x
 (apply 'append
(mapcar '(lambda (x) (vlax-invoke f 'intersectwith x acextendthisentity))
(vl-remove-if
  '(lambda (e) (equal e f))
  (mapcar 'vlax-ename->vla-object
  (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  )
)
)
 )
  )
  ;;convert to 3d points
  (while (caddr x)
    (setq pts (cons (list (car x) (cadr x) (caddr x)) pts)
  x   (cdddr x)
    )
  )
  ;;sort the points
  (setq pts (vl-sort pts (function (lambda (a b) (< (apply '+ a) (apply '+ b))))))
  ;;add lines
  (while (setq pt (cadr pts))
    (entmakex (list '(0 . "LINE") (cons 8 lyr) (cons 10 (car pts)) (cons 11 pt)))
    (setq pts (cddr pts))
  )
  ;;remove fence
  (vla-delete f)
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ozimad

  • Guest
Re: Trim routine
« Reply #7 on: May 26, 2010, 04:11:13 PM »
ronjonp
Thanks for the routine!
Can you please add a filter to sort and save only the points when lines have 2 or 4 or 6 or 8..... intersection points?
I will use break to cut sections. But before i will do the sort by the length from the start of the polyline.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Trim routine
« Reply #8 on: May 26, 2010, 04:36:41 PM »
ronjonp

Love your routine...this one has found a home in my toolbox top drawer.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Trim routine
« Reply #9 on: May 26, 2010, 04:40:15 PM »
ronjonp

Love your routine...this one has found a home in my toolbox top drawer.
I keep snacks in my top drawer.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Trim routine
« Reply #10 on: May 26, 2010, 04:52:05 PM »
ronjonp

Love your routine...this one has found a home in my toolbox top drawer.

Glad you have a use for it Gary.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Trim routine
« Reply #11 on: May 26, 2010, 04:52:31 PM »
ronjonp

Love your routine...this one has found a home in my toolbox top drawer.
I keep snacks in my top drawer.

I wish I had a drawer  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Trim routine
« Reply #12 on: May 26, 2010, 04:53:17 PM »
ronjonp

Love your routine...this one has found a home in my toolbox top drawer.
I keep snacks in my top drawer.

I wish I had a drawer  :-D
Going commando today?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Trim routine
« Reply #13 on: May 26, 2010, 04:58:55 PM »
ronjonp

Love your routine...this one has found a home in my toolbox top drawer.
I keep snacks in my top drawer.

I wish I had a drawer  :-D

Going commando today?

You don't wanna know :P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ozimad

  • Guest
Re: Trim routine
« Reply #14 on: May 26, 2010, 05:19:36 PM »
Please help me...
how can i add something like that?
(if (= 0 (rem (vl-list-length (vlax-invoke f 'intersectwith x acextendnone)) 2)))