Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp to Rename BAD line type on Exported from REVIT drawings

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
3arizona
1272 Views, 14 Replies

Lisp to Rename BAD line type on Exported from REVIT drawings

I have a lisp that changes properties of REVIT lines to CAD lines. I previously got help on this LISP but noticed this problems on all exported drawings. 

 

Somehow exported lines keep the REVIT cache. I want to rename all BAD lines so that i can reload them later down the LISP.

 

this is what i want to add to the lisp:

(COMMAND "-RENAME" "LT" "HIDDEN" "HIDDEN-BAD" "")
(COMMAND "-RENAME" "LT" "HIDDEN2" "HIDDEN2-BAD" "")
(COMMAND "-RENAME" "LT" "CENTER" "CENTER-BAD" "")
(COMMAND "-RENAME" "LT" "CENTER2" "CENTER2-BAD" "")
(COMMAND "-RENAME" "LT" "DASHED" "DASED-BAD" "")
(COMMAND "-RENAME" "LT" "DASHED2" "DASED2-BAD" "")

 

 

This is my lisp:

(defun c:TESTlt (/ 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)) "Dash,Dash 1_16_,Dash Dot 3_16_,Dash 1_32_,Dash 1_64_,Long dash,Hidden 1_8_,Hidden 1_16_,Overhead 1_16_,HIDDEN-BAD,HIDDEN2-BAD")
(put_linetype x "HIDDEN2" "acadiso.lin"))
((wcmatch (setq ltyp (vla-get-linetype x)) "IMPORT-INVISIBLE")
(put_linetype x "dot2" "acadiso.lin"))
((wcmatch ltyp "Center 1_8_;Grid 1_2_,Grid Line 1_2_,IMPORT-CHAINTHIN0,IMPORT-CENTER _10_,IMPORT-CENTER2,IMPORT-INVISIBLE,IMPORT-CENTER2,CENTER-BAD,CENTER2-BAD,,DASHED-BAD,DASHED2-BAD")
(put_linetype x "Center2" "acadiso.lin"))
(t ())))

 

 

14 REPLIES 14
Message 2 of 15
Ranjit_Singh2
in reply to: 3arizona

Just add it to the beginning of the lisp, right after you test the adoc variable. Have  you tried it already and it isn't working?

Message 3 of 15
3arizona
in reply to: Ranjit_Singh2

Ranjit.Singh,

 

Thanks for helping again!!  Rename only works if line type is present. i want to Rename all regardless, if line type resides or not. 

 

Message 4 of 15
Ranjit_Singh2
in reply to: 3arizona

Rename only the linetypes that are retrieved by

(setq linetypes (vla-get-linetypes adoc))

The system should allow you to rename those. If something is not part of the linetypes collection then why would you rename it? it will be loaded form acadiso when needed. Am I right?

 

Message 5 of 15
3arizona
in reply to: Ranjit_Singh2

Imported drawings come in with different combinations line types. Drawing can have all line types or just 1. i wanted to cycle through and overlook the lines not found in the drawing. Right now lisp is getting stuck at the, not found line type.

 

Thanks

Message 6 of 15
Ranjit_Singh2
in reply to: 3arizona


@3arizona wrote:

.......... i wanted to cycle through and overlook the lines not found in the drawing. Right now lisp is getting stuck at the, not found line type.

 .........


That's why I said retrieve present linetypes from the adoc linetypes collection. The routine will fail if you hard code linetype names.

(defun c:TESTlt (/ adoc linetypes ltyps ssobj ltypelst)
(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setq linetypes (vla-get-linetypes adoc))
(vlax-for i linetypes (setq ltypelst (cons (vla-get-name i) ltypelst)))
(mapcar '(lambda (x) (and (member x '("Continuous" "ByLayer" "ByBlock")) (setq ltypelst (vl-remove x ltypelst)))) ltypelst)
(mapcar '(lambda (x y) (command-s "._-rename" "_lt" x y "")) ltypelst (mapcar '(lambda (x) (strcat x "-BAD")) ltypelst))
(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)
..............
..............

 

Message 7 of 15
3arizona
in reply to: Ranjit_Singh2

Ranjit.Singh,

 

This inputs "-BAD" on ALL existing line types, but it gets caught up on layers that have a space in between "Dashed Dot". This is too complicated for me. I’ll keep the lisp as is and work around it.

 

List was suppose do the fowling:

  • Rename a few layers with -BAD
  • Change properties on a list of layers (this works). the only issue is that is doesn't pick up nested (forced) line types in blocks.

 

Again thanks for your time.

Message 8 of 15
Ranjit_Singh2
in reply to: 3arizona

OK. Try below change

...........
.............
(setq linetypes (vla-get-linetypes adoc))
(vlax-for i linetypes (setq ltypelst (cons (vla-get-name i) ltypelst))) (mapcar '(lambda (x) (and (not (member x '("HIDDEN" "HIDDEN2" "CENTER" "CENTER2" "DASHED" "DASHED2"))) (setq ltypelst (vl-remove x ltypelst)))) ltypelst) (mapcar '(lambda (x y) (command-s "._-rename" "_lt" x y "")) ltypelst (mapcar '(lambda (x) (strcat x "-BAD")) ltypelst)) (vlax-for ltyp (vla-get-linetypes adoc) (setq ltyps (cons (vla-get-name ltyp) ltyps))) ..........
...........
Message 9 of 15
3arizona
in reply to: Ranjit_Singh2

works perfect.

 

Lisp now looks for line types and changes properties. Can lisp be made to also look for those line types in blocks?

 

I appreciate your time.  

 

here is the lisp now:

 

(defun c:TESTlt (/ adoc linetypes ltyps ssobj ltypelst)
(or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setq linetypes (vla-get-linetypes adoc))
(vlax-for i linetypes (setq ltypelst (cons (vla-get-name i) ltypelst)))
(mapcar '(lambda (x) (and (member x '("Continuous" "ByLayer" "ByBlock")) (setq ltypelst (vl-remove x ltypelst)))) ltypelst)
(mapcar '(lambda (x y) (command-s "._-rename" "_lt" x y "")) ltypelst (mapcar '(lambda (x) (strcat x "-BAD")) ltypelst))
(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)) "Dash-BAD,Dash 1_16_-BAD,Dash Dot 3_16_-BAD,Dash 1_32_-BAD,Dash 1_64_-BAD,Long dash-BAD,Hidden 1_8_-BAD,Hidden 1_16_-BAD,Overhead 1_16_-BAD,HIDDEN-BAD-BAD,HIDDEN2-BAD")
(put_linetype x "HIDDEN2" "acadiso.lin"))
((wcmatch (setq ltyp (vla-get-linetype x)) "IMPORT-INVISIBLE-BAD")
(put_linetype x "dot2" "acadiso.lin"))
((wcmatch ltyp "Center 1_8_-BAD,Grid 1_2_-BAD,Grid Line 1_2_-BAD,IMPORT-CHAINTHIN0-BAD,Center 1_8_-BAD,IMPORT-CENTER _10_-BAD,IMPORT-CENTER2-BAD,IMPORT-INVISIBLE-BAD,IMPORT-CENTER2-BAD,CENTER-BAD-BAD,CENTER2-BAD-BAD,DASHED-BAD,DASHED2-BAD")
(put_linetype x "Center2" "acadiso.lin"))
(t ())))

 

 

Message 10 of 15
Ranjit_Singh2
in reply to: 3arizona


@3arizona wrote:

works perfect.

....................................
(vlax-for i linetypes (setq ltypelst (cons (vla-get-name i) ltypelst)))
(mapcar '(lambda (x) (and (member x '("Continuous" "ByLayer" "ByBlock")) (setq ltypelst (vl-remove x ltypelst)))) ltypelst)
(mapcar '(lambda (x y) (command-s "._-rename" "_lt" x y "")) ltypelst (mapcar '(lambda (x) (strcat x "-BAD")) ltypelst))
...................................................

...........................

  


Try adding below right before the princ. Also your above code still shows the change I suggested in post 6. Which I thought was adding "-BAD" to all linetypes? I think you need to change that per post 8.

..................
...................
 (while (setq bln (tblnext "block" (null bln)))
  (while (setq ent (cdr (assoc -2 bln)))
   (setq entobj (vlax-ename->vla-object ent))
   (if (vlax-property-available-p ent 'linetype)
    (demoln ent))
   (setq ent (entnext ent))))
 (princ))

 

Message 11 of 15
3arizona
in reply to: Ranjit_Singh2

Ranjit.Singh,

 

Block line types are still not being picked up.

I've also decided to drop the "-BAD" line type rename. Too much trouble. see lisp below and see if do not have anything out place.

 

(defun c:TESTlt (/ 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))
(while (setq bln (tblnext "block" (null bln)))
(while (setq ent (cdr (assoc -2 bln)))
(setq entobj (vlax-ename->vla-object ent))
(if (vlax-property-available-p ent 'linetype)
(demoln ent))
(setq ent (entnext ent))))
(defun demoln (x / ltyp)
(cond ((wcmatch (setq ltyp (vla-get-linetype x)) "Long dash,Hidden 1_8_,Hidden 1_16_,Overhead 1_16_,IMPORT-INVISIBLE")
(put_linetype x "HIDDEN2" "acadiso.lin"))
((wcmatch ltyp "Dash,Dash 1_8_,Dash 1_16_,Dash Dot 3_16_,Dash 1_32_,Dash 1_64_")
(put_linetype x "HIDDEN" "acadiso.lin"))
((wcmatch ltyp "Center 1_8_,Grid Line,Grid 1_2_,Grid Line 1_2_,Grid Line 1_4_,IMPORT-CHAINTHIN0,IMPORT-CENTER _10_,IMPORT-CENTER2,IMPORT-INVISIBLE,IMPORT-CENTER2,2HF 1_4_,Center 1_8_")
(put_linetype x "Center2" "acadiso.lin"))
(t ())))

Message 12 of 15
Ranjit_Singh2
in reply to: 3arizona

Maybe like this. If it still doesn't;t work then you may need to post a drawing.

(defun c:testlt  (/ adoc linetypes ltyps ssobj)
 (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
 (setq linetypes (vla-get-linetypes adoc))
 (vlax-for i linetypes (setq ltypelst (cons (vla-get-name i) ltypelst)))
 (mapcar '(lambda (x)
           (and (not (member x '("HIDDEN" "HIDDEN2" "CENTER" "CENTER2" "DASHED" "DASHED2")))
                (setq ltypelst (vl-remove x ltypelst))))
         ltypelst)
 (mapcar '(lambda (x y) (command-s "._-rename" "_lt" x y ""))
         ltypelst
         (mapcar '(lambda (x) (strcat x "-BAD")) ltypelst))
 (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)))
 (while (setq bln (tblnext "block" (null bln)))
  (while (setq ent (cdr (assoc -2 bln)))
   (setq entobj (vlax-ename->vla-object ent))
   (if (vlax-property-available-p ent 'linetype)
    (demoln ent))
   (setq ent (entnext ent))))
 (princ))

(defun demoln  (x / ltyp)
 (cond ((wcmatch (setq ltyp (vla-get-linetype x))
                 "Long dash,Hidden 1_8_,Hidden 1_16_,Overhead 1_16_,IMPORT-INVISIBLE")
        (put_linetype x "HIDDEN2" "acadiso.lin"))
       ((wcmatch ltyp "Dash,Dash 1_8_,Dash 1_16_,Dash Dot 3_16_,Dash 1_32_,Dash 1_64_")
        (put_linetype x "HIDDEN" "acadiso.lin"))
       ((wcmatch ltyp
                 "Center 1_8_,Grid Line,Grid 1_2_,Grid Line 1_2_,Grid Line 1_4_,IMPORT-CHAINTHIN0,IMPORT-CENTER _10_,IMPORT-CENTER2,IMPORT-INVISIBLE,IMPORT-CENTER2,2HF 1_4_,Center 1_8_")
        (put_linetype x "Center2" "acadiso.lin"))
       (t ())))
Message 13 of 15
3arizona
in reply to: Ranjit_Singh2

here is copy one of the drawings

Message 14 of 15
Ranjit_Singh2
in reply to: 3arizona

This seems to work on the attached drawing

(defun c:testlt  (/ adoc linetypes ltyps ssobj)
 (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
 (setq linetypes (vla-get-linetypes adoc))
 (vlax-for i linetypes (setq ltypelst (cons (vla-get-name i) ltypelst)))
 (mapcar '(lambda (x)
           (and (not (member x '("HIDDEN" "HIDDEN2" "CENTER" "CENTER2" "DASHED" "DASHED2")))
                (setq ltypelst (vl-remove x ltypelst))))
         ltypelst)
 (mapcar '(lambda (x y) (command-s "._-rename" "_lt" x y ""))
         ltypelst
         (mapcar '(lambda (x) (strcat x "-BAD")) ltypelst))
 (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)))
 (while (setq bln (tblnext "block" (null bln)))
  (setq ent (cdr (assoc -2 bln)))
  (while ent
   (setq entobj (vlax-ename->vla-object ent))
   (if (vlax-property-available-p entobj 'linetype)
    (demoln entobj))
   (setq ent (entnext ent))))
 (princ))
(defun demoln  (x / ltyp)
 (cond ((wcmatch (setq ltyp (vla-get-linetype x))
                 "Long dash,Hidden 1_8_,Hidden 1_16_,Overhead 1_16_,IMPORT-INVISIBLE")
        (put_linetype x "HIDDEN2" "acadiso.lin"))
       ((wcmatch ltyp "Dash,Dash 1_8_,Dash 1_16_,Dash Dot 3_16_,Dash 1_32_,Dash 1_64_")
        (put_linetype x "HIDDEN" "acadiso.lin"))
       ((wcmatch ltyp
                 "Center 1_8_,Grid Line,Grid 1_2_,Grid Line 1_2_,Grid Line 1_4_,IMPORT-CHAINTHIN0,IMPORT-CENTER _10_,IMPORT-CENTER2,IMPORT-INVISIBLE,IMPORT-CENTER2,2HF 1_4_,Center 1_8_")
        (put_linetype x "Center2" "acadiso.lin"))
       (t ())))
Message 15 of 15
3arizona
in reply to: Ranjit_Singh2

Ranjit.Singh,

 

That's it, thanks!!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost