LISP for automatic layer changing

LISP for automatic layer changing

liamQ8LGU
Explorer Explorer
653 Views
8 Replies
Message 1 of 9

LISP for automatic layer changing

liamQ8LGU
Explorer
Explorer

AutoCAD Experts,

 

I am trying to implement a LISP routine where the layers from an external consultants DWG file are automatically changed to reflect my layer conventions. I've found an easy LISP routine (attached) which uses the laymrg function, however the issue is when the layer does not exist in the DWG (which is common as consultants often purge their DWG's before releasing) the LISP will not function properly. Any advice on how to overcome this issue? Any help would be greatly appreciated.

0 Likes
Accepted solutions (1)
654 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

To stop layer is missing problems just add does layer exist 1st, (tblsearch "LAYER" layername) will return T if layer exists. 

0 Likes
Message 3 of 9

liamQ8LGU
Explorer
Explorer
Thank you, I think this is the solution but I am a LISP routine noob and not sure exactly how to implement. Are you able to attach the original LISP I included with the tblsearch as required?
0 Likes
Message 4 of 9

Sea-Haven
Mentor
Mentor

Need a rewrite 

(setq laylst (list (list "RIDGER" "Ex_Building Roof")
(list "DTM_Existing_contours" "Ex_Contours")
(list "PAVER" "Ex_Pavers")
(list "RIDGE" "Ex_Building Roof")))

(foreach lay laylst
(if (tblsearch "layer" (cadr lay))
(Command "_laymrg" "t" (car lay) "" "t" (cadr lay) "y")
)
)

 

Not tested. 

0 Likes
Message 5 of 9

liamQ8LGU
Explorer
Explorer
Unfortunately I'm not having any luck with merging the two LISP's. I'm still getting the same problem when a layer doesn't exist.
0 Likes
Message 6 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Maybe use a feature that is already built in? SEE HERE 

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

Shouldn't it test for the presence of both Layers for each merge?  How about [untested]:

(defun C:LC (/ pairs)
  (setq pairs
    '(
      ("RIDGER" "Ex_Building Roof")
      ("DTM_Existing_contours" "Ex_Contours")
      ("PAVER" "Ex_Pavers")
      ("RIDGE" "Ex_Building Roof")
    ); list
  ); setq
  (foreach pair pairs
    (if (and (tblsearch "layer" (car pair)) (tblsearch "layer" (cadr pair)))
    (command "_.laymrg" "_t" (car pair) "" "_t" (cadr pair) "y")
  ); foreach
  (prin1)
); defun

 

Kent Cooper, AIA
0 Likes
Message 8 of 9

liamQ8LGU
Explorer
Explorer

Perfect! Thanks so much. Any idea if there is a similar option for blocks??

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Pretty obvious

(tblsearch "BLOCK" "Northn")
((0 . "BLOCK") (2 . "NORTHN") (70 . 0) (10 0.0 0.0 0.0) (-2 . <Entity name: 3d3ef360>))

 

0 Likes