Lisp to Change forced REVIT Line types to CAD

Lisp to Change forced REVIT Line types to CAD

3arizona
Advocate Advocate
1,743 Views
9 Replies
Message 1 of 10

Lisp to Change forced REVIT Line types to CAD

3arizona
Advocate
Advocate

I have this lisp that changes REVIT line types to CAD lines. But it only works with LAYERS that have those line type names (By Layer). 

 

Most lines in the drawing are forced line types. Can this lisp be made to pick up those forced line types? 

 

 

 

this is the lisp:

 

(vl-load-com)
(defun c:demoLN (/ put_linetype linetypes ltyp ltyps)
(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setq linetypes (vla-get-linetypes adoc))
(vlax-for ltyp (vla-get-linetypes adoc)
(setq ltyps (cons (vla-get-name ltyp) ltyps))
)
(defun put_linetype (obj linetype linefile)
(if (vl-position linetype ltyps)
(vla-put-linetype obj linetype)
(progn
(vla-load linetypes linetype linefile)
(setq ltyps (cons linetype ltyps))
(vla-put-linetype lay linetype)
)
)
)
(vlax-for lay (vla-get-layers adoc)
(cond ((wcmatch (setq ltyp (vla-get-linetype lay)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
(put_linetype lay "HIDDEN2" "acadiso.lin")
)
((wcmatch (setq ltyp (vla-get-linetype lay)) "Dash 1_16_,Dash Dot 3_16_,Long dash")
(put_linetype lay "HIDDEN" "acadiso.lin")
)
((wcmatch (setq ltyp (vla-get-linetype lay)) "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
(put_linetype lay "Center2" "acadiso.lin")
)
)
)
(princ)
)

0 Likes
Accepted solutions (1)
1,744 Views
9 Replies
Replies (9)
Message 2 of 10

Ranjit_Singh
Advisor
Advisor

The code is going through all layers and based on the linetype of each layer picks the corresponding new linetype. It has nothing to do with the entities. Try setting all linetypes to by layer before calling your routine

(mapcar '(lambda (x) (vl-catch-all-apply 'vla-put-linetype (list x "ByLayer")))
        (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x")))))

If, however, you want to test the type of forced linetype and accordingly assign the corresponding new linetype then try adding this to the end of your code (after processing all layers)

 

(mapcar '(lambda (x)
           (if (vlax-property-available-p x 'linetype)
             (cond ((wcmatch (setq ltyp (vla-get-linetype x)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
                    (vla-put-linetype x "HIDDEN2")
                    )
                   ((wcmatch (setq ltyp (vla-get-linetype x)) "Dash 1_16_,Dash Dot 3_16_,Long dash")
                    (vla-put-linetype x "HIDDEN")
                    )
                   ((wcmatch (setq ltyp (vla-get-linetype x)) "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
                    (vla-put-linetype x "Center2")
                    )
                   (t ())
                   )))
        (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x")))))

No testing at all.

 

0 Likes
Message 3 of 10

3arizona
Advocate
Advocate

Ranjit Singh,

 

Command take long to process but it doesn't work.  This is what how i put it together. maybe i put it out of sequence? i need it to pick up both layers and forced line types. like MERGE LAYERS command.

 

(vl-load-com)
(defun c:demoLN (/ put_linetype linetypes ltyp ltyps)
(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setq linetypes (vla-get-linetypes adoc))
(vlax-for ltyp (vla-get-linetypes adoc)
(setq ltyps (cons (vla-get-name ltyp) ltyps))
)
(defun put_linetype (obj linetype linefile)
(if (vl-position linetype ltyps)
(vla-put-linetype obj linetype)
(progn
(vla-load linetypes linetype linefile)
(setq ltyps (cons linetype ltyps))
(vla-put-linetype lay linetype)
)
)
)
(vlax-for lay (vla-get-layers adoc)
(cond ((wcmatch (setq ltyp (vla-get-linetype lay)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
(put_linetype lay "HIDDEN2" "acadiso.lin")
)
((wcmatch (setq ltyp (vla-get-linetype lay)) "Dash 1_16_,Dash Dot 3_16_,Long dash")
(put_linetype lay "HIDDEN" "acadiso.lin")
)
((wcmatch (setq ltyp (vla-get-linetype lay)) "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
(put_linetype lay "Center2" "acadiso.lin")
)
(mapcar '(lambda (x)
(if (vlax-property-available-p x 'linetype)
(cond ((wcmatch (setq ltyp (vla-get-linetype x)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
(vla-put-linetype x "HIDDEN2")
)
((wcmatch (setq ltyp (vla-get-linetype x)) "Dash 1_16_,Dash Dot 3_16_,Long dash")
(vla-put-linetype x "HIDDEN")
)
((wcmatch (setq ltyp (vla-get-linetype x)) "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
(vla-put-linetype x "Center2")
)
(t ())
)))
(mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x")))))
)
)
(princ)
)

0 Likes
Message 4 of 10

Ranjit_Singh
Advisor
Advisor

Try below. If it still does not work then post a sample drawing?

(vl-load-com)
(defun c:demoln  (/ adoc linetypes ltyps ssobj)
 (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
 (setq linetypes (vla-get-linetypes adoc))
 (vlax-for ltyp (vla-get-linetypes adoc) (setq ltyps (cons (vla-get-name ltyp) ltyps)))
 (defun put_linetype  (obj linetype linefile)
  (if (vl-position linetype ltyps)
   (vla-put-linetype obj linetype)
   (progn (vla-load linetypes linetype linefile)
          (setq ltyps (cons linetype ltyps))
          (vla-put-linetype lay linetype))))
 (vlax-for lay  (vla-get-layers adoc)
  (cond ((wcmatch (setq ltyp (vla-get-linetype lay)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
         (put_linetype lay "HIDDEN2" "acadiso.lin"))
        ((wcmatch (setq ltyp (vla-get-linetype lay)) "Dash 1_16_,Dash Dot 3_16_,Long dash")
         (put_linetype lay "HIDDEN" "acadiso.lin"))
        ((wcmatch (setq ltyp (vla-get-linetype lay)) "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
         (put_linetype lay "Center2" "acadiso.lin"))
        (t ())))
 (ssget "_x")
 (setq ssobj (vla-get-activeselectionset adoc))
 (vlax-for x  ssobj
  (if (vlax-property-available-p x 'linetype)
   (cond ((wcmatch (setq ltyp (vla-get-linetype x)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
          (vla-put-linetype x "HIDDEN2"))
         ((wcmatch (setq ltyp (vla-get-linetype x)) "Dash 1_16_,Dash Dot 3_16_,Long dash")
          (vla-put-linetype x "HIDDEN"))
         ((wcmatch (setq ltyp (vla-get-linetype x)) "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
          (vla-put-linetype x "Center2"))
         (t ()))))
 (princ))
0 Likes
Message 5 of 10

3arizona
Advocate
Advocate


Ranjit Singh,

 

Only changes the layers and no forced layers.

 

i get this error:

 

; error: Automation Error. Key not found

0 Likes
Message 6 of 10

Ranjit_Singh
Advisor
Advisor

As I mentioned before, post a sample drawing.

0 Likes
Message 7 of 10

3arizona
Advocate
Advocate

Here you go. Only a few lines as i had trouble uploading files before.

 

Thanks

0 Likes
Message 8 of 10

Ranjit_Singh
Advisor
Advisor
Accepted solution

OK. Try now. It works for me

(defun c:demoln  (/ adoc linetypes ltyps ssobj)
 (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
 (setq linetypes (vla-get-linetypes adoc))
 (vlax-for ltyp (vla-get-linetypes adoc) (setq ltyps (cons (vla-get-name ltyp) ltyps)))
 (defun put_linetype  (obj linetype linefile)
  (if (vl-position linetype ltyps)
   (vla-put-linetype obj linetype)
   (progn (vla-load linetypes linetype linefile)
          (setq ltyps (cons linetype ltyps))
          (vla-put-linetype lay linetype))))
 (vlax-for lay (vla-get-layers adoc) (demoln lay))
 (ssget "_x")
 (setq ssobj (vla-get-activeselectionset adoc))
 (vlax-for lay  ssobj
  (if (vlax-property-available-p lay 'linetype)
   (demoln lay)))
 (princ))
(defun demoln  (x / ltyp)
 (cond ((wcmatch (setq ltyp (vla-get-linetype x)) "Hidden 1_8_,Hidden 1_8_,Overhead 1_16_")
        (put_linetype x "HIDDEN2" "acadiso.lin"))
       ((wcmatch ltyp "Dash 1_16_,Dash Dot 3_16_,Long dash") (put_linetype x "HIDDEN" "acadiso.lin"))
       ((wcmatch ltyp "IMPORT-CHAINTHIN0,Grid 1_2_,Grid Line 1_2_")
        (put_linetype x "Center2" "acadiso.lin"))
       (t ())))

demoln.gif

 

Message 9 of 10

3arizona
Advocate
Advocate

Ranjit Singh;

 

works perfect!

 

thanks for your time

0 Likes
Message 10 of 10

3arizona
Advocate
Advocate

Ranjit Singh,

 

I've noticed if an exiting drawing has one of the line type being loaded from the lisp, it doesn't work. Would it be easier to load lines at the beginning of the lisp and skip the loading from acadiso.lin".

 

(put_linetype x "HIDDEN2" "acadiso.lin"))

 

 

AutoCAD error:

 

; error: Automation Error. Duplicate record name

 

0 Likes