jamami Posted yesterday at 12:36 PM Author Posted yesterday at 12:36 PM This is a typical example drawing, you will see the bogus linetypes and block. I have processed 6 scripts files now on this one folder (500+ drawings each time), and after each time consumung cycles I realise that something else isn't quite perfect... AA0003-3D-LWT.dwg Quote
jamami Posted yesterday at 12:53 PM Author Posted yesterday at 12:53 PM i am getting somewhere I have wblocked out all entities to a new 'mirror' files, this has got rid of all the detritus. then i hacked your brilliant routine (below) and reprocessed all the files. i have noticed a few files still have am_5 and am_7 layers in them!! ;;; Clean drawings to match standards ;;; ;;; https://www.cadtutor.net/forum/topic/98263-extracting-block-data-to-a-report/#findComment-673250 ;;; ;;; SLW210 (a.k.a. Steve Wilson) ;;; ;;; CheckDrawing_1-1.lsp ;;; ;;; Made more robust layer handling and some general clean-up ;| ************************************************************************************************************** | Moves 3D solids to layer `3D` | | Moves centrelines (assumed to be lines with "center" linetype) to `CL` (for red) or `CL_SS` (for color 150)| | Sets all entities’ color, linetype, and lineweight to BYLAYER | | Sets current layer to `0` | | Purges 3x | | Sets UCS to World | | Sets visual style to Conceptual | | Sets view to SW Isometric | | Zooms to Extents | | Ensures layer `0` is empty, and layers `CL`, `CL_SS`, `3D` exist with correct settings | *************************************************************************************************************|; (defun strp (x) (eq (type x) 'STR)) ;; Ensure required layers exist (adjust as needed) (defun ensure-layer (name color) (if (not (tblsearch "LAYER" name)) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 name) ; Layer name (cons 70 0) ; Layer flags (cons 62 color) ; ACI color (cons 6 "Continuous") ; Linetype ) ) ) ) (defun c:setdrawing (/ ) ;; Create layers with specified colors (ensure-layer "D-3D-SOL" 7) ; White (ensure-layer "D-3D-CLG" 1) ; Red (ensure-layer "D-3D-CLM" 5) ; Blue ;; Set current layer to sol (command "_.layer" "_set" "D-3D-SOL" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.3" "" "") (command "_.layer" "_l" "Continuous" "" "") ;; Set current layer to clm (command "_.layer" "_set" "D-3D-CLM" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.18" "" "") (command "_.layer" "_l" "Center" "" "") ;; Set current layer to clg (command "_.layer" "_set" "D-3D-CLG" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.18" "" "") (command "_.layer" "_l" "Center" "" "") ;; Set current layer to 0 (command "_.layer" "_set" "0" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.25" "" "") (command "_.layer" "_l" "Continuous" "" "") ;; Purge unused items (3 passes) (repeat 3 (command "_.purge" "all" "*" "n")) ;; Reset UCS, visual style, and view (command "_.ucs" "_world") (command "_.vscurrent" "Conceptual") (command "_.view" "_swiso") (command "_.zoom" "_extents") (princ "\nDrawing processed successfully.") (princ) ) They all looking good besides that, have several more folders to process now but Im thinking there must be quicker way, like you say let the lisp take the strain. I also want o run the audit report occasionally so i can see if any 'non complaint' blocks have appeared. Quote
jamami Posted yesterday at 12:54 PM Author Posted yesterday at 12:54 PM i also noticed that all the dwg icons were inverted when i scripted out all the wblocks ! Quote
SLW210 Posted yesterday at 02:04 PM Posted yesterday at 02:04 PM That drawing already appears to be cleaned up. Quote
jamami Posted yesterday at 03:19 PM Author Posted yesterday at 03:19 PM 2 hours ago, jamami said: This is a typical example drawing, you will see the bogus linetypes and block. I have processed 6 scripts files now on this one folder (500+ drawings each time), and after each time consumung cycles I realise that something else isn't quite perfect... AA0003-3D-LWT.dwg 93.78 kB · 1 download No, it has many linestyles in it that are not needed or puregable, also a block GENAXAH that is not purgeable. I have now script wblocked out the entities and saved a mirror copy, this creates a clean drawing but doesn't solve the issue of extra layers, items on wrong layers, default colors, linetypes , transpancey etc etc etc Quote
jamami Posted yesterday at 03:22 PM Author Posted yesterday at 03:22 PM the layer color isnt correct either as i have now set layer D-3D-CLM to blue (color 5) Quote
SLW210 Posted 22 hours ago Posted 22 hours ago I'll look at it tomorrow at work. Anything else? Quote
BIGAL Posted 20 hours ago Posted 20 hours ago (edited) Have you thought about what if it exists as part of this call "(ensure-layer "D-3D-CLM" 5)", your doing a does not exist but you can do a set color if exists. Look at your "ensure-layer". Example code to put in your defun, same if want to change linetype. (command "-layer" "C" color name "") Edited 20 hours ago by BIGAL Quote
jamami Posted 13 hours ago Author Posted 13 hours ago Thanks for suggestion I had done exactly as suggested but I did it as a script file rather than lisp routine adding lines for linetyp, line weight and transparency . Quote
jamami Posted 10 hours ago Author Posted 10 hours ago in the ensure-layer function below the layer name is referenced as dxf group code 2 (defun ensure-layer (name color) (if (not (tblsearch "LAYER" name)) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 name) ; Layer name (cons 70 0) ; Layer flags (cons 62 color) ; ACI color (cons 6 "Continuous") ; Linetype ) ) ) ) the autocad reference provides 8 as the layer as shown on the attached image. is this because we are assigning a name under entmake rather than reading a name Quote
Lee Mac Posted 10 hours ago Posted 10 hours ago (edited) The DXF data list supplied to entmake in your ensure-layer function is creating a layer table record (or LAYER entity), for which the reference may be found here, whereas DXF group 8 typically contains the layer referenced by another entity. Edited 10 hours ago by Lee Mac Quote
jamami Posted 4 hours ago Author Posted 4 hours ago transparency is not listed in the LAYER symbol table entries, I noted a reference to this in the DXF table as 440 is an earlier table. to enable me to get on i wrote a crude lisp that was basically a script file in disguise, this used layer New command to make sure the layers I wanted existed, if they existed already when New invoked the script didnt bug out , I then set up the layers how I need them leaving layer 0 as the current layer. Script then wblcoked out all entities to a mirror drawing (for some reason this inverted all the icons) this got rid of the acadm non purgeable entities, I then ran another script to open sequentially open all the new mirrored drawings, using SLW210 Clean up routine to purge, set view state etc before saving and closing. Thanks to all the help on this forum , I am starting to get a decent set of clean blocks now.. ;; Set current layer to sol (command "_.layer" "_set" "D-3D-SOL" "") (command "_.layer" "_c" "7" "" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.3" "" "") (command "_.layer" "_l" "Continuous" "" "") ;; Set current layer to clm (command "_.layer" "_set" "D-3D-CLM" "") (command "_.layer" "_c" "5" "" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.18" "" "") (command "_.layer" "_l" "Center" "" "") ;; Set current layer to clg (command "_.layer" "_set" "D-3D-CLG" "") (command "_.layer" "_c" "1" "" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.18" "" "") (command "_.layer" "_l" "Center" "" "") ;; Set current layer to 0 (command "_.layer" "_set" "0" "") (command "_.layer" "_c" "7" "" "") (command "_.layer" "_tr" "0" "" "") (command "_.layer" "_lw" "0.25" "" "") (command "_.layer" "_l" "Continuous" "" "") Quote
SLW210 Posted 3 hours ago Posted 3 hours ago Only one way to clean those Mechanical files. ;;; AutoCAD Mechanical .dwg and export to AutoCAD .dwg to remove Mechanical Layers and Linetypes, etc. ;;; ;;; https://www.cadtutor.net/forum/topic/98263-extracting-block-data-to-a-report/page/3/#findComment-673915 ;;; ;;; By SLW210 (Steve Wilson) ;;; (defun c:M2A () (vl-load-com) ;; Get the current drawing (setq sourceFile (getvar "DWGNAME")) ;; Construct the export file name (setq exportFileName (strcat (vl-filename-directory sourceFile) "" (vl-filename-base sourceFile) "_cleaned.dwg" ) ) ;; Step 1: Set export options (focusing on just file format, bind xrefs, and no prefix/suffix) (command "-EXPORTTOAUTOCAD" "F" "2018" ;; Specify format (e.g., 2018) "B" "Y" ;; Bind Xrefs: Yes "T" "Insert" ;; Bind Type: Insert "M" "Y" ;; Maintain file properties "P" "." ;; Empty prefix (no prefix) "S" "." ;; Empty suffix (no suffix) "" exportFileName ;; Filename for exported file ) (princ "\nDrawing processed successfully.") ) ;; End of function (princ) Quote
SLW210 Posted 3 hours ago Posted 3 hours ago My apologies for not realizing those AM files needed to -EXPORTTOAUTOCAD to completely clean them. I already do Map 3D, Civil 3D, etc. with that routine as well as my own Mechanical files. I could have took care of those right away. If you would be more specific on your needs, the LISP can be adjusted to suit. Are you aware AutoCAD Mechanical has AMSCRIPT? I was working on adding a DCL for Layer entries on the fly for myself, I stopped for now due to my work requirements. I can try to get back on that and gear it more towards what you would want for entries when work allows. Quote
jamami Posted 3 hours ago Author Posted 3 hours ago this works a treat, many thanks. It gets rid of all the acadm linetypes,blocks and dims as a work around i have wblocked out items and this has the same effect of getting rid of the not used items, i am more comfortable with using your routine going forward as I am still unsure what template wblocked entities use. I have a lot more folders to process and building these scripts is invaluable. At present I am opening each file processing it and then save/closing. Is it possible to process files without opening them? Quote
SLW210 Posted 2 hours ago Posted 2 hours ago I posted a link on page one for AutoCAD Core Console Save as M2A.bat and add the paths as indicated (LISP should be in support path AFAIK) (I haven't tested). @echo off setlocal :: Set the AutoCAD Core Console executable path set AutoCADCoreConsole="C:\Program Files\Autodesk\AutoCAD 2023\acadcore.exe" :: Set the path to the folder containing your DWG files set folderPath=C:\Path\To\Your\Drawings :: Set the path to your LISP file set lispFile=C:\Path\To\Your\LISP\M2A.LSP :: Loop through all DWG files in the folder for %%f in (%folderPath%\*.dwg) do ( echo Processing: %%f %AutoCADCoreConsole% /i "%%f" /s "%lispFile%" -r M2A ) :: End of batch script endlocal The aforementioned AMSCRIPT in AutoCAD Mechanical You could add a DCL for file selection to run the LISP ScriptPro, VBA and other languages could do something. Though technically the drawings get opened. Quote
jamami Posted 1 hour ago Author Posted 1 hour ago I will look into AMSCRIPT. We have blocks created in vanilla cad, acadm, fusion and inventor. From these extracted blocks I create 'lightweight' blocks with wall thicknesses, fillets radii removed etc. this is a manual process and takes quite some. this whole exercise is to regularise these blocks for use i building assemblies and for distribution. going forward i will have much stricter rules for preparation of the lightweight blocks to avoid this mess in the future. i have run the checkdrawing audit report you supplied, impressive work, it creates 3 csv files but not all these are populated is hsi correct? Quote
SLW210 Posted 1 hour ago Posted 1 hour ago 20 minutes ago, jamami said: ... i have run the checkdrawing audit report you supplied, impressive work, it creates 3 csv files but not all these are populated is hsi correct? I'll have to check them tomorrow, I haven't checked on it since I first created it and didn't have all of the drawings and criteria, IIRC. Yes, that's possible, if nothing is found some may not be populated. Quote
jamami Posted 57 minutes ago Author Posted 57 minutes ago i am busy educating myself at present using your recent posts as guidance, it is going to take me some time ! this routine is great, after creating the layer sd-3d-sol, d-3d-clg and d-3d-clm can the layer properties be assigned programmatically? or is it a case of using the command function? i am working on the next few folders and have a few more issues, ill cogitate and revert... ;;; Clean drawings to match standards ;;; ;;; https://www.cadtutor.net/forum/topic/98263-extracting-block-data-to-a-report/#findComment-673250 ;;; ;;; SLW210 (a.k.a. Steve Wilson) ;;; ;;; CheckDrawing_1-1.lsp ;;; ;;; Made more robust layer handling and some general clean-up ;| ************************************************************************************************************** | Moves 3D solids to layer `3D` | | Moves centrelines (assumed to be lines with "center" linetype) to `CL` (for red) or `CL_SS` (for color 150)| | Sets all entities’ color, linetype, and lineweight to BYLAYER | | Sets current layer to `0` | | Purges 3x | | Sets UCS to World | | Sets visual style to Conceptual | | Sets view to SW Isometric | | Zooms to Extents | | Ensures layer `0` is empty, and layers `CL`, `CL_SS`, `3D` exist with correct settings | *************************************************************************************************************|; (defun strp (x) (eq (type x) 'STR)) ;; Ensure required layers exist (adjust as needed) (defun ensure-layer (name color) (if (not (tblsearch "LAYER" name)) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 name) ; Layer name (cons 70 0) ; Layer flags (cons 62 color) ; ACI color (cons 6 "Continuous") ; Linetype ) ) ) ) (defun c:CleanDrawing (/ ent lay typ ss i ltype entData) ;; Create layers with specified colors (ensure-layer "D-3D-SOL" 7) ; White (ensure-layer "D-3D-CLG" 1) ; Red (ensure-layer "D-3D-CLM" 5) ; Blue ;; Get all entities (setq ss (ssget "_X")) (if ss (progn (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (setq entData (entget ent)) (setq typ (cdr (assoc 0 entData))) (setq lay (cdr (assoc 8 entData))) (setq ltype (cdr (assoc 6 entData))) ;; Move 3DSOLID to D-3D-SOL (if (and (equal typ "3DSOLID") (/= lay "D-3D-SOL")) (entmod (subst (cons 8 "D-3D-SOL") (assoc 8 entData) entData)) ) ;; Assign CENTER linetypes to D-3D-CLG or D-3D-CLM (if (and ltype (strp ltype)) (cond ((and (wcmatch ltype "CENTER") (= lay "D-3D-CLG")) (entmod (subst (cons 8 "D-3D-CLG") (assoc 8 entData) entData)) ) ((and (wcmatch ltype "CENTER") (= lay "D-3D-CLM")) (entmod (subst (cons 8 "D-3D-CLM") (assoc 8 entData) entData)) ) ) ) ;; Set color, linetype, and lineweight to BYLAYER (if (assoc 62 entData) (entmod (subst (cons 62 256) (assoc 62 entData) entData))) ; Color = BYLAYER (if (assoc 6 entData) (entmod (subst (cons 6 "BYLAYER") (assoc 6 entData) entData))) ; Linetype (if (assoc 370 entData) (entmod (subst (cons 370 -1) (assoc 370 entData) entData))) ; Lineweight = BYLAYER (setq i (1+ i)) ) ) ) ;; Set current layer to 0 (command "_.layer" "_set" "0" "") ;; Purge unused items (3 passes) (repeat 3 (command "_.purge" "all" "*" "n")) ;; Reset UCS, visual style, and view (command "_.ucs" "_world") (command "_.vscurrent" "Conceptual") (command "_.view" "_swiso") (command "_.zoom" "_extents") (princ "\nDrawing processed successfully.") (princ) ) 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.