Hi Tom i did a little bit of tweaking and the code seems to work well so far, thanks for your help.
I have added code to change the layers that i know of but would still like to know how to select and edit the layer properties based on their assigned properties (linetypes, etc).
Here is the code I'm currently using
Code:
(vl-load-com)
(defun C:fb (/ *ERROR* SSET intCount ENAM EOBJ ELST BNAM FLST FIX1)
(setq thisdrawing (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark thisdrawing)
;Roy-Load Linetypes
(if (tblsearch "LTYPE" "centre")
(command "-linetype" "l" "centre" "C:/Program Files/AutoCAD 2010/Support/Linetypes/Centre.lin" "YES" "")
(command "-linetype" "l" "centre" "C:/Program Files/AutoCAD 2010/Support/Linetypes/Centre.lin" "")
)(princ)
(if (tblsearch "LTYPE" "dot2")
(command "-linetype" "l" "dot2" "C:/Documents and Settings/jonesr/Application Data/Autodesk/AutoCAD 2010/R18.0/enu/Support/acad.lin" "YES" "")
(command "-linetype" "l" "dot2" "C:/Documents and Settings/jonesr/Application Data/Autodesk/AutoCAD 2010/R18.0/enu/Support/acad.lin" "")
)(princ)
(if (tblsearch "LTYPE" "HIDDEN")
(command "-linetype" "l" "HIDDEN" "C:/Documents and Settings/jonesr/Application Data/Autodesk/AutoCAD 2010/R18.0/enu/Support/acad.lin" "YES" "")
(command "-linetype" "l" "HIDDEN" "C:/Documents and Settings/jonesr/Application Data/Autodesk/AutoCAD 2010/R18.0/enu/Support/acad.lin" "")
)(princ)
(if (tblsearch "LTYPE" "PHANTOM")
(command "-linetype" "l" "PHANTOM" "C:/Documents and Settings/jonesr/Application Data/Autodesk/AutoCAD 2010/R18.0/enu/Support/acad.lin" "YES" "")
(command "-linetype" "l" "PHANTOM" "C:/Documents and Settings/jonesr/Application Data/Autodesk/AutoCAD 2010/R18.0/enu/Support/acad.lin" "")
)(princ)
(prompt "\n\n")
(prompt "\nLINETYPES LOADED")
(command "resume")
(princ)
;=================
(defun *ERROR* (err) ; define local handler
(vl-cmdf "undo" "Mark")
(princ "\n\n")
(princ)
); "" is the same message you get when exiting an AutoCAD command.
(defun FIX1 (BNAM / BENAM BONAM)
(if (not (member BNAM FLST))
(progn
(setq FLST (cons BNAM FLST)
BENAM (tblobjname "block" BNAM)
)
(while (setq BENAM (entnext BENAM))
(if (= (cdr (assoc 0 (entget BENAM))) "INSERT")
(fix1 (cdr (assoc 2 (entget BENAM))))
(progn
(setq BONAM(vlax-ename->vla-object BENAM))
(cond
; roys code
((= "DGN Style 1"(vlax-get-property BONAM 'Linetype))
(vl-catch-all-apply 'vla-put-LinetypeScale (list BONAM 5))
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Dot2"))
)
; roys code
((= "DGN Style 2"(vlax-get-property BONAM 'Linetype))
(vl-catch-all-apply 'vla-put-LinetypeScale (list BONAM 10))
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Hidden"))
)
((= "DGN Style 3"(vlax-get-property BONAM 'Linetype))
(vl-catch-all-apply 'vla-put-LinetypeScale (list BONAM 10))
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Hidden"))
)
((= "DGN Style 4"(vlax-get-property BONAM 'Linetype))
(vl-catch-all-apply 'vla-put-LinetypeScale (list BONAM 1))
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Centre"))
)
((= "DGN Style 6"(vlax-get-property BONAM 'Linetype))
(vl-catch-all-apply 'vla-put-LinetypeScale (list BONAM 3))
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Phantom"))
)
((= "DGN Style 7"(vlax-get-property BONAM 'Linetype))
(vl-catch-all-apply 'vla-put-LinetypeScale (list BONAM 1))
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Centre"))
)
(T
(vl-catch-all-apply 'vla-put-linetype (list BONAM "Byblock"))
)
)
(vl-catch-all-apply 'vla-put-layer (list BONAM "0"))
(vl-catch-all-apply 'vla-put-color (list BONAM 0))
;Roy-Set Linetype Generation
(vl-catch-all-apply 'vla-put-linetypegeneration (list BONAM 0))
;===========================
)
)
)
)
)
)
;ALL OBJECTS NOT IN BLOCKS
(PROMPT "\n PROCESSING ALL OBJECTS NOT IN BLOCKS")
(if (setq SSET (ssget "X" (list (cons 6 "DGN Style 2,DGN Style 3"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vla-put-LinetypeScale EOBJ 10)
(vla-put-Linetype EOBJ "Hidden")
)
(prompt "\n No objects outside of blocks with a linetype of DGN Style 2,DGN Style 3")
)
(if (setq SSET (ssget "X" (list (cons 6 "DGN Style 4,DGN Style 7"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vla-put-LinetypeScale EOBJ 1)
(vla-put-Linetype EOBJ "CENTRE")
)
(prompt "\n No objects outside of blocks with a linetype of DGN Style 4,DGN Style 7")
)
(if (setq SSET (ssget "X" (list (cons 6 "DGN Style 6"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vla-put-LinetypeScale EOBJ 3)
(vla-put-Linetype EOBJ "PHANTOM")
)
(prompt "\n No objects outside of blocks with a linetype of DGN Style 6")
)
;Roy-Set Linetype Generation
(if (setq SSET (ssget "x" (list (cons 0 "LWpolyline"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vl-catch-all-apply 'vla-put-linetypegeneration (list EOBJ 0))
)
(prompt "\n No objects outside of blocks that are Polylines")
)
;===================
;Roy-Set Color Correction
(if (setq SSET (ssget "x" (list (cons 62 254))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vl-catch-all-apply 'vla-put-color (list EOBJ 9))
)
(prompt "\n No objects outside of blocks that are Polylines")
)
;===================
;Roy-Set properties of known Layers
(command "-layer" "l" "centre" "centre,1000-Excavation Centre Lines" "")
(princ)
(command "-layer" "l" "Phantom" "phantom,Handrail SingleLine" "")
(princ)
(command "-layer" "l" "hidden" "hidden,Concrete-Hidden1,Steel_BeamHidden,Steel_ColumnHidden" "")
(princ)
(command "-layer" "c" "9" "phantom,hatch,hidden" "")
(princ)
(command ^C^C)
;===================
;Roy-Set properties of known Layer Objects
(if (setq SSET (ssget "x" (list (cons 8 "phantom,Handrail SingleLine"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vla-put-LinetypeScale EOBJ 3)
(vla-put-Linetype EOBJ "bylayer")
)
(prompt "\n No objects on layers named phantom,Handrail SingleLine")
)
(if (setq SSET (ssget "x" (list (cons 8 "hidden,Concrete-Hidden1,Steel_BeamHidden,Steel_ColumnHidden"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vla-put-LinetypeScale EOBJ 10)
(vla-put-Linetype EOBJ "ByLayer")
)
(prompt "\n No objects on layers named hidden,Concrete-Hidden1,Steel_BeamHidden,Steel_ColumnHidden")
)
(if (setq SSET (ssget "x" (list (cons 8 "centre,1000-Excavation Centre Lines"))))
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
EOBJ (vlax-ename->vla-object ENAM)
)
(vla-put-LinetypeScale EOBJ 1)
(vla-put-Linetype EOBJ "ByLayer")
)
(prompt "\n No objects on layers named centre,1000-Excavation Centre Lines")
)
;===================
(setq SSET (ssget "X" (list (cons 0 "INSERT")))) ; every block in drawing
;(setq SSET (ssget (list (cons 0 "INSERT")))) ; pick blocks
(repeat (setq intCount (sslength SSET))
(setq intCount (1- intCount)
ENAM (ssname SSET intCOunt)
ELST (entget ENAM)
BNAM (cdr (assoc 2 ELST))
FLST nil
)
(fix1 BNAM)
)
(vl-cmdf "regen")
(vla-endundomark thisdrawing)
(princ)
(command "resume")
)