Author Topic: to split a poly in two news poly  (Read 1736 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 481
to split a poly in two news poly
« on: September 17, 2006, 09:23:31 PM »
For a given LightWeightPolyline , I have a point on it , that is not a vertex.
How could I get the coordinates af the 2 new polys , if I want it to be splited at such point.
Of course I have the coordinates of the poly ,and the point too.
Also i have the param at such point.

The task shall be done in VLISP , no command or VL-CMDF

So I will have the coordinates, as  safearray, for the two new polys, as to build it by

(vla-addLightWeightPolyline modsp  left-poly-saf )

Thanks in advance.

Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: to split a poly in two news poly
« Reply #1 on: September 18, 2006, 12:46:03 AM »
Well, I saw this request at the Adesk NG first, so my reponse is posted there, too......

There are a couple different methods you could use.
This is how I'd do it:

Code: [Select]
;;requires a LWPOLYLINE as a (vla-object) and a 2d or 3d point that lies on
the pline.
(defun break-pline (pline pt / coords1 coords2 endparam idx ms pline1 pline2
ptparam tmp)
  (setq ptparam (vlax-curve-getparamatpoint pline pt)
 endparam (vlax-curve-getendparam pline)
 idx -1
 )
  (if (> (length pt) 2)
    (setq pt (list (car pt) (cadr pt)))
    )
  (while (< (setq idx (1+ idx)) ptparam)
    (setq coords1 (cons (vlax-get-property pline 'coordinate idx) coords1))
    )
  (setq tmp (mapcar '(lambda (x)
         (vlax-safearray->list
    (vlax-variant-value x)))
      (reverse coords1)))
  (setq coords1 (apply 'append tmp)
 coords1 (append coords1 pt)
 idx (1- idx))
  (while (<= (setq idx (1+ idx)) endparam)
    (setq coords2 (cons (vlax-get-property pline 'coordinate idx) coords2))
    )
  (setq tmp (mapcar '(lambda (x)
         (vlax-safearray->list
    (vlax-variant-value x)))
      (reverse coords2)))
  (setq coords2 (apply 'append tmp)
 coords2 (append pt coords2))
  (setq ms (vla-get-modelspace (vla-get-activedocument
(vlax-get-acad-object))))
  (setq pline1 (vlax-invoke ms 'addlightweightpolyline coords1)
 pline2 (vlax-invoke ms 'addlightweightpolyline coords2)
 )
  ;;;add code here to allow for Bulges, widths, layers, etc.
  ;;;If you want the original pline deleted, do that here, too.
  )

DEVITG

  • Bull Frog
  • Posts: 481
Re: to split a poly in two news poly
« Reply #2 on: September 18, 2006, 06:09:35 AM »
Hi Jeff, thanks for it
Location @ Córdoba Argentina Using ACAD 2019  at Window 10