Author Topic: How to close Mline ?  (Read 4131 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to close Mline ?
« on: September 23, 2011, 02:25:44 PM »
Hello everybody ...

I have many mlines that are already drawn in a drawing but unfortunately all of them are open , and as all of you know that the mlstyle  can not be accessed to modify .

I wonder if it is possible with vla-put-***** function that could close the selected mlines or any other way !!!

Many thanks

kojacek

  • Mosquito
  • Posts: 14
Re: How to close Mline ?
« Reply #1 on: September 23, 2011, 04:24:23 PM »
Hello everybody ...

I have many mlines that are already drawn in a drawing but unfortunately all of them are open , and as all of you know that the mlstyle  can not be accessed to modify .

I wonder if it is possible with vla-put-***** function that could close the selected mlines or any other way !!!

Many thanks

This function can closed or open selected MLINE:

Code: [Select]
; ============================================================ ;
; Close [code=1] or open [code=0] MLINE object [Ent=ename]     ;
; ============================================================ ;
(defun jk:ENT_CloseMline (Ent Code / Data Obj Points Closedp)
  (setq Data (entget Ent)
        Closedp (= 2 (logand 2 (cdr (assoc 71 Data))))
        Obj (vlax-ename->vla-object Ent)
        Points (vla-get-coordinates Obj)
  )
  (cond
    ( (zerop Code)
      (if Closedp
        (progn
          (entmod
            (subst
              (cons 71 (- (cdr (assoc 71 Data)) 2))(assoc 71 Data)
              Data
            )
          )
          (vla-put-coordinates Obj Points)
          (vla-update Obj)
        )
        Nil
      )
    )
    ( (= Code 1)
      (if (not Closedp)
        (progn
          (entmod
            (subst
              (cons 71 (+ 2 (cdr (assoc 71 Data))))(assoc 71 Data) Data)
          )
          (vla-put-coordinates Obj Points)
          (vla-update Obj)
        )
        Nil
      )
    )
    (T Nil)
  )
)
regards
kojacek

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to close Mline ?
« Reply #2 on: September 23, 2011, 08:41:04 PM »
Another:

Code: [Select]
(defun _CloseMLine ( e )
    (setq e (entget e))
    (entmod (subst (cons 71 (boole 7 2 (cdr (assoc 71 e)))) (assoc 71 e) e))
)

e.g.
Code: [Select]
(defun c:test ( / ent )
    (if (setq ent (car (entsel))) (_CloseMLine ent))
    (princ)
)

Coder

  • Swamp Rat
  • Posts: 827
Re: How to close Mline ?
« Reply #3 on: September 24, 2011, 12:18:31 AM »
Thank you both so much ,

I am sorry , i did not mean to join the start and the end points as one , but to close each end alone .  :oops:

Appreciated a lot .

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to close Mline ?
« Reply #4 on: September 24, 2011, 01:44:08 AM »
Another:

Code: [Select]
(defun _CloseMLine ( e )
    (setq e (entget e))
    (entmod (subst (cons 71 (boole 7 2 (cdr (assoc 71 e)))) (assoc 71 e) e))
)

e.g.
Code: [Select]
(defun c:test ( / ent )
    (if (setq ent (car (entsel))) (_CloseMLine ent))
    (princ)
)
Lee please noticed that you need to get mline coordinates, entmod and them put coordinates back to correctly display updated mline

Thank you both so much ,

I am sorry , i did not mean to join the start and the end points as one , but to close each end alone .  :oops:

Appreciated a lot .
i'm not sure but it might be not possble.
kruuger

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to close Mline ?
« Reply #5 on: September 24, 2011, 05:57:35 AM »
Lee please noticed that you need to get mline coordinates, entmod and them put coordinates back to correctly display updated mline

In my quick tests all seemed fine...  :?

Hugo

  • Bull Frog
  • Posts: 431
Re: How to close Mline ?
« Reply #6 on: September 24, 2011, 08:11:52 AM »
I think he thinks so closed (see picture)

Ich glaube er meint so geschlossen (siehe Bild)

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: How to close Mline ?
« Reply #7 on: September 24, 2011, 11:52:24 AM »
Maybe this should help :
(note that new MLINESTYLE object is created - called : "ML-CLOSED")

Code: [Select]
(defun c:mlendsclosed ( / mls ml mll )
(setq mls (entmakex '((0 . "MLINESTYLE") (100 . "AcDbMlineStyle") (2 . "ML-CLOSED") (70 . 272) (71 . 2) (49 . 0.5) (62 . 256) (6 . "BYLAYER") (49 . -0.5) (62 . 256) (6 . "BYLAYER"))))
(entmod (subst (cons 330 (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE")))) (assoc 330 (entget mls)) (entget mls)))
(entmod (append (dictsearch (namedobjdict) "ACAD_MLINESTYLE") (list (cons 3 "ML-CLOSED") (cons 350 mls))))
(setq ml (car (entsel "\nPick mline to make its ends closed")))
(setq mll (entget ml))
(setq mll (vl-remove (assoc -1 mll) mll))
(setq mll (vl-remove (assoc 330 mll) mll))
(setq mll (subst (cons 2 "ML-CLOSED") (assoc 2 mll) mll))
(setq mll (subst (cons 340 mls) (assoc 340 mll) mll))
(entdel ml)
(entmakex mll)
(princ)
)

M.R.
 8-)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kruuger

  • Swamp Rat
  • Posts: 637
Re: How to close Mline ?
« Reply #8 on: September 24, 2011, 02:29:34 PM »
Lee please noticed that you need to get mline coordinates, entmod and them put coordinates back to correctly display updated mline

In my quick tests all seemed fine...  :?
please see picture. left is only with entmod right with coordinates.
after grips move left mline is displayed correctly
k.
« Last Edit: September 24, 2011, 02:50:11 PM by kruuger »

kojacek

  • Mosquito
  • Posts: 14
Re: How to close Mline ?
« Reply #9 on: September 24, 2011, 02:40:19 PM »
Try it: :)
MTEST command
Code: [Select]
; ============================================================ ;
; 24-09-2011 kojacek                                           ;
; ============================================================ ;
(defun C:MTEST (/ e d s sd sn nn ns dt)
  (if
    (and
      (setq e (entsel "\nSelect mline: "))
      (= "MLINE" (cdr (assoc 0 (setq d (entget (car e))))))
    )
    (progn
      (setq sd (jk:MLN_GetMstyleData (setq sn (cdr (assoc 2 d)))))
      (if
        (not
          (= 272 (logand 272 (cdr (assoc 70 sd))))
        )
        (progn
          (if
            (not
              (jk:MLN_GetMstyleData
                (setq nn (strcat sn "-END-CAPS"))
              )
            )
            (progn
              (if
                (setq sn (jk:MLN_CopyMStyle sn nn))
                (progn
                  (setq dt (jk:MLN_GetMstyleData nn))
                  (entmod
                    (subst
                      (cons 70 272)
                      (assoc 70 dt)
                      dt
                    )
                  )
                )
              )
            )
          )
          (if
            (vlax-write-enabled-p (car e))
            (progn
              (setq d (vl-remove-if
                        '(lambda (%)(member (car %)'(-1 5 330))) d
                      )
                    d (subst
                        (cons 2 nn)
                        (cons 2 sn)
                        d
                      )
                    d (subst
                        (cons 340
                          (cdr (assoc -1 (jk:MLN_GetMstyleData nn)))
                        )
                        (assoc 340 d)
                        d
                      )
              )
              (entmakex d)
              (entdel (car e))
            )
            (princ "\Cannot change object. ")
          )
        )
        (princ "\nMLine have a close cap.")
      )
    )
  )
  (princ)
)
; ============================================================ ;
(defun jk:MLN_GetMstyleData (Name)
  (dictsearch
    (jk:MLN_GetMStyleDict)
    Name
  )
)
; ============================================================ ;
(defun jk:MLN_GetMStyleDict ()
  (cdr
    (assoc -1
      (dictsearch (namedobjdict) "ACAD_MLINESTYLE")
    )
  )
)
; ============================================================ ;
(defun jk:MLN_CopyMStyle (Res New / d)
  (setq d (jk:MLN_GetMstyleData Res)
        d (vl-remove-if
                '(lambda (%)(member (car %)'(-1 5))) d)
        d (subst
            (cons 2 New)
            (cons 2 Res)
            d
          )
  )
  (dictadd
    (jk:MLN_GetMStyleDict)
    New
    (entmakex d)
  )
)
; ============================================================ ;
regards
kojacek

Coder

  • Swamp Rat
  • Posts: 827
Re: How to close Mline ?
« Reply #10 on: September 24, 2011, 03:21:53 PM »
Very great kojacek .

And a very great routine , Thank you so much for your efforts and your time .

Highly appreciated .

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to close Mline ?
« Reply #11 on: September 24, 2011, 03:23:51 PM »
Lee please noticed that you need to get mline coordinates, entmod and them put coordinates back to correctly display updated mline

In my quick tests all seemed fine...  :?
please see picture. left is only with entmod right with coordinates.
after grips move left mline is displayed correctly
k.

Oh, I see what you mean - that's quite annoying  :|

Corrected:

Code: [Select]
(defun _CloseMLine ( e )
    (setq e (entget e))
    (entmod (subst (cons 71 (boole 7 2 (cdr (assoc 71 e)))) (assoc 71 e) e))
    (setq e (vlax-ename->vla-object (cdr (assoc -1 e))))
    (vla-put-coordinates e (vla-get-coordinates e))
)

Thanks  :-)

myloveflyer

  • Newt
  • Posts: 152
Re: How to close Mline ?
« Reply #12 on: September 27, 2011, 02:37:20 AM »
LEE , cool! ^-^
Never give up !

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: How to close Mline ?
« Reply #13 on: September 27, 2011, 12:44:26 PM »