Standards Check Lisp error help.
So in changing to BricsCad we lost the Standards checking ability autocad has.
so ive attempted to write a lisp that checks if a layer exists in a text file.
ive managed to get this to work and have been asked to add a feature of purging any empty non standard layers
so now if there are in fact any non standard empty layers the following error comes up
; error : Automation Error 80020009; [IAcadLayers] Error accessing [ITEM] method. ErrIndex=0;
but if i re run the code a second time no errors appear and it works perfectly.
id prefer to not have to run the code twice every time i need it.
can someone see the error. or is there a way to program into the code to make it run twice.
Thanks for any help
Here is the code
(defun c:SD()
;read list from file
(setq f (open "X:\\_BricsCAD\\Standards\\PCB_layerlist.txt" "r"))
(setq count 0)
(while (/= (setq text (read-line f)) nil)
(setq layerlist
(cond
(
(= 0 count)
(cons (cons 8 text) layerlist)
)
(
(append layerlist (list (cons 8 text)))
)
)
)
(setq count (+ count 1))
)
(close f)
(setq f (open (strcat "C:\\layerstandardstest.txt") "w"))
(write-line "The Following layers do not meet standard:" f)
(write-line " " f)
(setq layerspresent (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(setq i 0)
(repeat (vla-get-count layerspresent)
(setq thislayer (vla-get-name (vla-item layerspresent i)))
(setq templist (cons 8 thislayer))
(if ; not in any of the layer lists?
(= ;'testexpr'
(length
(vl-remove
nil ; remove any nil results from list returned by (mapcar)
(mapcar ; apply member check of layer name across all lists, return list of results
'(lambda (x) (member templist x)); applied to all in following list
(list layerlist)
); mapcar
); vl-remove
); length
0 ; all nils removed from list of results, so it's empty [returned nil for all lists]
); =
(progn ; 'thenexpr'
(command "_.purge" "Layers" thislayer "No");purge layer
(if (tblsearch "layer" thislayer);check if layer still exists after purge.
(write-line thislayer f);if layer still exists write to file
();if layer no longer exists do nothing
)
)
() ; else nothing
)
(setq i (1+ i))
); repeat
(print "Standards check complete see text file for errors C:\layerstandardstest")
(close f)
(startapp "explorer" (strcat "C:\\layerstandardstest.txt"))
)
0
Comments
-
Duncan,
The layer may be empty, but is being referenced by another object, such as a block. Works the second time round as the referencing object was likely purged.
I guess you could try working the other way around. Repeatedly call purge until nothing to purge is found, then check standards etc..
Regards,Jason Bourhill
0
This discussion has been closed.