jamami Posted Saturday at 10:09 PM Author Posted Saturday at 10:09 PM This is brilliant thank you for the response . the. Comments are really helpful and are helping me to follow and understand the code . i have tried adding some code myself and have discovered the syntax is quite unforgiving , numbers of spaces , apostrophes and parentheses being critical . Is there a code checker in the visual lisp editor ?? Quote
SLW210 Posted Sunday at 01:59 PM Posted Sunday at 01:59 PM Yes, also some other IDEs can as well. Notepad++ is popular for AutoCAD LISP. https://notepad-plus-plus.org/ Newer AutoCAD can use Visual Studio Code https://help.autodesk.com/view/OARX/2023/ESP/?guid=GUID-7BE00235-5D40-4789-9E34-D57685E83875 https://www.lee-mac.com/introtovlide.html https://www.lee-mac.com/functioninfo.html https://www.lee-mac.com/debugvlide.html https://www.lee-mac.com/quicklocalising.html https://www.theswamp.org/index.php?topic=44949.msg501762#msg501762 If you want post the problem areas and/or what you are trying to do. Quote
jamami Posted Monday at 12:29 PM Author Posted Monday at 12:29 PM (edited) Hi I have been trying to get the code to run and have come across a few issues. I have tried debugging using the IDE tutorials from L Mac, but cannot resolve this issue. I noticed that there is variable ltype that was not stated in the original defun statement, so i have added to the declaration ( is it compulsory that all variables ae pre declared? many variables may be made up in the process of coding , do I have to keep a track of them all ang go back and add them all to the header? in VB we can use Option Explicit to force declaration and the editor will immediately pick up an report a non declared variable, the lisp IDE doesnt seem to do this?) In the IDE I have asked it to break on error, but it doesnt , I just get an error message:- I have tracked the error to (setq ltype (cdr (assoc 6 (entget ent)))) but in the watch window ltype is always nil? I had added watch expressions Edited yesterday at 11:40 AM by SLW210 Removed Old Code Quote
SLW210 Posted Monday at 03:20 PM Posted Monday at 03:20 PM (edited) I'll try to make this more robust and better error checking. I posted a LINK to Lee Mac's Localizing Variables This fixed that error, it's been a while since I started this project. How did the CheckDrawing.lsp run? I'll try to go through it better later today if I get time. Edited yesterday at 11:41 AM by SLW210 Removed Old Code Quote
jamami Posted Monday at 04:45 PM Author Posted Monday at 04:45 PM I havent run the reporting tools yet. My plan is to complete the initial file cleaning using the CleanDrawings above kindly provided above and learn some lisp while doing so. I changed /= to = on the linetype check, and also added a reference to the ltype variable, but I still cant get the watch window to show ltype as anything other than nil. Even when I hard code set q ltype 1, or "test", the watch window always shows nil. Quote
SLW210 Posted Monday at 05:08 PM Posted Monday at 05:08 PM I redid some layer stuff and other cleaning. I tried to stay AutoLISP, hoping it will run on AutoCAD LT, some engineers here run that, at least 1 knows how to run a LISP. Let me know or ask around if you need more comments. For myself, I may try to do a VLISP version. ;;; Clean drawings to match standards ;;; ;;; https://www.cadtutor.net/forum/topic/98263-extracting-block-data-to-a-report/page/2/#findComment-673661 ;;; ;;; 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
jamami Posted Monday at 05:10 PM Author Posted Monday at 05:10 PM for info i am using acad 2026 Quote
jamami Posted Monday at 05:13 PM Author Posted Monday at 05:13 PM Is this a problem, I am loading this routine into the VLIDE to try and use the debug capabilities, do i need to save as nnn.lsp and load via appload? will this make a difference? i have just installed visual studio as a collegaue suggested this mat be better for lisp? Quote
SLW210 Posted Monday at 05:13 PM Posted Monday at 05:13 PM You should start trying to use Visual Studio Code with the AutoCAD App. I use it some, but IT has some resources blocked here. Quote
SLW210 Posted Monday at 05:16 PM Posted Monday at 05:16 PM I drag and drop into AutoCAD. APPLOAD is fine. Lot's of threads on here for loading LISPs. Quote
jamami Posted Monday at 05:27 PM Author Posted Monday at 05:27 PM I have just tried the CleanDrawing routine and it now works. This brings mixed emotions, great that it works (thank you once again) but I am disappointed that I couldn't bug fix this using the IDE. I had originally assumed that it was because variable ltype had not been localised but don't think this is the case as adding this did not solve the problem. How did you fix this or was it a case of experience spotting ? I get strange issues using the vlide, for one the cursor keeps going into a crude mini cross hair with brackets next to it, at this point the drawing is frozen and so is most of the IDE. I managed to glean a lot from your code and also realised that I need to find a good reference for the DXF codes needed when building and interrogating lists. Quote
SLW210 Posted Monday at 06:27 PM Posted Monday at 06:27 PM Error Message Troubleshooter | Lee Mac Programming I thought I posted this link. My apologies. Tutorials | Lee Mac Programming for references. I usually just search. Autodesk has pretty much abandoned the VLIDE (as well as LISP, VBA), that cursor you see usually means you still have the code running, enter sometimes fixes it as it usually needs to finish the command. I'm not real experienced with complicated LISP, I go back to different websites on LISP, and read when I hit a snag. Usually AfraLISP, Autodesk forums, the Swamp, Lee Mac, Terry Miller's site and CADTutor plus a few more. Quote
jamami Posted Monday at 10:50 PM Author Posted Monday at 10:50 PM Noted. I will definitely read into this some more. You say Autocad have abandoned Lisp ? Quote
BIGAL Posted Monday at 11:42 PM Posted Monday at 11:42 PM "(as well as LISP, VBA)," you would here the screaming from around the world if Autodesk ever stopped lisp support, the opposition programs would jump on that band wagon so fast and not foolow. There is a push to use Visual studio rather than VLIDE for coding. Re VBA @SLW210 if you search here you will find comments like 6 years ago maybe more, Autodesk said VBA would be discontinued, it is still able to be installed but as a separate install, maybe Bill had a chat to Autodesk about dropping VBA, Any hint from Microsoft about Excel not using VBA ? Python is certainly being pushed at the moment, but what happened to Pascal. Any way what about L2c.exe need to go back to 1994 as it would convert lsp code to C# code I still have a copy, But need a real old pc to run it on. The other problem do an upgrade and your C# code has to be redone with new libraries. Real old lisp still works. Quote
SLW210 Posted yesterday at 11:12 AM Posted yesterday at 11:12 AM 11 hours ago, BIGAL said: "(as well as LISP, VBA)," you would here the screaming from around the world if Autodesk ever stopped lisp support, the opposition programs would jump on that band wagon so fast and not foolow. There is a push to use Visual studio rather than VLIDE for coding. Re VBA @SLW210 if you search here you will find comments like 6 years ago maybe more, Autodesk said VBA would be discontinued, it is still able to be installed but as a separate install, maybe Bill had a chat to Autodesk about dropping VBA, Any hint from Microsoft about Excel not using VBA ? Python is certainly being pushed at the moment, but what happened to Pascal. Any way what about L2c.exe need to go back to 1994 as it would convert lsp code to C# code I still have a copy, But need a real old pc to run it on. The other problem do an upgrade and your C# code has to be redone with new libraries. Real old lisp still works. They are no longer making improvements, it's been discussed all over, never said one thing about getting rid of it. Autodesk has shifted its focus away from improving LISP, favoring more modern development environments like .NET. While LISP remains a key customization language for AutoCAD, major enhancements have not been made since the early 2000s, Microsoft has done the same for VBA. Excel (MSOffice) users are the only reason there is any sort of VBA still around, Microsoft did try to kill it, it is also harder to get loaded on AutoCAD now and to top it off now VBScript is not supported in Windows 11, Microsoft is really leaning towards making VBA gone, it too has seen little advancement in decades, it's all the talk on Excel (MSOffice) forums and Reddit, they are pushing higher level coding as well. Office Scripts, which are designed for Excel Online and allow for automation in a cloud-based environment, and various programming languages like Python and JavaScript are becoming the new languages for Microsoft. Besides running through my old LISP projects and helping here, I have been spending my time studying mostly Python (other than AutoCAD uses as well as AutoCAD), C#, Lua and Luau (Lua derivative for Roblox). I may look into TypeScript, supposed to be a better JavaScript replacement. But, I'm getting old and mostly just trying to keep the gray matter regenerating. Last year I spent a whole week in the afternoons rehashing an online coarse for HTML and CSS and never did my website, I may need to run through that again. Still have a complicated LISP I was working on for work, but may start over in Python and update some of the LISP to VLISP. Having only dabbled the edges of VBA for AutoCAD (I used to do more on the Excel side) I my short experience with Python, it does have more upside and IMO as easy as or easier than VBA. P.S. Pascal was dropped by Autodesk a long time ago, in general it was killed off by the C languages, particularly C++. I believe there are still those that use some derivatives AFAIK. Quote
SLW210 Posted yesterday at 11:37 AM Posted yesterday at 11:37 AM 18 hours ago, jamami said: ...How did you fix this or was it a case of experience spotting ?... Sorry, I forgot to reply to that question. Basically the first one was an older try at Layers and Linetypes, I just redid the way I was doing that, I think I forgot to do a make layer if not found in the first try. I think I'll delete the older one. Quote
SLW210 Posted yesterday at 11:47 AM Posted yesterday at 11:47 AM If you could post examples of some really bad drawings with Mechanical Layers, Layers not wanted, etc. and a few correct drawings, I'll try to run some test on both LISPs, if I have time later today. I meant to ask earlier, what determines which centerlines go on which centerline layer CL or CL_SS? Quote
SLW210 Posted yesterday at 11:49 AM Posted yesterday at 11:49 AM Speaking of @BIGAL He has a Multievals.lsp that can add a DCL with some selections for added utilization. Quote
jamami Posted yesterday at 12:19 PM Author Posted yesterday at 12:19 PM I have cleaned all teh files in one folder now suesfully. The bogus linetypes and blocks are still there and I have found that blocking out all elements to a new file with the same name (in a different folder!) gets rid of all the bogus blocks and linetypes. HOWEVER I looked into what template would be used when wblocking out elements and I read it was the template defined in options under QNew, but I am not sur ethsi is correct as the colors, linotypes, lineweights, transparancy etc of the entities in the new block are the same as the prevous and they have not inherited the properties of the template. Quote
SLW210 Posted yesterday at 12:30 PM Posted yesterday at 12:30 PM It would likely be easier with LISP. If you post some difficult drawings me or someone else can just let the LISP do the work. 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.