jamami Posted June 12 Posted June 12 I have large number of blocks that have been developed over the years and I want to regularlise them. Each block should consist of only 3D solids(on layer 3D) and centrelines (structural(on layer CL_S) and reference(on layer CL)) There should be no blocks or layouts (other than Layout 1) within the file. At the moment am looking at each block in turn in design centre to see if the above is true and editing where necessary. with over 1200 blocks to get through this is going to take a lot of time. In the first instance I would like to produce a report scheduling data for each dwg:- dwg name name contains block y/n y/n existing layer names layer 1 layer2 etc this way I can identify and focus on the blocks that do not accord with the standard. Question is, using lisp, is it possible to produce a conjoined report by cycling through all the dwgs in a folder, extract and format required data then adding this to a csv/txt file or Mtext? or will this data extract be limited to a single open file only with no possibility of producing an overall report? Quote
BIGAL Posted June 12 Posted June 12 1 Can get a list of dwg names 2 Can use OBDX to look inside a dwg 3 Can check does it have blocks in say model space. 4 Can get used layers 5 Write to somewhere the result Not sure about looking in layouts When you say checking the blocks what do you mean ? I am working on something else at moment that does similar. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/program-to-pull-attribute-data-from-a-title-block-to-create-a/td-p/13656260 that code will not do what you want. Some one may have some time to have a go, I have a bit on at moment. Quote
jamami Posted June 13 Author Posted June 13 i want a report to show if there are blocks within the file, but have found a work around. i have found an excellent explodeall routine on this forum so i am write a script file to systematically open each drawing, run the explodeall lisp and then purge, save, close. the report i need then would be what layers are in the drawing and how many objects and object type on that layer (ie layer cl, 3 x 3d solids, 4x lines) this way i can identify what drawings don't meet the standard i want to impose, which is all solids on layer 3d all centrelines on layer cl or cl_s all objects color bylayer, linetype by layer, lineweight by layer i have a custom command that allows me to select a point n the block and then moves all to 0,0,0 and sets current layer 0 purges 3x ucs w vscurrent conceptual view swiso zoom extents this way i have a consistent block library and file icons my issue is with all the legacy blocks, i can script the above on all of them but finding out what layers exist and what objects exist is a different kettle of fish Quote
SLW210 Posted June 13 Posted June 13 Do you have an example drawing or two for testing? I would prefer the ones not exploded, I started with your original post before mentioning exploding everything. Actually, go ahead and post examples of exploded and not-exploded. Quote
jamami Posted June 13 Author Posted June 13 AA0002-3D-LWT.dwgAF0001-3D-LWT.dwgAA0006-3D-LWT.dwgAA0005-3D-LWT.dwg Quote
jamami Posted June 13 Author Posted June 13 Hi I am planning to write a script file that opens up each file in turn and explodes any blocks, purges and then resaves, so the block within drawing should not be an issue when complete. (I found a lisp called c:explodeall by L Mac that works really well) The issue I do have is making sure all the layers are correct. I only want 0, 3D, CL and CL_SS. Some of these blocks I did in acad mechanical and these have acad mechanical layer names for the centrelines and I am trying to locate all of these to manually rename, that's why a report would be handy so I can spot them in the long list. Some of the blocks have a defpoints layer that i do not want or need and I cannot seem to purge this out even though it isnt used. Layer 0 should be empty Layer 3D should contain 3D solids Layer CL is red and contains reference centrelines Layer CL_SS is color 150 and contains the primary item centreline (extracted and used to build 3D Models for structural analyses) I am currently trying to work out how to use qselect in a script file to select all 3d solids and move to layer 3D, select all red lines and move to CL and select all blue lines and move to layer CL_SS, rename layer AM_7 to CL_SS AA0005-3D-LWT.dwg AA0006-3D-LWT.dwg AF0001-3D-LWT.dwg AA0002-3D-LWT.dwg AA0005-3D-LWT.dwg AA0006-3D-LWT.dwg AF0001-3D-LWT.dwg AA0002-3D-LWT.dwg Quote
jamami Posted June 13 Author Posted June 13 apologies it looks like the files have been loaded multiple times. Quote
SLW210 Posted June 13 Posted June 13 It's usually bad form to explode an entire drawing, though sometimes it's just fine, I think I can do it either way. You may be able to do it all with one LISP. After you posted the explode method, I looked at adding the explode any blocks to the LISP. I'll try to get something this weekend or early next week, at least something basic, though my weekend looks real busy. Based on a LISP I am making for myself, here is what I am working towards, let me know what else you need or anything here unnecessary... | File | Description | | -------------------------- | -------------------------------------------- | | `layer_audit_report.csv` | Full audit of all entities | | `violations_report.csv` | Line-by-line of noncompliant drawings | | `compliance_summary.csv` | One row per DWG, total violations, PASS/FAIL | | Explode blocks | ✔ | | Audit all layers and linetypes | ✔ | | Flag color/linetype/lineweight issues | ✔ | | Flag incorrect layer use | ✔ | | Write full and filtered reports | ✔ | | Export only non-compliant entities | ✔ | | Highlight errors in red | ✔ | | Count and log violation types | ✔ | | Pass/Fail per DWG | ✔ | It would help if you could post an example CSV header, so I know what to populate. From you previous posts I came up with this... DWG Name,Layer,Entity Type,Count,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantLayer MyDrawing1.dwg,3D,AcDb3dSolid,15,Y,Y,Y,Y MyDrawing2.dwg,CL,AcDbLine,8,Y,Y,Y,Y MyDrawing3.dwg,Layer1,AcDb3dSolid,2,N,Y,Y,N MyDrawing4.dwg,0,AcDbLine,1,N,N,Y,N Or something simpler... DWG Name,Only On Allowed Layers,Layers MyDrawing1.dwg,N,"3D;CL;Layer1;" MyDrawing2.dwg,Y,"3D;CL;CL_S;" Violations CSV is just a list of non-compliant drawings Non_Compliant Drawings MyDrawing2.dwg MyDrawing5.dwg My compliance CSV looks like... DWG Name,ColorErr,LtypeErr,LweightErr,LayerErr,TotalViolations,Status Test1.dwg,0,0,0,0,0,PASS Test2.dwg,1,0,0,2,3,FAIL Quote
jamami Posted June 13 Author Posted June 13 while explode (setq explode nil) (vlax-for layout layouts (vlax-for obj (vla-get-block layout) (and (= "AcDbBlockReference" (vla-get-objectname obj)) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list obj)))) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list obj)))) (setq explode t) ) ) ) ) From what I can tell as a newbie to the above from L Mac only explodes blocks within the drawing, not the whole drawing ie the 3D solids are not exploded to surfaces Quote
jamami Posted June 13 Author Posted June 13 DWG Name,Layer,Entity Type,Count,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantLayer MyDrawing1.dwg,3D,AcDb3dSolid,15,Y,Y,Y,Y MyDrawing2.dwg,CL,AcDbLine,8,Y,Y,Y,Y MyDrawing3.dwg,Layer1,AcDb3dSolid,2,N,Y,Y,N MyDrawing4.dwg,0,AcDbLine,1,N,N,Y,N this is very cool, BUT Drawing1...4 etc will have several layers and also nuisance blocks like GENAX and nuisance layers like defpoints that i cant get rid of. only way i am finding to do this is to cut/past dwg entities to a new fresh template Quote
SLW210 Posted June 13 Posted June 13 2 hours ago, jamami said: Some of the blocks have a defpoints layer that i do not want or need and I cannot seem to purge this out even though it isnt used. Layer 0 should be empty Layer 3D should contain 3D solids Layer CL is red and contains reference centrelines Layer CL_SS is color 150 and contains the primary item centreline (extracted and used to build 3D Models for structural analyses) I am currently trying to work out how to use qselect in a script file to select all 3d solids and move to layer 3D, select all red lines and move to CL and select all blue lines and move to layer CL_SS, rename layer AM_7 to CL_SS You might look at Son of a Batch! AutoCAD Core Console Through Lisp | House of BIM. If defpoints doesn't purge, it is being used by something. From the sound of your post, you really do not need a report, just a LISP to run on all of the drawings to do the designated steps. Quote this is very cool, BUT Drawing1...4 etc will have several layers and also nuisance blocks like GENAX and nuisance layers like defpoints that i cant get rid of. That's why I need your preferred CSV layout. Quote
jamami Posted June 13 Author Posted June 13 the plot thickens with this as i start working through. in some of the files there are a bunch of linetypes that cannot be purged, incorrect linetypes assigned, GENAXAH blocks that cannot be purged, layers that cannot be purged etc This is all to do with some blocks being prepared in Mechanical. To reach my utopia of only 2 linestyles, continuous and center, no embedded or hidden blocks, with only the minimum number of layers I have found the only way is to open a new template and cut paste the visible entitles from dwg1 to the template, close dwg1 and then clean up the new drawing and save as dwg1, I have managed to do around 30 blocks so far but have many many more to go. i was hoping to create a script with all 850+ dwgs like this:- open dwg1 copybase 0,0,0 all close n new paste 0,0,0 save dwg1 but as soon as the file is closed, or the new one is opened the script stops. is it possible to have a a lisp in the new template that runs a paste command on start up? all i then need to figure out is how to pass the save time to teh new instance.... Quote
jamami Posted June 13 Author Posted June 13 Just now, jamami said: the plot thickens with this as i start working through. in some of the files there are a bunch of linetypes that cannot be purged, incorrect linetypes assigned, GENAXAH blocks that cannot be purged, layers that cannot be purged etc This is all to do with some blocks being prepared in Mechanical. To reach my utopia of only 2 linestyles, continuous and center, no embedded or hidden blocks, with only the minimum number of layers I have found the only way is to open a new template and cut paste the visible entitles from dwg1 to the template, close dwg1 and then clean up the new drawing and save as dwg1, I have managed to do around 30 blocks so far but have many many more to go. i was hoping to create a script with all 850+ dwgs like this:- open dwg1 copybase 0,0,0 all close n new paste 0,0,0 save dwg1 but as soon as the file is closed, or the new one is opened the script stops. is it possible to have a a lisp in the new template that runs a paste command on start up? all i then need to figure out is how to pass the save time to teh new instance.... 'save name' not time Quote
SLW210 Posted June 13 Posted June 13 Post one of the drawings with the Mechanical Layers. You should still proceed with the LISP to create a report after fixing all of the drawings it can. The drawing you posted AA0005-3D-LWT.dwg with the defpoints layer, had 3 lines on that layer. 3 item(s) selected. Command: _.erase 3 found Command: -pu -PURGE Enter type of unused objects to purge [Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/All]: a Enter name(s) to purge <*>: Verify each name to be purged? [Yes/No] <Y>: n No unreferenced blocks found. Deleting layer "Defpoints". 1 layer deleted. Quote
jamami Posted June 13 Author Posted June 13 here is a typical example (there are many like this) acadm lines will not purge out nor will the genaxah block I have just run a script to rename the 3 layers, 3d, cl, cl_ss to d-3d-clg, d-3d-clm & d-3d-sol In doing so I have also notice that sometimes the cl_ss layer is blue (150) other times blue(152 and other times blue(160)....no consistency cutting and pasting into a new template solves the issues but is really clunky and time consuming, unless of course this can be automated to process all the files in the folder. a report would be great so i could see the totality of all this BC1000-3D-LWT.dwg Quote
jamami Posted June 13 Author Posted June 13 dwg name1,Entity1,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity dwg name1,Entity2,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity dwg name1,Entity3,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity dwg name1,Entity4,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity .......... dwg name2,Entity1,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity dwg name2,Entity2,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity dwg name2,Entity3,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity dwg name2,Entity4,layer,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantEntity .......... OUTPUT LIKE:- BC1000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y BC1000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y BC1000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y BC1000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y BC1000-3D-LWT,SOLID, 0,Y,Y,Y,N ;;(Because solids should not be on layer 0) BC1000-3D-LWT,LINE, D-3D-CLM,Y,Y,Y,Y BC1000-3D-LWT,LINE, D-3D-CLM,Y,Y,Y,Y BC1000-3D-LWT,LINE, D-3D-CLG,Y,Y,Y,Y BC1000-3D-LWT,CIRCLE, D-3D-CLG,Y,Y,Y,Y BC1000-3D-LWT,BLOCK, ACADMLAYER,Y,Y,Y,N ;;(Becuase I dont want any blocks within the model) BC2000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y BC2000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y BC2000-3D-LWT,SOLID, D-3D-SOL,Y,Y,Y,Y ...... ..... Im thinking a report by entity is the way forward, this way i can look at where it resides and its compliance status. Ultimately I need to move all solids to layer D-3D-SOL, all red lines to D-3D-GLG and all blue lines to D-3D-CLM, all bylayer, bylayer, bylayer with D-3D-SOL continuous, D-3D-CLG &CLM center, all based on the acad_iso template and linetype definitions. The object rotation and base point will need to be assigned manually as I need to look at each item in turn and decide a logical insertion point with knowledge of what parts it fits together with. I have written a custom command that allows me to pick a point and the object aligns, sets base point, sets view, sets visual style and saves so this, although laborious, needs to be the final deed after cleaning up the blocks. Quote
jamami Posted June 14 Author Posted June 14 A downside of the report above is it will not show if their are random non purgeable linetypes in the drawing. But will have limited auditing application if it isnt picking this up as well. The more I process these files I am convinced that (as suggested earier) a lisp routine would be best to process all. Thoughts on steps needed. open dwg1 use explodeall routine above to make sure no blocks/nested blocks exist open clean template 'mytemplate.dwt' Copy all solids from dwg1 to layer D-3D-SOL on clean template using common copy and paste points Copy all red lines(various shades) and lines from layer D-3D-CLG from dwg1 to D-3D-CLG on clean template using common copy and paste points Copy all blue lines(various shades) and lines from layer D-3D-CLM from dwg1 to D-3D-CLM on clean template using common copy and paste points Close dwg1 not saving any changes Save mytemplate.dwt as dwg1 repeat 10^3 times Ive tried doing the above with a script but it trips over when opening new file, so having to do manually one by one at mo. I have written custom commands to help process these blocks and have pasted these onto a tool pallete from the cui. I cannot get these custom commends to run within my scripts and I realise that they cannot be invoked from the command line. I have tried adding it into the pgp file but no luck...its looking more and more likely that lisp or manual processing 1 by 1 is the only way forward. Quote
jamami Posted June 14 Author Posted June 14 A downside of the report above is it will not show if their are random non purgeable linetypes in the drawing. But will have limited auditing application if it isnt picking this up as well. The more I process these files I am convinced that (as suggested earier) a lisp routine would be best to process all. Thoughts on steps needed. open dwg1 use explodeall routine above to make sure no blocks/nested blocks exist open clean template 'mytemplate.dwt' Copy all solids from dwg1 to layer D-3D-SOL on clean template using common copy and paste points Copy all red lines(various shades) and lines from layer D-3D-CLG from dwg1 to D-3D-CLG on clean template using common copy and paste points Copy all blue lines(various shades) and lines from layer D-3D-CLM from dwg1 to D-3D-CLM on clean template using common copy and paste points Close dwg1 not saving any changes Save mytemplate.dwt as dwg1 repeat 10^3 times Ive tried doing the above with a script but it trips over when opening new file, so having to do manually one by one at mo. I have written custom commands to help process these blocks and have pasted these onto a tool pallete from the cui. I cannot get these custom commends to run within my scripts and I realise that they cannot be invoked from the command line. I have tried adding it into the pgp file but no luck...its looking more and more likely that lisp or manual processing 1 by 1 is the only way forward. Quote
jamami Posted June 14 Author Posted June 14 have found a link to this https://lee-mac.com/copytodrawing.html but this requires manually picking data in the source drawing and manually selecting the destination... Quote
SLW210 Posted June 14 Posted June 14 (edited) To do any more I need to be at work, probably Monday USA Eastern Time. What I got so far-- before your latest posts... Untested, but I checked them in VLIDE + similar for myself worked, basically I added check for solids, etc.. ;;; Check 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.lsp ;;; ;| ****************************************** |Actions Taken | |Explode blocks | | Audit all layers and types | | Flag color/linetype/lineweight issues | | Flag incorrect layer use | | Write full and filtered reports | | Export only non-compliant entities | | Highlight errors in red | | Auto-open violations DWG | | Count and log violation types | | Pass/Fail per DWG | ****************************************** ------------------------------------------ *************************************************************************| |Make sure this structure exists, if changing adjust code as commented. | | | | C:\DWG_Reports\ | |+-- AuditDrawing.lsp | |+-- run_audit.scr | |+-- DWGs\ <-- Put your DWGs here | |+-- Violations\ <-- This will hold extracted error drawings | |+-- layer_audit_report.csv | |+-- violations_report.csv | *************************************************************************|; (defun c:CheckDrawing (/ doc ms laytbl file file2 file3 dwgname ent layname enttype col ltyp lw cnt layerdata blk entlist compliant newdoc errfile acadApp colorErr ltypeErr lwErr layerErr totalErr passFail violation-found ) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq ms (vla-get-ModelSpace doc)) (setq laytbl (vla-get-Layers doc)) (setq dwgname (getvar "DWGNAME")) (setq csv-full "C:/DWG_Reports/layer_audit_report.csv") ; Change path if you aren't using the default (setq csv-viol "C:/DWG_Reports/violations_report.csv") ; Change path if you aren't using the default (setq csv-sum "C:/DWG_Reports/compliance_summary.csv") ; Change path if you aren't using the default ;; Create directories if needed (vl-mkdir "C:/DWG_Reports") ; Change path if you aren't using the default (vl-mkdir "C:/DWG_Reports/Violations"); Change path if you aren't using the default ;; Open report files (setq file (open csv-full "a")) (setq file2 (open csv-viol "a")) (setq file3 (open csv-sum "a")) ;; Headers (if (= (vl-file-size csv-full) 0) (write-line "DWG Name,Layer,Entity Types,Count,ColorByLayer,LtypeByLayer,LweightByLayer,CompliantLayer" file ) ) ; Adjust headers for layer audit report if desired (if (= (vl-file-size csv-viol) 0) (write-line "DWG Name,Layer,Entity Types,Handle,Color,Ltype,Lweight,CompliantLayer" file2 ) ) ; Adjust headers for violations report if desired (if (= (vl-file-size csv-sum) 0) (write-line "DWG Name,ColorErr,LtypeErr,LweightErr,LayerErr,TotalViolations,Status" file3 ) ) ; Adjust headers for summary report if desired ;; Explode top-level blocks in modelspace (vlax-for ent ms (if (= (vla-get-ObjectName ent) "AcDbBlockReference") (progn (vl-catch-all-apply 'vla-Explode (list ent)) (vla-delete ent) ) ) ) ;; Counters (setq colorErr 0 ltypeErr 0 lwErr 0 layerErr 0 totalErr 0 ) (setq violation-found nil) (setq layerdata '()) ;; Create new DWG with _ERRORS added on to end of file name for violations (comment out if not needed) (setq acadApp (vlax-get-acad-object)) (setq newdoc (vla-Add (vla-get-Documents acadApp))) (setq errfile (strcat "C:/DWG_Reports/Violations/" (vl-filename-base dwgname) "_ERRORS.dwg" ) ) ; Change path if you aren't using the default ;; Helpers (defun is-by (val types) (cond ((= types "color") (= val 256)) ((= types "ltype") (= (strcase val) "BYLAYER")) ((= types "lw") (= val acLnWtByLayer)) ) ) ;; Process (vlax-for ent ms (setq layname (vla-get-Layer ent)) (setq enttype (vla-get-ObjectName ent)) (setq col (vla-get-Color ent)) (setq ltyp (vla-get-Linetype ent)) (setq lw (vla-get-Lineweight ent)) (setq handle (vla-get-Handle ent)) (setq compliant t) ;; Check BYLAYER (if (not (is-by col "color")) (setq colorErr (1+ colorErr) compliant nil ) ) (if (not (is-by ltyp "ltype")) (setq ltypeErr (1+ ltypeErr) compliant nil ) ) (if (not (is-by lw "lw")) (setq lwErr (1+ lwErr) compliant nil ) ) ;; Check for correct layer usage (if (or (and (= enttype "AcDb3dSolid") (not (= (strcase layname) "3D")) ) (and (member enttype '("AcDbLine" "AcDbPolyline")) (not (member (strcase layname) '("CL" "CL_S"))) ) ) (setq layerErr (1+ layerErr) compliant nil ) ) ;; Count and store layer data (setq key (list layname enttype)) (setq entry (assoc key layerdata)) (if entry (setq layerdata (subst (list key (1+ (cadr entry)) compliant) entry layerdata ) ) (setq layerdata (cons (list key 1 compliant) layerdata)) ) ;; Handle violations (if (not compliant) (progn (setq violation-found t) (setq totalErr (1+ totalErr)) (write-line (strcat dwgname "," layname "," enttype "," handle "," (itoa col) "," ltyp "," (vl-princ-to-string lw) ",N" ) file2 ) ;; Clone and mark red (setq newent (vla-copy ent)) (vla-put-Color newent 1) ; red (vla-move newent (vlax-3d-point '(0 0 0)) (vlax-3d-point '(0 0 0)) ) (vla-AppendCopy (vla-get-ModelSpace newdoc) newent) ) ) ) ;; Write full audit data (foreach item layerdata (setq key (car item)) (setq lay (car key)) (setq typ (cadr key)) (setq cnt (cadr item)) (setq comp (if (caddr item) "Y" "N" ) ) (write-line (strcat dwgname "," lay "," typ "," (itoa cnt) ",Y,Y,Y," comp ) file ) ) ;; Write summary (setq passFail (if (> totalErr 0) "FAIL" "PASS" ) ) (write-line (strcat dwgname "," (itoa colorErr) "," (itoa ltypeErr) "," (itoa lwErr) "," (itoa layerErr) "," (itoa totalErr) "," passFail ) file3 ) ;; Save violations DWG if needed (if violation-found (progn (vla-saveas newdoc errfile) (vla-Activate acadApp) (vla-Activate newdoc) ) (vla-close newdoc) ) (close file) (close file2) (close file3) (princ "\nFull audit, summary, and violations export complete." ) (princ) ) This should be a start on cleaning the files. See Latest Code This would be the scripts to run these... adjust the file paths as needed if you change the setup. ; CheckDrawing.scr (load "C:/DWG_Reports/CheckDrawing.lsp") CheckDrawing QSAVE QUIT ; CleanDrawing.scr (load "C:/DWG_Reports/CleanDrawing.lsp") CleanDrawing QSAVE QUIT Everything else will have to wait until Monday. Edited June 17 by SLW210 Removed Old Code 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.