Jump to content

Recommended Posts

Posted

Hello. Could someone shed some light on the following problem?

I am writing a lisp program to create custom Mlines. The problem is I need to compare the properties of a proposed Mline with existing Mlines to see if it already exist. If it does I set that one current, if not I create a new Mline and set that one current. The properties I am having problems comparing are the offset, color and linetype since they can be in any order.

 

Can anyone show me how to do this?

Posted (edited)

Be careful that the MlineStylename is case sensitive so Standard is not equal to STANDARD .

 

Try this , and if it passed correctly , you'd have the needed information in the variable "st" .

 

Do not forget to change the variable MlStyleName to suit yours ;)

(setq MlStyleName "Tharwat")
(cond ((and (setq ml (dictsearch (namedobjdict) "ACAD_MLINESTYLE")))
      (cond ((and (member MlStyleName (mapcar 'cdr (vl-remove-if-not '(lambda (u) (eq (car u) 3)) ml))))
             (setq st (entget (cdr (cadr (member (cons 3 MlStyleName) ml)))))
            )
            (t (alert (strcat "Mline Style < " MlStylename " > is not found !!")))
      )
     )
     (t (alert "This AutoCAD version does not support Mline object !!"))
)

Edited by Tharwat
cond function revised
Posted

Seems that Ray1 is looking to also compare the features of existing MLine Styles, not only their names. Please check this discussion for codes that store those.

Posted

Thank you for the replies but I am not looking to compare names. The name of the proposed Mline style will not exist unless the individual properties do not match any existing Mline styles. I need a way to compare the offset, color and linetype of one style with all existing styles with the same number of offsets. I think I can do it but what I write would not be as clean and streamlined as the examples I have seen on this forum.

Thanks.

Posted

Thanks for your help but I have the code written and working now.

Posted

I have just finished writing this lisp routine and I hope it would meet your requirements .

Run the routine and it should ask you to specify a point for a table and the required values for every MLStyle would be in each related cell .

 

(defun c:Test (/ acdoc l lst WriteAndSet e hgt ins row col tbl)
 ;;    Tharwat 17.June.2014        ;;
 (foreach x (entget
              (cdr
                (cadr
                  (member '(3 . "ACAD_MLINESTYLE")
                          (entget (namedobjdict))
                  )
                )
              )
            )
   (if (eq (car x) 350)
     (progn
       (vl-remove-if-not
         '(lambda (a)
            (if (member (car a) '(2 62 49 6))
              (setq lst (cons (cdr a) lst))
            )
          )
         (entget (cdr x))
       )
       (setq l   (cons (reverse lst) l)
             lst nil
       )
     )
   )
 )

 (defun WriteAndSet (col row string)
   (vla-settext tbl row col string)
   (vla-setcellalignment tbl row col acMiddleCenter)
 )

 (setq hgt
        (if
          (zerop
            (cdr
              (assoc
                40
                (setq e (entget (tblobjname "STYLE" (getvar 'textstyle))))
              )
            )
          )
           (* (getvar 'textsize) 2.0)
           (* (cdr (assoc 40 e)) 2.0)
        )
 )
 (if (setq ins (getpoint "\n Specify Table Location :"))
   (progn
     (setq tbl (vla-addtable
                 (setq space (if (> (vla-get-activespace
                                      (setq acdoc (vla-get-activedocument
                                                    (vlax-get-acad-object)
                                                  )
                                      )
                                    )
                                    0
                                 )
                               (vla-get-modelspace acdoc)
                               (vla-get-paperspace acdoc)
                             )
                 )
                 (vlax-3d-point ins)
                 (+ (length l) 2)
                 7
                 (* hgt 1.5)
                 (* hgt 1.5)
               )
     )
     (vla-settext
       tbl
       0
       0
       (strcat "MLStyle Comparison")
     )
     (setq col 0
           row 1
     )
     (foreach str (list "MLStyle Name:"
                        "Offset"
                        "Color"
                        "LineType"
                        "Offset"
                        "Color"
                        "LineType"
                  )
       (WriteAndSet col 1 str)
       (vla-setcolumnwidth tbl col (* hgt 10.))
       (vla-setrowheight tbl 1 (* hgt 1.5))
       (setq col (1+ col))
     )
     (setq col 0
           row 2
     )
     (foreach val (mapcar '(lambda (u)
                             (list (car u)
                                   (caddr u)
                                   (nth 3 u)
                                   (nth 4 u)
                                   (nth 5 u)
                                   (nth 6 u)
                                   (nth 7 u)
                             )
                           )
                          l
                  )
       (foreach x val
         (WriteAndSet
           col
           row
           (if (eq (type x) 'STR)
             x
             (if (eq x 256)
               "BYLAYER"
               (rtos x 2)
             )
           )
         )
         (setq col (1+ col))
       )
       (vla-setrowheight tbl row (* hgt 1.5))
       (setq col 0
             row (1+ row)
       )
     )
   )
 )
 (princ "\n Written by Tharwat Al Shoufi")
 (princ)
)
(vl-load-com)

Posted

Ray1

How did you get on with the codes , was it helpful or a waste of time ?

Posted

I wrote the code myself. It turned out to be easier than I thought it would be. I needed to compare the offset, color and linetype of a proposed mline with all existing mlines to see if an existing mline was the same or if I need to make a new mline.

 

No one responded with code to do this comparision but as I said I wrote it and it is working.

 

Thanks for looking into it for me.

Posted

As I said also , did you try the code ?

 

My routine would make a table of all existing MLine style names and that would be easy to compare , I think .

 

Which way you took with your codes to compare ?

Posted

I tried the code but it made a table for making a visual comparison. What I needed, and have written, is a program that will make the comparisons with code so the program decides what to do at run time.

 

Thank you for your help but as for as I am concerned this case is closed.

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