Author Topic: Add vertex mline  (Read 1622 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Add vertex mline
« on: June 20, 2016, 03:54:54 AM »
Unfortunately, the MLINE entities capabilities in BricsCAD are limited compared AutoCAD.
Is there a lisp to add or remove a vertex of a multi-line?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Add vertex mline
« Reply #1 on: June 20, 2016, 07:13:50 AM »
Have you tried (vlax-put obj 'coordinates ...)?

Lupo76

  • Bull Frog
  • Posts: 343
Re: Add vertex mline
« Reply #2 on: June 20, 2016, 11:15:02 AM »
I studied a little 'code  (vlax-put obj 'coordinates ...)
However there is much work to do to achieve the result as if, for example, a multi-line has 4 vertices I find 8 point coordinates and then I am forced to find the 2 vertex coordinates perpendicular to each other.

I should be able to do this but there is much work to do.
Before doing this I would like to dedicate some of my time to see if there is something ready  :roll:

Lupo76

  • Bull Frog
  • Posts: 343
Re: Add vertex mline
« Reply #3 on: June 21, 2016, 04:47:24 AM »
Perhaps the code is not very clean, but I managed to achieve the result :-)

Code: [Select]
(defun c:AddVertexMLine (/ listavertex new_CoordList ogg Pt Obj CoordList n X Y listavertex dist tmpPt1 tmpPt2 tmpPer Pper Ang)
;*************************************
   (setvar "CMDECHO" 0)
   (setq old-error *error*)
   (defun *error* (msg)
     (setq messaggio (strcat "Errore: " msg))
     (princ messaggio)
     (setq *error* old-error)
     (command "_.undo" "_end" "_u")
     (exit)
   )
   (command "_.undo" "_be")
   (setq var (getvar "CMDECHO"))
   (setvar "CMDECHO" 0)
;*************************************

  (setq ogg (car (entsel "\nSelect mline: ")))
  (if (/= ogg nil)
    (if (= (cdr (assoc 0 (entget ogg))) "MLINE")
      (progn
        (while (= Pt nil)(setq Pt (getpoint "\nSelect point: ")))
        (setq Obj (vlax-ename->vla-object ogg))
        (setq CoordList (vlax-get Obj 'Coordinates))
       
        ;----
        (setq n 0)
        (while (< n (length CoordList))
          (progn
            (setq X (nth n CoordList))
            (setq Y (nth (+ n 1) CoordList))
            (if listavertex
              (setq listavertex (append (list (list X Y)) listavertex))
              (setq listavertex (list (list X Y)))
            )
            (setq n (+ n 3))
          )
        )
        ;----
       
        ;----
        (setq n 0)
        (setq dist nil)
        (while (< (+ n 1)(length listavertex))
          (progn
            (setq tmpPt1 (nth n listavertex))
            (setq tmpPt2 (nth (+ n 1) listavertex))
            (setq tmpPer (inters tmpPt1 tmpPt2 (polar pt (- (angle tmpPt1 tmpPt2)(* pi 0.5)) (distance pt tmpPt1)) (polar pt (+ (angle tmpPt1 tmpPt2)(* pi 0.5)) (distance pt tmpPt1)) T))
            (if (/= tmpPer nil)
              (if (= dist nil)
                (progn
                  (setq dist (distance tmpPer Pt))
                  (setq Pper tmpPt1)
                )
                (if (< (distance tmpPer Pt) dist)
                  (progn
                    (setq dist (distance tmpPer Pt))
                    (setq Pper tmpPt1)
                  )
                )
              )
            )
            (setq n (+ n 1))
          )
        )
        ;----

        ;----
        (setq n 0)
        (while (< (+ n 1)(length listavertex))
          (progn
            (setq tmpPt1 (nth n listavertex))
            (setq tmpPt2 (nth (+ n 1) listavertex))
            (setq Ang (angle tmpPt1 tmpPt2))
           
            ;--
            (if new_CoordList
              (setq new_CoordList (append (list 0.0) new_CoordList))
              (setq new_CoordList (list 0.0))
            )
            (setq new_CoordList (append tmpPt1 new_CoordList))
            (if
              (or
                (equal (angle Pper tmpPt1) Ang 0.000001)
                (equal (angle Pper tmpPt2) Ang 0.000001)
              )
              (progn
                (setq new_CoordList (append Pt new_CoordList))
              )
            )
            ;--
            (setq n (+ n 1))
          )
        )
        (setq new_CoordList (append (list 0.0) new_CoordList))
        (setq new_CoordList (append tmpPt2 new_CoordList))
       
        ;----

        (vlax-put Obj 'Coordinates new_CoordList)
      )
    )
  )
 
;*************************************
  (setq *error* old-error)
  (command "_.undo" "_end")
  (setvar "cmdecho" var)
  (princ)
)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Add vertex mline
« Reply #4 on: June 21, 2016, 01:29:26 PM »
Here is how I would do it:
Code - Auto/Visual Lisp: [Select]
  1. (defun KGA_List_Divide_3 (lst / ret)
  2.   (repeat (/ (length lst) 3)
  3.     (setq ret (cons (list (car lst) (cadr lst) (caddr lst)) ret))
  4.     (setq lst (cdddr lst))
  5.   )
  6.   (reverse ret)
  7. )
  8.  
  9. (defun KGA_List_IndexSeqMakeLength (len / ret)
  10.   (repeat (rem len 4)
  11.     (setq ret (cons (setq len (1- len)) ret))
  12.   )
  13.   (repeat (/ len 4)
  14.     (setq ret
  15.       (vl-list*
  16.         (- len 4)
  17.         (- len 3)
  18.         (- len 2)
  19.         (- len 1)
  20.         ret
  21.       )
  22.     )
  23.     (setq len (- len 4))
  24.   )
  25.   ret
  26. )
  27.  
  28. ; (MlineVertexAdd (vlax-ename->vla-object (car (entsel))) (trans (getpoint "\nNew point: ") 1 0) nil)
  29. ; The point pt is automatically translated: WCS -> OCS -> Correct Z in OCS -> WCS.
  30. (defun MlineVertexAdd (obj pt idx / coordLst) ; Pt in WCS. Idx >= 0 or nil.
  31.   (setq coordLst (vlax-get obj 'coordinates))
  32.     obj
  33.     'coordinates
  34.     (if (or (not idx) (>= idx (/ (length coordLst) 3)))
  35.       (append coordLst pt)
  36.       (apply
  37.         'append
  38.         (mapcar
  39.           '(lambda (i p)
  40.             (if (= i idx)
  41.               (append pt p)
  42.               p
  43.             )
  44.           )
  45.           (KGA_List_IndexSeqMakeLength (/ (length coordLst) 3))
  46.           (KGA_List_Divide coordLst 3)
  47.         )
  48.       )
  49.     )
  50.   )
  51.   obj
  52. )