rob150588 Posted February 19, 2009 Author Posted February 19, 2009 My apologies Rob - working on a mere '04 version, I wasn't aware that they had been incorporated into the full version... With this knowledge, it would probably be easier just to use the LayMrg function within the code. As for your other request to have the colour and linetype.. this is not too difficult to incorporate - I shall look into it Everyone knows '04 was the best release anyway. Thanks very much. Rob. Quote
Lee Mac Posted February 19, 2009 Posted February 19, 2009 Try this for starters (untested as laymrg is still express on mine...) (defun mlay (lay1 lay2 / oldcmd) (vl-load-com) (setq oldcmd (getvar "cmdecho")) (mapcar 'setvar '("CMDECHO" "CLAYER") '(0 "0")) (if (and (tblsearch "layer" lay1) (not (eq "0" lay1)) (tblsearch "layer" lay2)) (progn (command "_laymrg" "T" lay1 "" "T" lay2 "Y")) (princ "\n<!> Error in Argument Specification <!>")) (setvar "cmdecho" oldcmd)) (defun c:test () (mlay "detail" "cd-pipework") (princ) ) Quote
rob150588 Posted February 20, 2009 Author Posted February 20, 2009 Not sure why but that doesn't work at all. It just reports: <!> Error in Argument Specification <!> So whatever's happening it's not reading the layer list right. I tried making a few tweaks to the code to see if I could jump start it: ; Layer Merger ~ Lee McDonnell 18.02.09 ; Two Args (strings): ; lay1 = layer to be deleted ; lay2 = layer to be merged to (defun mlay (lay1 lay2 / oldcmd) (vl-load-com) (setq oldcmd (getvar "cmdecho")) (mapcar 'setvar '("CMDECHO" "CLAYER") '(0 "0")) (if (and (tblsearch "layer" lay1) (not (eq "0" lay1)) (tblsearch "layer" lay2)) (progn (command "_-laymrg" "N" lay1 "" "N" lay2 "Y")) (princ "\n<!> Error in Argument Specification <!>")) (setvar "cmdecho" oldcmd)) (defun c:mmbl () (mlay "DETAIL" "CD-PIPEWORK") (mlay "PLANNING" "CD-PLANNING") (mlay "CENTRELINE" "CD-BOLTS") (mlay "SYMBOL" "Z-SYMBOL") (mlay "ORIGIN" "Z-ORIGIN") (mlay "DETAILV" "CD-VALVES") (mlay "CONCRETE" "CD-CONCRETE") (mlay "BLOCKWORK" "CD-BLOCKWORK") (princ) ) No luck... Wasn't sure about the part that was running the commands. Changed T to N (because N tells it to specify a name, not an object). And added the "-" to laymrg to run it solely on the command line, no dialogue boxes. It was probably wrong, but hey, I tried. Cheers. Rob. Quote
Lee Mac Posted February 20, 2009 Posted February 20, 2009 I must admit, I for the prompts for the layer mrg command, I just went on what was present in the laymrg express tools which doesn't have a dialog box and uses "T" for "type-it". But the "Error in Arguments Specification" can only mean three things: lay1 is not in the drawing lay2 is not in the drawing lay1 is the "0" layer. With all of these specified correctly and the laymrg prompts correct, the function should work smoothly. Quote
rob150588 Posted February 20, 2009 Author Posted February 20, 2009 Yeah, I just worked that out myself . Lay2 is not in the current drawing, because the part that creates the layers if they are not present isn't there. I've been trying to work out how to get that function back in based on the previous code you've posted. But I'm running out of ideas: This is as far as I got...the commented out stuff is what I copied from the previous code: ; Layer Merger ~ Lee McDonnell 18.02.09 ; Two Args (strings): ; lay1 = layer to be deleted ; lay2 = layer to be merged to (defun mlay (lay1 lay2 / oldcmd) (vl-load-com) (setq oldcmd (getvar "cmdecho")) (mapcar 'setvar '("CMDECHO" "CLAYER") '(0 "0")) (if (and (tblsearch "layer" lay1) (not (eq "0" lay1)) (tblsearch "layer" lay2)) ; (progn ; (if (not (tblsearch "layer" lay2)) (command "-layer" "m" lay2 "")) ; (setq eLst (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))) ; (mapcar '(lambda (x) (entmod (subst (cons 8 lay2) (assoc 8 x) x))) eLst) ; (if (vl-catch-all-error-p ; (vl-catch-all-apply 'vla-Delete (list (vlax-ename->vla-object (tblobjname "LAYER" lay1))))) ; (mapcar 'setvar vlst ovar)) ; (princ "\n<!> Layer Could not be Deleted <!>"))) ; (princ "\n<!> Error in Layer Name Specification <!>")) (progn (command "-laymrg" "N" lay1 "" "N" lay2 "Y")) (princ "\n<!> Error in Argument Specification <!>")) (setvar "cmdecho" oldcmd)) (defun c:mmbl () (mlay "DETAIL" "CD-PIPEWORK") (mlay "PLANNING" "CD-PLANNING") (mlay "CENTRELINE" "CD-BOLTS") (mlay "SYMBOL" "Z-SYMBOL") (mlay "ORIGIN" "Z-ORIGIN") (mlay "DETAILV" "CD-VALVES") (mlay "CONCRETE" "CD-CONCRETE") (mlay "BLOCKWORK" "CD-BLOCKWORK") (princ) ) There's probably some blindingly obvious solution that I'm missing... Cheers. Rob. Quote
Lee Mac Posted February 20, 2009 Posted February 20, 2009 Ok try this: Populate the table with the desired linetypes and colours ; Layer Merger ~ Lee McDonnell 18.02.09 ; Two Args (strings): ; lay1 = layer to be deleted ; lay2 = layer to be merged to (defun mlay (lay1 lay2 / oldcmd) (vl-load-com) (setq oldcmd (getvar "cmdecho")) (mapcar 'setvar '("CMDECHO" "CLAYER") '(0 "0")) (if (and (tblsearch "layer" lay1) (not (eq "0" lay1))) (progn (if (not (tblsearch "layer" lay2)) (makelay lay2)) (command "_-laymrg" "N" lay1 "" "N" lay2 "Y")) (princ "\n<!> Error in Argument Specification <!>")) (setvar "cmdecho" oldcmd)) (defun c:mmbl () (mlay "DETAIL" "CD-PIPEWORK") (mlay "2" "CD-PLANNING") (princ) ) (defun makelay (nme) (setq laytbl '( ("CD-PIPEWORK" . ("2" "HIDDEN")) ; populate with format ("layername" . ("colournumber" "linetype")) ("CD-PLANNING" . ("4" "CONTINUOUS")) ) ) ; end setq (if (assoc nme laytbl) (command "-layer" "M" nme "C" (cadr (assoc nme laytbl)) nme "L" (caddr (assoc nme laytbl)) nme "") (command "-layer" "M" nme ""))) Quote
rob150588 Posted February 20, 2009 Author Posted February 20, 2009 That works absolutely brilliantly. :D Well Lee, thank you very much for you time. It was much appreciated. I shall post the final version when I have written all the layers into it so there is a record of it. Thanks again. Rob. (Now available with big smile). Quote
Lee Mac Posted February 20, 2009 Posted February 20, 2009 Excellent rob, glad it worked for you - I took a bit longer to work out what would be the best way to have a layer table that you could easily edit. But thanks for the compliments - much appreciated. Cheers Lee Quote
rob150588 Posted February 24, 2009 Author Posted February 24, 2009 Here we go, this is the final code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Layer Merger Tool. ;;;;;;;;;; Version 1.4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Revision: Made By: Details: ;; ; 1.0 Lee McDonnell First Revision. ;; ; 1.1 Lee McDonnell Layer creation function added. ;; ; 1.2 Lee McDonnell Function altered to incorporate "-laymrg" command. ;; ; 1.3 Lee McDonnell Layer table added. ;; ; 1.4 Rob Jackson Additional layers added, Error message altered. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun mlay (lay1 lay2 / oldcmd) (vl-load-com) (setq oldcmd (getvar "cmdecho")) (mapcar 'setvar '("CMDECHO" "CLAYER") '(0 "0")) (if (and (tblsearch "layer" lay1) (not (eq "0" lay1))) (progn (if (not (tblsearch "layer" lay2)) (makelay lay2)) (command "_-laymrg" "N" lay1 "" "N" lay2 "Y")) (princ (strcat "\n<!> WARNING, LAYER "lay1" NOT PRESENT IN DRAWING <!>"))) (setvar "cmdecho" oldcmd)) (defun c:mmbl () ; Fastrack Layers: (mlay "DETAIL" "CD-PIPEWORK") (mlay "PLANNING" "CD-PLANNING") (mlay "HIDDEN" "CD-HIDDEN") (mlay "ORIGIN" "CD-ORIGIN") (mlay "SYMBOL" "CD-SYMBOL") (mlay "DETAILV" "CD-VALVES") (mlay "CENTRELINE" "CD-CENTRELINE") (mlay "BOLTS" "CD-BOLTS") (mlay "PAMATT" "CD-PAMATT") ; Detailing Layers: (mlay "BLOCKWORK" "CD-BLOCKWORK") (mlay "BRICKWORK" "CD-BRICKWORK") (mlay "CONCRETE" "CD-CONCRETE") (mlay "EXISTING" "CD-EXISTING") (mlay "GROUND" "CD-GROUND") (mlay "HATCH" "CD-HATCH") (mlay "PIPEWORK" "CD-PIPEWORK") (mlay "PRECAST-CONCRETE" "CD-PRECAST-CONCRETE") (mlay "PUMPS" "CD-PUMPS") (mlay "SHADE" "CD-SHADE") (mlay "STEELWORK" "CD-STEELWORK") (mlay "REINFORCEMENT" "CD-REINFORCEMENT") ; General Layers: (mlay "018TEXT" "Z-018TEXT") (mlay "025TEXT" "Z-025TEXT") (mlay "035TEXT" "Z-035TEXT") (mlay "050TEXT" "Z-050TEXT") (mlay "070TEXT" "Z-070TEXT") (mlay "DIMENSIONS" "Z-DIMENSIONS") (mlay "LEVELS" "Z-LEVELS") (mlay "VIEWPORT" "Z-VIEWPORT") (princ) ) (defun makelay (nme) (setq laytbl '( ; Fastrack Layers: ("CD-PIPEWORK" . ("2" "CONTINUOUS")) ("CD-PLANNING" . ("1" "CENTER")) ("CD-HIDDEN" . ("1" "CONTINUOUS")) ("CD-ORIGIN" . ("6" "CONTINUOUS")) ("CD-SYMBOL" . ("7" "CONTINUOUS")) ("CD-VALVES" . ("4" "CONTINUOUS")) ("CD-CENTRELINE" . ("3" "CENTER")) ("CD-BOLTS" . ("3" "CONTINUOUS")) ("CD-PAMATT" . ("7" "CONTINUOUS")) ; Detailing Layers: ("CD-BLOCKWORK" . ("3" "CONTINUOUS")) ("CD-BRICKWORK" . ("3" "CONTINUOUS")) ("CD-CONCRETE" . ("4" "CONTINUOUS")) ("CD-EXISTING" . ("8" "CONTINUOUS")) ("CD-GROUND" . ("3" "CONTINUOUS")) ("CD-HATCH" . ("1" "CONTINUOUS")) ("CD-PRECAST-CONCRETE" . ("4" "CONTINUOUS")) ("CD-PUMPS" . ("3" "CONTINUOUS")) ("CD-SHADE" . ("253" "CONTINUOUS")) ("CD-STEELWORK" . ("3" "CONTINUOUS")) ("CD-REINFORCEMENT" . ("4" "DASHDOT")) ; General Layers: ("Z-018TEXT" . ("1" "CONTINUOUS")) ("Z-025TEXT" . ("7" "CONTINUOUS")) ("Z-035TEXT" . ("2" "CONTINUOUS")) ("Z-050TEXT" . ("4" "CONTINUOUS")) ("Z-070TEXT" . ("5" "CONTINUOUS")) ("Z-DIMENSIONS" . ("7" "CONTINUOUS")) ("Z-LEVELS" . ("7" "CONTINUOUS")) ("Z-VIEWPORT" . ("6" "CONTINUOUS")) ) ) ; end setq (if (assoc nme laytbl) (command "-layer" "M" nme "C" (cadr (assoc nme laytbl)) nme "L" (caddr (assoc nme laytbl)) nme "") (command "-layer" "M" nme ""))) Rob. Quote
Lee Mac Posted February 24, 2009 Posted February 24, 2009 Excellent Rob, Its good to see it being put to good use Glad that it saves you some time If you have any other questions regarding the code, just ask Cheers Lee Quote
Recommended Posts
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.