Leaderboard
Popular Content
Showing content with the highest reputation since 07/19/2026 in all areas
-
a little story : This is the famous Myth of Thamus and Theuth, found in the dialogue Phaedrus by the Greek philosopher Plato (written around 370 BCE). In this text, Plato has his teacher Socrates relate an ancient Egyptian anecdote. Here is how the story unfolds: The Invention The Egyptian god Theuth (Thoth), the deity of inventions, visits Thamus, the king (pharaoh) of Egypt. Theuth presents his various creations, including arithmetic, geometry, and astronomy. Finally, he introduces the written word. Theuth is enthusiastic and claims: "This invention will make the Egyptians wiser and improve their memories. It is a potion for both memory and wisdom!" The Pharaoh's Objection King Thamus is not impressed and responds with deep skepticism. He argues that writing will have the exact opposite effect: Memory loss: People will stop training their memories. By relying on external written characters, they will no longer internalize knowledge. The illusion of wisdom: People will read quantities of information without proper instruction. As a result, they will appear knowledgeable but will actually remain ignorant, becoming conceited and difficult to get along with. The Historical Irony Socrates used this story to argue that spoken dialogue is superior to the written word. He believed text is dead; it cannot answer back or clarify itself when misunderstood. The ultimate irony is that Socrates himself never wrote anything down. The only reason we know this story today is because his student, Plato, wrote it down. This ancient debate resurfaces with every technological leap. The same anxieties were voiced about the printing press, calculators, the internet, and now, Artificial Intelligence (AI).6 points
-
Hello. I'm happy to share this routine I created with the help of Copilot, which I believe works acceptably for distributing elements (sprinklers, detectors, etc.) based on user input. I would be very grateful if any member of this forum could improve the code or offer any advice. I'm a big fan of @Lee Mac's programs, whom I consider a master. The routine will ask the user to define the measurements that define minimum and maximum values and then, by selecting a block, from which it acquires the layer and scale properties, by selecting an area, with or without "islands", it will generate a mesh pattern, which for a preliminary design is acceptable or approximate in many cases. I am Spanish and the routine is coded in Castilian Spanish (Spain). PCI_PRO (PFP).lsp5 points
-
AI , I like to call it Clippy , is here to stay but you are the architect , in the driver seat. Don't blame Clippy if something goes wrong, blame yourself when blindly believing everything it says. It's just a tool but you are responsible at all times. Like guns don't kill people , its people that kill people. Clippy is very good in finding facts and patterns , but it has no real understanding. When coding something big, give total control to Clippy and for sure you end up with lots of code you don't understand nor control anymore. Just do what you always do, create a block or flow diagram and feed it little bits and test everything. Like this weekend , have a portable airco for my sweat-room. Missed (misplaced) a part so I told Clippy and behold, oh you need this and there you find it, So ordered the part (and a day later I found it in a drawer) , but then Clippy said , oh you have simple (dum) airco , would you like to be able to control it with your phone?... sure, what's on your mind?... it gave me 3 options and I went for gold (of course). Paranoid dragon as I am , did some research (after I placed the order) on how IR boosters work and downloaded the manual and found out the IR booster I just ordered only works when airco has a remote with a display and mine only has buttons. So fortunately was able to cancel the order and found another , much cheaper and works with my machine. Now I can only blame myself, not Clippy. It means well , but it can't be trusted blindly. The better the info you feed it , the better result you can get back. At this moment the term AI is found everywhere , many times as a marketing slogan, designed by AI , controlled by AI , AI knows everything... well I can say for certain there is only one person on this whole planet who knows everything and I'm married to her. ok time to for me.5 points
-
This particular issue has been in play for a long time. Have you ever gone to a food joint, the power is out, and the staff refuse to prepare food for you because they can't ring it up? Like they've never heard of pencil and paper or making change. If you can't do the basic, human version of your job, you'll be left in the dark (sometimes literally) when the AI can't do its job. Worse, you won't recognize when the AI is making a mistake. Without a real-world backup, and the sense to use it, you're at the mercy of the AI and its hallucinations. It's the height of irresponsibility to replace us with something that needs its hand held all the time in case it has a malfunction.5 points
-
Hi everyone, I'm Vico, an architectural designer with about 12 years in the industry. I'm based in China and have mostly been active in local developer forums, but I've always respected the open-source spirit here. I wanted to share a quick tool I wrote and also get your feedback on an idea. Codebase Packer — a LISP for AI-assisted work Over the past months I've been building a web-based side-project for CAD. The frontend work forced me to lean heavily on AI assistants (Claude, ChatGPT). The biggest bottleneck was always the context window: opening and pasting 30+ files manually drove me crazy. So I solved it with a little LISP routine. Codebase Packer lets you point at a folder and aggregate every file inside into a single .txt, ready for an LLM prompt. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Command CPK (Codebase Packer) - Version 1.0 Release ;;; ;;; ;;; ;;; Features: ;;; ;;; Efficiently extracts the directory structure and file contents ;;; ;;; of a project. Features smart character encoding detection and ;;; ;;; automatically saves the packed file as UTF-8 alongside the ;;; ;;; project folder for AI-friendly integration. ;;; ;;; ;;; ;;; Author: Vico Wang ;;; ;;; Compatibility: AutoCAD 2006+ (Visual LISP / ActiveX) ;;; ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (vl-load-com) (defun cpk:getdate ( / cd ) (setq cd (rtos (getvar 'cdate) 2 6)) (strcat (substr cd 1 4) (substr cd 5 2) (substr cd 7 2)) ) (defun cpk:read ( fn / ext charset stm text err ) (setq ext (strcase (vl-filename-extension fn) t) charset (if (member ext '(".lsp" ".dcl" ".mnl" ".bat" ".ini")) "GBK" "UTF-8") text "" ) (if (setq stm (vlax-create-object "adodb.stream")) (progn (setq err (vl-catch-all-apply '(lambda () (vlax-put-property stm 'type 2) (vlax-put-property stm 'mode 3) (vlax-put-property stm 'charset charset) (vlax-invoke stm 'open) (vlax-invoke stm 'loadfromfile fn) (if (> (vlax-get-property stm 'size) 0) (setq text (vlax-invoke stm 'readtext -1)) ) ) ) ) (if (= 'vla-object (type stm)) (progn (vl-catch-all-apply '(lambda () (vlax-invoke stm 'close))) (vlax-release-object stm) ) ) (if (vl-catch-all-error-p err) (strcat "// Note: Error reading file - " (vl-catch-all-error-message err)) (if (= "" text) "// Note: File is empty or extraction failed" text) ) ) "// Note: ADODB.Stream component missing" ) ) (defun cpk:traverse ( fso dir prefix islast root / fobj subdirs files items i cnt name rel ) (if (setq fobj (vl-catch-all-apply 'vlax-invoke (list fso 'getfolder dir))) (if (not (vl-catch-all-error-p fobj)) (progn (if (/= (strcase dir) (strcase root)) (setq name (vlax-get fobj 'name) rel (vl-string-translate "\\" "/" (substr dir (+ 2 (strlen root)))) out-tree (cons (strcat prefix (if islast "©¸©¤©¤ " "©À©¤©¤ ") name "/ # " rel) out-tree) ) ) (setq items nil) (vlax-for x (vlax-get fobj 'subfolders) (setq items (cons (cons x t) items))) (vlax-for x (vlax-get fobj 'files) (setq items (cons (cons x nil) items))) (setq items (reverse items) cnt (length items) i 0 ) (setq prefix (if (= (strcase dir) (strcase root)) "" (strcat prefix (if islast " " "©¦ ")))) (foreach item items (setq i (1+ i) name (vlax-get (car item) 'name) ) (if (cdr item) (cpk:traverse fso (vlax-get (car item) 'path) prefix (= i cnt) root) (progn (setq rel (vl-string-translate "\\" "/" (substr (vlax-get (car item) 'path) (+ 2 (strlen root))))) (setq out-tree (cons (strcat prefix (if (= i cnt) "©¸©¤©¤ " "©À©¤©¤ ") name " # maps to /" rel) out-tree)) (setq out-files (cons (list (vlax-get (car item) 'path) name rel) out-files)) ) ) ) (vlax-release-object fobj) ) ) ) ) (defun c:cpk ( / *error* old-cmd out-tree out-files fso shl fld root-dir root-name lst fn rel sv-dir sv-path stm cnt err ) (defun *error* ( msg ) (foreach obj (list fso shl fld stm) (if (and obj (= 'vla-object (type obj)) (not (vlax-object-released-p obj))) (vl-catch-all-apply 'vlax-release-object (list obj)) ) ) (if old-cmd (setvar 'cmdecho old-cmd)) (if (and msg (not (wcmatch (strcase msg t) "*break*,*cancel*,*exit*"))) (princ (strcat "\nCPK Error: " msg)) ) (princ) ) (setq old-cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) (princ "\nSelect root folder to pack...") (if (setq shl (vlax-create-object "shell.application")) (progn (if (setq fld (vlax-invoke shl 'browseforfolder 0 "Select project root folder (Codebase Packer)" 0 0)) (setq root-dir (vlax-get (vlax-get fld 'self) 'path)) ) (vlax-release-object shl) ) ) (if root-dir (progn (setq fso (vlax-create-object "scripting.filesystemobject") root-name (vlax-get (vlax-invoke fso 'getfolder root-dir) 'name) out-tree (list (strcat root-name "/ # [Root Directory] " root-dir) "") ) ;; Automatically uses out-tree and out-files via LISP dynamic scoping (cpk:traverse fso root-dir "" t root-dir) (setq lst (list "Part A: Overall Folder and File Structure\n")) (foreach x (reverse out-tree) (setq lst (cons (strcat x "\n") lst)) ) (setq lst (cons "\n\nPart B: Specific File Contents\n" lst) out-files (reverse out-files) cnt (length out-files) ) (foreach x out-files (setq fn (car x) rel (caddr x) ) (setq lst (cons (strcat "\n------------------------------------------------------------\n" "File location: " rel "\n" "File name: " (cadr x) "\n" "------------------------------------------------------------\n\n" (cpk:read fn) "\n") lst) ) ) (setq lst (reverse lst)) (setq sv-dir (vl-catch-all-apply 'vlax-invoke (list fso 'getparentfoldername root-dir))) (if (or (vl-catch-all-error-p sv-dir) (= "" sv-dir)) (setq sv-dir root-dir) ) (if (/= "\\" (substr sv-dir (strlen sv-dir))) (setq sv-dir (strcat sv-dir "\\")) ) (if (setq sv-path (getfiled "Save Packed File" (strcat sv-dir root-name "-Packed-" (cpk:getdate) ".txt") "txt" 1)) (if (setq stm (vlax-create-object "adodb.stream")) (progn (setq err (vl-catch-all-apply '(lambda () (vlax-put-property stm 'type 2) (vlax-put-property stm 'mode 3) (vlax-put-property stm 'charset "utf-8") (vlax-invoke stm 'open) (foreach x lst (vlax-invoke stm 'writetext x)) (vlax-invoke stm 'savetofile sv-path 2) (vlax-invoke stm 'close) ) ) ) (vlax-release-object stm) (if (vl-catch-all-error-p err) (alert "\nUnable to write file. Please check permissions or file path.") (alert (strcat "Processing complete!\n\nProcessed " (itoa cnt) " files.\nFile saved (UTF-8) to:\n" sv-path)) ) ) ) ) (vlax-release-object fso) ) ) (*error* nil) (princ) ) (princ "\nCodebase Packer (Version 1.0 Release, Author: Vico Wang) loaded. Type CPK to start.") (princ) The story behind this tool That web frontend I mentioned? It turned into VedaCAD — an experiment in modernising how we manage CAD environments. We're all still copying .arg profiles and fixing broken Support paths like it's 1999. I wanted something simpler: wrap your scripts and configs into 6-character ShareCodes, Then type the ID in the VC panel and pull it down to use it directly. There is a fully free tier (BASE mode works offline, FREE tier allows sync up to 3MB per file). For creators, I'm experimenting with some tools like push-updates and a tip-jar (0% commission), but honestly the platform is still young and I'm here mostly to listen. If you'd like to try the Codebase Packer without copy-pasting, you can install it into AutoCAD using ShareCode 0FBGZB (whatever that means for you — no pressure). I'd genuinely appreciate any thoughts, especially from the veterans. Is "environment sync" a real pain point for you? Am I solving a problem that's just mine? Cheers, Vico4 points
-
Set bit 1 of the QAFLAGS system variable (storing the original value and resetting after the command); with bit 1 enabled, the EXPLODE command will accept selection sets when invoked from the LISP API. Alternatively, ensure that this bit is not set and only pass a single entity with no double quotes. The key point is that by controlling the bit, you can ensure consistent behaviour.4 points
-
Hello everyone, I've just finished developing MPL (Multi Plot Layout/Model), a free AutoLISP tool that helps you batch print drawings in AutoCAD. Main Features MPL includes all the essential functions found in other batch plotting LISP tools, plus several improvements: Smart and intuitive DCL interface Merge all plots into a single PDF (no additional software or virtual PDF printer required) Automatically open the output file or folder after plotting, with customizable file name and save location Zone-based plotting – organize messy drawings and print them in the correct order based on defined zones Batch plot multiple layouts – rearrange the printing order of layout tabs without dragging the tabs at the bottom of AutoCAD Print Preview mode Add Selection feature – easily add more drawings to the current print list without starting over Export/Import plot configuration for quick reuse Download and user guide: https://drive.google.com/drive/folders/1WwmkXVgHFWTy8zIhARJYCH_G2OC2A_3D?usp=sharing Feel free to download it, give it a try, and let me know your feedback. Your suggestions will help improve MPL even further!3 points
-
@troggarf yep took the plunge and installed Python, the install is easy With @Danielm103 help also installed a couple of extra modules that where needed for his code. Then it's simple like lisp using Pyload instead of Appload. Or you can load python scripts using a lisp call. ; lisp start python (setq python "C:/Users/xxxxxx/AppData/Local/Python/Python-3.14-64/python.exe" pyscript "D:\\alan\\lisp\\ctb table.py" ) (startapp python pyscript)3 points
-
AI has been around a long time, LLM since the 1990's, LISP was created for AI programming IIRC. It's a tool just like VLIDE, VS Code, etc. for programming. Problem, just like before, people came on to forums often demanding a code, etc. be written to make their life easier instead of learning something on their own to do it themselves. Most forums used to provide help and occasionally a custom code, etc. just like... That's a long list of requests. So now they demand AI to do their demands, those with some abilities have success, those that have great abilities have great success, etc. I know recently a man in Lee County, FL was arrested for a crime committed in or near Jacksonville, FL due to AI facial recognition, done by a third county's AI program, no second looks, no reasonable investigation, the man had never been to Jacksonville and a valid alibi for the time showing such. That's the bigger problem with AI right now, accepting the results without question. From the comments I see everywhere a great many seem tired of the AI everything.3 points
-
I’m loving AI, it’s allowed me to do stuff that would take months to write in days. Example, this dark mode project to BricsCAD (https://github.com/CEXT-Dan/BrxDarkMenu) would have taken months to research.I had already done some win32 programming in the past, but very little. In short, you kind of have to know what you’re doing to use AI. I read about the Brown university thing where the professor made the students do their exams in class and most of the class failed. Scary! People need to at least learn foundational level stuff before using AI. What if the cloud is down, or you reach your token max, would you be able to go old school and continue? Or just sit there and twiddle your thumbs. With regards to anti-scraping, I see lots of open-source projects moving off GitHub to other places like Codeberg so their projects aren’t scraped, I guess so big companies that use AI don’t end up getting their code. I’m the opposite, I want AI to train on my code (if its open source)3 points
-
Couple of comments to add: MHUPP mentioned anti-scraping, years ago I had a website and would layer the important images, put together they showed correctly but a left click, copy, paste, gave something like just the yellow and a transparent colour block - had to dig a little deeper to get the original image... so it is something that has happened kind of for years. If it is out there though I don't know if you can have a true anti-scraping system and have it visible to the humans CADTutor, for the future of AutoCAD, I am not concerned - though I am also including the others such as BricsCAD and so on - many of the issues on one system are common to the others and this forum will be relevant for a while yet (15 years please, till I retire...).3 points
-
Hi everyone, I'm Vico, an architectural designer. I've found this forum incredibly helpful over the years— so many of the LISP routines shared here have become the backbone of my daily workflow. But as my collection grew, one thing started driving me absolutely crazy: the APPLOAD dialog. The problem (I suspect I'm not alone) Managing dozens of .lsp, .fas, and .vlx files through that interface is clunky at best. You can't see what's loaded, what's conflicting, or even what half of them do without opening each file. And the Startup Suite? Let's just say it and I have a complicated relationship. Then there's the real nightmare: upgrading to a new PC. You spend half a day manually rebuilding your Startup Suite, redefining aliases in acad.pgp, and fixing broken Support paths — and you still forget something. My attempt at a solution Over the past few months I built a tool to solve this for myself, and I thought the community here might find it useful. It's part of a side-project I've been tinkering with called VedaCAD. The tool comes as a single compiled .vlx. By default it runs in Base mode — completely offline, no accounts, no network calls, nothing phoning home. It just sits quietly and manages your local scripts. What it does: Gives you a clean UI to see all your loaded scripts in one place — no more hunting through APPLOAD. Lets you assign custom command aliases directly from the interface, without manually editing acad.pgp or writing wrapper LISPs. Has a one-click "Export Config" that builds a lightweight JSON mapping of your entire environment. Take that file (plus your LISP folder) to a new machine, hit "Import Config", and everything comes back exactly as it was — script mappings, custom aliases, and paths, bypassing the native Startup Suite entirely. A couple of disclaimers It's written entirely in pure AutoLISP/Visual LISP and DCL, so it should be compatible all the way back to AutoCAD 2006 — none of that "requires .NET Framework X.x" nonsense. I've personally tested it on 2006, 2014, and 2024, and it runs smoothly right across that range. And again: fully air-gapped in Base mode. No telemetry, no registration nag, no "sign up to unlock." If you're paranoid about that sort of thing (I certainly am), you can verify with any network monitor like Wireshark. Why I'm posting I built this to scratch my own itch, and it's made my life genuinely easier. But I'm one person with one workflow — I'd be really curious to hear if this solves a real problem for anyone else, or if I've just been doing APPLOAD wrong all these years. If you'd like to give it a spin, the .vlx is attached. Happy to answer questions, and very open to feedback (including the critical kind). Cheers, Vico VedaCAD V1.0.VLX2 points
-
@HypnoS if your using title blocks then it is possible to detect the name of the title block and use the correct plot settings, for example a A4 in landscape or portrait mode. Just using say layout extents can return wrong answers as even where I worked there was occasional junk in a layout outside of the title block.2 points
-
Based on my practice of networking LISP, I am going to make an online game platform that executes in the CAD model space. However, the game category is different from the products I developed before. It requires a certain timeliness, which is a challenge to the network infrastructure. In short, I have developed a local battle version of Gomoku. You can copy the following code or download the lsp file to run it locally. Gomoku V0.3.lsp After the problem of the network infrastructure part is solved, the plug-in will be iterated quickly to achieve online instant challenges. I have provided another updateable installation method to avoid duplicate copying or downloading. If I update it, you will know: [Gomoku CadCade] VCID: 1G8VY1 @ VedaCAD I hope to hear your opinions on UI and interaction. ;;; AutoCAD Gomoku v0.3 ;;; Author: Vico (CadCade) ;;; Description: Standalone 15x15 Gomoku in ModelSpace (vl-load-com) ;;; --- Globals & States --- (setq *gmk-size* 15 *gmk-cell* 10.0 *gmk-radius* (* *gmk-cell* 0.333) *gmk-layer* "CADCADE_CANVAS" *gmk-p1-color* 10 ; Soft Pastel Red *gmk-p2-color* 140 ; Bright Light Blue *gmk-win-color* 3 ; Bright Green *gmk-idle-color* 8) ; Dark Gray (setq *gmk-board* nil *gmk-hover-ent* nil *gmk-active* nil *gmk-ui-x* 0.0 *gmk-ui-y* 0.0 *gmk-p1-total* 0.0 *gmk-p2-total* 0.0 *gmk-history* nil) (setq *gmk-ui-p1-time-ent* nil *gmk-ui-p1-tot-ent* nil *gmk-ui-p2-time-ent* nil *gmk-ui-p2-tot-ent* nil *gmk-ui-p1-icon-ent* nil *gmk-ui-p1-name-ent* nil *gmk-ui-p2-icon-ent* nil *gmk-ui-p2-name-ent* nil *gmk-ui-hist-1* nil *gmk-ui-hist-2* nil *gmk-ui-hist-3* nil *gmk-ui-hist-4* nil *gmk-ui-hist-5* nil *gmk-ui-hist-6* nil) ;;; --- Data Structure --- (defun gmk:get-index (x y) (+ (* y *gmk-size*) x)) (defun gmk:get-cell (x y) (if (and (>= x 0) (< x *gmk-size*) (>= y 0) (< y *gmk-size*)) (nth (gmk:get-index x y) *gmk-board*) -1 ) ) (defun gmk:set-cell (x y val / idx i nb) (setq idx (gmk:get-index x y) i 0 nb nil) (foreach item *gmk-board* (setq nb (cons (if (= i idx) val item) nb) i (1+ i)) ) (setq *gmk-board* (reverse nb)) ) ;;; --- Graphics & Layer --- (defun gmk:ensure-layer () (if (not (tblsearch "LAYER" *gmk-layer*)) (entmakex (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") (cons 2 *gmk-layer*) '(70 . 0))) ) ) (defun gmk:purge-board (/ ss i e) (if (setq ss (ssget "_X" (list (cons 8 *gmk-layer*)))) (progn (setq i -1) (while (setq e (ssname ss (setq i (1+ i)))) (vl-catch-all-apply 'entdel (list e)) ) ) ) ) (defun gmk:draw-line (pt1 pt2 col) (entmakex (list '(0 . "LINE") (cons 8 *gmk-layer*) (cons 10 pt1) (cons 11 pt2) (cons 62 col))) ) (defun gmk:draw-thick-line (pt1 pt2 col wid) (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") (cons 8 *gmk-layer*) '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0) (cons 43 wid) (cons 62 col) (cons 10 (list (car pt1) (cadr pt1))) (cons 10 (list (car pt2) (cadr pt2))))) ) (defun gmk:draw-text (pt str hgt col) (entmakex (list '(0 . "TEXT") (cons 8 *gmk-layer*) (cons 10 pt) (cons 40 hgt) (cons 1 str) (cons 62 col))) ) (defun gmk:draw-centered-text (pt str hgt col) (entmakex (list '(0 . "TEXT") (cons 8 *gmk-layer*) (cons 10 pt) (cons 11 pt) (cons 40 hgt) (cons 1 str) (cons 62 col) '(72 . 1) '(73 . 2))) ) (defun gmk:update-dynamic-text (sym pt str hgt col / el) (if (and (eval sym) (setq el (entget (eval sym)))) (entmod (subst (cons 62 col) (assoc 62 el) (subst (cons 1 str) (assoc 1 el) el))) (set sym (gmk:draw-text pt str hgt col)) ) ) (defun gmk:update-color (ent col / el) (if (and ent (setq el (entget ent))) (entmod (subst (cons 62 col) (assoc 62 el) el)) ) ) (defun gmk:set-turn (p / c1 c2) (if (= p 1) (setq c1 *gmk-p1-color* c2 *gmk-idle-color*) (setq c1 *gmk-idle-color* c2 *gmk-p2-color*) ) (gmk:update-color *gmk-ui-p1-icon-ent* c1) (gmk:update-color *gmk-ui-p1-name-ent* c1) (gmk:update-color *gmk-ui-p2-icon-ent* c2) (gmk:update-color *gmk-ui-p2-name-ent* c2) (redraw) ) (defun gmk:draw-solid-circle (pt rad col / r2 p1 p2) (setq r2 (/ rad 2.0) p1 (list (- (car pt) r2) (cadr pt)) p2 (list (+ (car pt) r2) (cadr pt))) (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") (cons 8 *gmk-layer*) '(100 . "AcDbPolyline") '(90 . 2) '(70 . 1) (cons 62 col) (cons 43 rad) (cons 10 p1) '(42 . 1.0) (cons 10 p2) '(42 . 1.0))) ) (defun gmk:draw-rounded-rect (xmin ymin xmax ymax r col wid / b) (setq b 0.41421356) ; tan(pi/8) (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") (cons 8 *gmk-layer*) '(100 . "AcDbPolyline") '(90 . 8) '(70 . 1) (cons 43 wid) (cons 62 col) (cons 10 (list (+ xmin r) ymin)) (cons 42 0.0) (cons 10 (list (- xmax r) ymin)) (cons 42 b) (cons 10 (list xmax (+ ymin r))) (cons 42 0.0) (cons 10 (list xmax (- ymax r))) (cons 42 b) (cons 10 (list (- xmax r) ymax)) (cons 42 0.0) (cons 10 (list (+ xmin r) ymax)) (cons 42 b) (cons 10 (list xmin (- ymax r))) (cons 42 0.0) (cons 10 (list xmin (+ ymin r))) (cons 42 b))) ) (defun gmk:draw-board (/ i mdim cx ux-l ux-r) (setq mdim (* (1- *gmk-size*) *gmk-cell*)) (setq i 1) (while (< i (1- *gmk-size*)) (gmk:draw-line (list (* i *gmk-cell*) 0.0 0.0) (list (* i *gmk-cell*) mdim 0.0) 8) (gmk:draw-line (list 0.0 (* i *gmk-cell*) 0.0) (list mdim (* i *gmk-cell*) 0.0) 8) (setq i (1+ i)) ) (setq i 0) (while (< i *gmk-size*) (gmk:draw-text (list (- (* i *gmk-cell*) (* *gmk-cell* 0.2)) (* -0.8 *gmk-cell*) 0.0) (chr (+ 65 i)) (* *gmk-cell* 0.4) 8) (gmk:draw-text (list (* -1.4 *gmk-cell*) (- (* i *gmk-cell*) (* *gmk-cell* 0.2)) 0.0) (itoa (1+ i)) (* *gmk-cell* 0.4) 8) (setq i (1+ i)) ) (entmakex (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 8 *gmk-layer*) '(90 . 4) '(70 . 1) (cons 43 (* *gmk-cell* 0.08)) '(62 . 8) (cons 10 '(0.0 0.0)) (cons 10 (list mdim 0.0)) (cons 10 (list mdim mdim)) (cons 10 (list 0.0 mdim)))) (gmk:draw-solid-circle (list (* 7 *gmk-cell*) (* 7 *gmk-cell*) 0.0) (* *gmk-cell* 0.15) 8) (setq ux-l (+ mdim (* *gmk-cell* 2.5)) ux-r (+ ux-l (* *gmk-cell* 7.5)) cx (+ ux-l (* *gmk-cell* 3.75))) (gmk:draw-rounded-rect ux-l 0.0 ux-r mdim (* *gmk-cell* 0.5) 8 (* *gmk-cell* 0.05)) (gmk:draw-centered-text (list cx (- mdim (* *gmk-cell* 0.7)) 0.0) "GOMOKU" (* *gmk-cell* 0.55) 8) (gmk:draw-centered-text (list cx (- mdim (* *gmk-cell* 1.4)) 0.0) "CadCade.com" (* *gmk-cell* 0.25) 8) (gmk:draw-line (list (+ ux-l (* *gmk-cell* 0.4)) (- mdim (* *gmk-cell* 1.9)) 0.0) (list (- ux-r (* *gmk-cell* 0.4)) (- mdim (* *gmk-cell* 1.9)) 0.0) 8) (setq *gmk-ui-p1-icon-ent* (gmk:draw-solid-circle (list (+ ux-l (* *gmk-cell* 1.0)) (- mdim (* *gmk-cell* 2.7)) 0.0) *gmk-radius* *gmk-p1-color*)) (setq *gmk-ui-p1-name-ent* (gmk:draw-text (list (+ ux-l (* *gmk-cell* 1.8)) (- mdim (* *gmk-cell* 2.85)) 0.0) "Player 1" (* *gmk-cell* 0.4) *gmk-p1-color*)) (gmk:draw-text (list (+ ux-l (* *gmk-cell* 1.0)) (- mdim (* *gmk-cell* 3.6)) 0.0) "Think Time:" (* *gmk-cell* 0.3) 8) (gmk:update-dynamic-text '*gmk-ui-p1-time-ent* (list (+ ux-l (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 3.6)) 0.0) "0.00s" (* *gmk-cell* 0.3) 8) (gmk:draw-text (list (+ ux-l (* *gmk-cell* 1.0)) (- mdim (* *gmk-cell* 4.1)) 0.0) "Total Time:" (* *gmk-cell* 0.3) 8) (gmk:update-dynamic-text '*gmk-ui-p1-tot-ent* (list (+ ux-l (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 4.1)) 0.0) "0.00s" (* *gmk-cell* 0.3) 8) (gmk:draw-line (list (+ ux-l (* *gmk-cell* 0.4)) (- mdim (* *gmk-cell* 4.7)) 0.0) (list (- ux-r (* *gmk-cell* 0.4)) (- mdim (* *gmk-cell* 4.7)) 0.0) 8) (setq *gmk-ui-p2-icon-ent* (gmk:draw-solid-circle (list (+ ux-l (* *gmk-cell* 1.0)) (- mdim (* *gmk-cell* 5.5)) 0.0) *gmk-radius* *gmk-p2-color*)) (setq *gmk-ui-p2-name-ent* (gmk:draw-text (list (+ ux-l (* *gmk-cell* 1.8)) (- mdim (* *gmk-cell* 5.65)) 0.0) "Local AI" (* *gmk-cell* 0.4) *gmk-p2-color*)) (gmk:draw-text (list (+ ux-l (* *gmk-cell* 1.0)) (- mdim (* *gmk-cell* 6.4)) 0.0) "Think Time:" (* *gmk-cell* 0.3) 8) (gmk:update-dynamic-text '*gmk-ui-p2-time-ent* (list (+ ux-l (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 6.4)) 0.0) "0.00s" (* *gmk-cell* 0.3) 8) (gmk:draw-text (list (+ ux-l (* *gmk-cell* 1.0)) (- mdim (* *gmk-cell* 6.9)) 0.0) "Total Time:" (* *gmk-cell* 0.3) 8) (gmk:update-dynamic-text '*gmk-ui-p2-tot-ent* (list (+ ux-l (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 6.9)) 0.0) "0.00s" (* *gmk-cell* 0.3) 8) (gmk:draw-line (list (+ ux-l (* *gmk-cell* 0.4)) (- mdim (* *gmk-cell* 7.5)) 0.0) (list (- ux-r (* *gmk-cell* 0.4)) (- mdim (* *gmk-cell* 7.5)) 0.0) 8) (gmk:draw-text (list (+ ux-l (* *gmk-cell* 0.8)) (- mdim (* *gmk-cell* 8.2)) 0.0) "RECENT MOVES:" (* *gmk-cell* 0.35) 8) (setq *gmk-history* nil) (gmk:draw-line (list (+ ux-l (* *gmk-cell* 0.4)) (* *gmk-cell* 1.4) 0.0) (list (- ux-r (* *gmk-cell* 0.4)) (* *gmk-cell* 1.4) 0.0) 8) (gmk:draw-centered-text (list cx (* *gmk-cell* 0.8) 0.0) "Powered by CadCade.com" (* *gmk-cell* 0.2) 8) (gmk:draw-centered-text (list cx (* *gmk-cell* 0.3) 0.0) "Code by Vico" (* *gmk-cell* 0.2) 8) ) (defun gmk:format-move (x y) (strcat (chr (+ 65 x)) (itoa (1+ y)))) (defun gmk:add-history (p mstr / c pt i mdim ux-l) (setq *gmk-history* (cons (list p mstr) *gmk-history*)) (if (> (length *gmk-history*) 6) (setq *gmk-history* (reverse (cdr (reverse *gmk-history*)))) ) (setq mdim (* (1- *gmk-size*) *gmk-cell*) ux-l (+ mdim (* *gmk-cell* 2.5)) i 0) (foreach item *gmk-history* (setq c (if (= (car item) 1) *gmk-p1-color* *gmk-p2-color*) pt (list (+ ux-l (* *gmk-cell* 1.2)) (- mdim (* *gmk-cell* (+ 8.8 (* i 0.55)))) 0.0)) (gmk:update-dynamic-text (read (strcat "*gmk-ui-hist-" (itoa (1+ i)) "*")) pt (cadr item) (* *gmk-cell* 0.3) c) (setq i (1+ i)) ) ) (defun gmk:update-hover (x y / pt el) (if (and (>= x 0) (< x *gmk-size*) (>= y 0) (< y *gmk-size*) (zerop (gmk:get-cell x y))) (progn (setq pt (list (* x *gmk-cell*) (* y *gmk-cell*) 0.0)) (if (or (not *gmk-hover-ent*) (not (entget *gmk-hover-ent*))) (setq *gmk-hover-ent* (entmakex (list '(0 . "CIRCLE") (cons 8 *gmk-layer*) (cons 10 pt) (cons 40 *gmk-radius*) (cons 62 *gmk-p1-color*)))) (progn (setq el (entget *gmk-hover-ent*)) (entmod (subst (cons 10 pt) (assoc 10 el) el)) ) ) ) (gmk:clear-hover) ) ) (defun gmk:clear-hover () (if *gmk-hover-ent* (progn (vl-catch-all-apply 'entdel (list *gmk-hover-ent*)) (setq *gmk-hover-ent* nil) ) ) ) (defun gmk:cleanup () (gmk:clear-hover) (setq *gmk-entities* nil *gmk-hover-ent* nil *gmk-board* nil *gmk-ui-p1-time-ent* nil *gmk-ui-p1-tot-ent* nil *gmk-ui-p2-time-ent* nil *gmk-ui-p2-tot-ent* nil *gmk-ui-p1-icon-ent* nil *gmk-ui-p1-name-ent* nil *gmk-ui-p2-icon-ent* nil *gmk-ui-p2-name-ent* nil *gmk-ui-hist-1* nil *gmk-ui-hist-2* nil *gmk-ui-hist-3* nil *gmk-ui-hist-4* nil *gmk-ui-hist-5* nil *gmk-ui-hist-6* nil) ) ;;; --- DCL UI --- (defun gmk:show-lobby-dialog (/ fn f id res) (setq fn (vl-filename-mktemp "gmk_lobby.dcl") f (open fn "w")) (foreach str '( "gmk_lobby : dialog { label=\"CadCade.com Lobby\"; width=40;" " : spacer { height=0.5; }" " : text { label=\"Select Game Mode:\"; alignment=centered; font=\"bold\"; }" " : spacer { height=1; }" " : column { alignment=centered; fixed_width=true;" " : button { key=\"btn_match\"; label=\"Online Matchmaking\"; width=28; fixed_width=true; is_enabled=false; }" " : spacer { height=0.2; }" " : button { key=\"btn_watch\"; label=\"Spectate Mode\"; width=28; fixed_width=true; is_enabled=false; }" " : spacer { height=0.2; }" " : button { key=\"btn_local\"; label=\"Local PvE (vs AI)\"; width=28; fixed_width=true; is_default=true; }" " }" " : spacer { height=1; }" " : button { key=\"btn_quit\"; label=\"Exit Game\"; is_cancel=true; width=12; alignment=centered; }" "}") (write-line str f) ) (close f) (setq id (load_dialog fn)) (if (new_dialog "gmk_lobby" id) (progn (action_tile "btn_local" "(done_dialog 1)") (action_tile "btn_match" "(done_dialog 2)") (action_tile "btn_watch" "(done_dialog 3)") (action_tile "btn_quit" "(done_dialog 0)") (setq res (start_dialog)) ) (setq res 0) ) (unload_dialog id) (vl-file-delete fn) res ) (defun gmk:show-gameover-dialog (msg / fn f id res) (gmk:clear-hover) (setq fn (vl-filename-mktemp "gmk_go.dcl") f (open fn "w")) (foreach str (list "gmk_go : dialog { label=\"Match Complete\";" " : spacer { height=0.5; }" (strcat " : text { label=\"" msg "\"; alignment=centered; font=\"bold\"; }") " : spacer { height=1; }" " : row { alignment=centered; fixed_width=true;" " : button { key=\"btn_next\"; label=\"Play Again\"; is_default=true; width=16; fixed_width=true; }" " : button { key=\"btn_quit\"; label=\"End Match\"; is_cancel=true; width=16; fixed_width=true; }" " }" "}") (write-line str f) ) (close f) (setq id (load_dialog fn)) (if (new_dialog "gmk_go" id) (progn (action_tile "btn_next" "(done_dialog 1)") (action_tile "btn_quit" "(done_dialog 0)") (setq res (start_dialog)) ) ) (unload_dialog id) (vl-file-delete fn) res ) (defun gmk:show-cleanup-dialog (/ fn f id res) (gmk:clear-hover) (setq fn (vl-filename-mktemp "gmk_cl.dcl") f (open fn "w")) (foreach str '( "gmk_cl : dialog { label=\"Exit Game\";" " : spacer { height=0.5; }" " : text { label=\"Do you want to keep the board on the screen?\"; alignment=centered; }" " : text { label=\"(Kept entities will become standard CAD objects)\"; alignment=centered; color=8; }" " : spacer { height=1; }" " : row { alignment=centered; fixed_width=true;" " : button { key=\"btn_keep\"; label=\"Keep Board\"; is_default=true; width=14; fixed_width=true; }" " : button { key=\"btn_clean\"; label=\"Clean Up\"; is_cancel=true; width=14; fixed_width=true; }" " }" "}") (write-line str f) ) (close f) (setq id (load_dialog fn)) (if (new_dialog "gmk_cl" id) (progn (action_tile "btn_keep" "(done_dialog 1)") (action_tile "btn_clean" "(done_dialog 0)") (setq res (start_dialog)) ) ) (unload_dialog id) (vl-file-delete fn) res ) ;;; --- Core Math & AI --- (defun gmk:get-time-seconds () (* 86400.0 (getvar "DATE"))) (defun gmk:count-continuous (x y dx dy p / cnt blk cx cy px py) (setq cnt 0 blk 0 cx (+ x dx) cy (+ y dy) px x py y) (while (and (>= cx 0) (< cx *gmk-size*) (>= cy 0) (< cy *gmk-size*) (= (gmk:get-cell cx cy) p)) (setq px cx py cy cnt (1+ cnt) cx (+ cx dx) cy (+ cy dy)) ) (if (or (< cx 0) (>= cx *gmk-size*) (< cy 0) (>= cy *gmk-size*) (/= (gmk:get-cell cx cy) 0)) (setq blk 1) ) (list cnt blk px py) ) (defun gmk:check-win (x y p / dirs d r1 r2 tot win) (setq dirs '((1 0) (0 1) (1 1) (1 -1)) win nil) (foreach d dirs (setq r1 (gmk:count-continuous x y (car d) (cadr d) p) r2 (gmk:count-continuous x y (- (car d)) (- (cadr d)) p) tot (+ 1 (car r1) (car r2))) (if (>= tot 5) (setq win (list (nth 2 r2) (nth 3 r2) (nth 2 r1) (nth 3 r1))) ) ) win ) (defun gmk:eval-dir (x y dx dy p / r1 r2 cnt blk) (setq r1 (gmk:count-continuous x y dx dy p) r2 (gmk:count-continuous x y (- dx) (- dy) p) cnt (+ 1 (car r1) (car r2)) blk (+ (cadr r1) (cadr r2))) (cond ((>= cnt 5) 1000000) ; Win ((and (= cnt 4) (= blk 0)) 100000) ; Open 4 ((and (= cnt 4) (= blk 1)) 10000) ; Closed 4 ((and (= cnt 3) (= blk 0)) 5000) ; Open 3 ((and (= cnt 3) (= blk 1)) 50) ; Closed 3 ((and (= cnt 2) (= blk 0)) 100) ; Open 2 ((and (= cnt 2) (= blk 1)) 5) ; Closed 2 (t 1) ) ) (defun gmk:eval-point (x y p / dirs tot d) (setq dirs '((1 0) (0 1) (1 1) (1 -1)) tot 0) (foreach d dirs (setq tot (+ tot (gmk:eval-dir x y (car d) (cadr d) p))) ) tot ) (defun gmk:ai-move (/ bx by max-s x y s1 s2 cbias tot) (setq max-s -1 bx 7 by 7 x 0) (while (< x *gmk-size*) (setq y 0) (while (< y *gmk-size*) (if (zerop (gmk:get-cell x y)) (progn (setq s1 (gmk:eval-point x y 1) s2 (gmk:eval-point x y 2) ;; Center bias using inverse Manhattan distance to (7,7). Max value ~14, Min 0. cbias (- 14.0 (+ (abs (- x 7)) (abs (- y 7)))) tot (+ s2 (* s1 1.2) (* cbias 0.5))) (if (> tot max-s) (setq max-s tot bx x by y)) ) ) (setq y (1+ y)) ) (setq x (1+ x)) ) (list bx by) ) ;;; --- Main App Loop --- (defun c:GOMOKU (/ *error* o-cmd o-osm run md pa gr pt spt cx cy am win r st dt uxl mdim ccode) (defun *error* (msg) (gmk:purge-board) (gmk:cleanup) (if o-cmd (setvar "CMDECHO" o-cmd)) (if o-osm (setvar "OSMODE" o-osm)) (if (not (wcmatch (strcase msg) "*QUIT*,*CANCEL*,*BREAK*")) (princ (strcat "\n[Gomoku] Error: " msg)) (princ "\n[Gomoku] Match aborted by user.") ) (princ) ) (setq o-cmd (getvar "CMDECHO") o-osm (getvar "OSMODE")) (setvar "CMDECHO" 0) (setvar "OSMODE" 32) (setq mdim (* (1- *gmk-size*) *gmk-cell*) uxl (+ mdim (* *gmk-cell* 2.5)) run T) (while run (setq md (gmk:show-lobby-dialog)) (cond ((= md 0) (setq run nil)) ((= md 1) (setq pa T) (while pa (princ "\n[Gomoku] Initializing Sandbox Board...") (gmk:ensure-layer) (gmk:purge-board) (gmk:cleanup) (setq *gmk-board* '()) (repeat (* *gmk-size* *gmk-size*) (setq *gmk-board* (cons 0 *gmk-board*))) (setq *gmk-p1-total* 0.0 *gmk-p2-total* 0.0) (gmk:draw-board) (command "_.ZOOM" "_W" (list (* -2 *gmk-cell*) (* -2 *gmk-cell*)) (list (+ uxl (* *gmk-cell* 9.5)) (+ mdim (* *gmk-cell* 2.0)))) (princ "\n[Gomoku] Game Start! You are Red. Click to place your piece. Press ESC or Right-Click to exit.") (setq *gmk-active* T st (gmk:get-time-seconds)) (gmk:set-turn 1) (while *gmk-active* (setq gr (grread T 15 0) ccode (car gr) pt (cadr gr)) (cond ;; Hover ((= ccode 5) (if (setq spt (osnap pt "_int")) (setq pt spt)) (setq cx (fix (+ (/ (car pt) *gmk-cell*) 0.5)) cy (fix (+ (/ (cadr pt) *gmk-cell*) 0.5))) (gmk:update-hover cx cy) (setq dt (- (gmk:get-time-seconds) st)) (gmk:update-dynamic-text '*gmk-ui-p1-time-ent* (list (+ uxl (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 3.6)) 0.0) (strcat (rtos dt 2 2) "s") (* *gmk-cell* 0.3) 8) ) ;; Click ((= ccode 3) (if (setq spt (osnap pt "_int")) (setq pt spt)) (setq cx (fix (+ (/ (car pt) *gmk-cell*) 0.5)) cy (fix (+ (/ (cadr pt) *gmk-cell*) 0.5))) (if (and (>= cx 0) (< cx *gmk-size*) (>= cy 0) (< cy *gmk-size*) (zerop (gmk:get-cell cx cy))) (progn (setq dt (- (gmk:get-time-seconds) st) *gmk-p1-total* (+ *gmk-p1-total* dt)) (gmk:update-dynamic-text '*gmk-ui-p1-time-ent* (list (+ uxl (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 3.6)) 0.0) (strcat (rtos dt 2 2) "s") (* *gmk-cell* 0.3) 8) (gmk:update-dynamic-text '*gmk-ui-p1-tot-ent* (list (+ uxl (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 4.1)) 0.0) (strcat (rtos *gmk-p1-total* 2 2) "s") (* *gmk-cell* 0.3) 8) (gmk:set-cell cx cy 1) (gmk:draw-solid-circle (list (* cx *gmk-cell*) (* cy *gmk-cell*)) *gmk-radius* *gmk-p1-color*) (gmk:clear-hover) (gmk:add-history 1 (strcat "Red: " (gmk:format-move cx cy))) (if (setq win (gmk:check-win cx cy 1)) (progn (gmk:add-history 1 "Red: MATCH WIN!") (gmk:draw-thick-line (list (* (car win) *gmk-cell*) (* (cadr win) *gmk-cell*)) (list (* (nth 2 win) *gmk-cell*) (* (nth 3 win) *gmk-cell*)) *gmk-win-color* (* *gmk-cell* 0.4)) (redraw) (setq r (gmk:show-gameover-dialog "Victory! You defeated the Local AI.") *gmk-active* nil pa (= r 1)) ) (if (not (member 0 *gmk-board*)) (progn (gmk:add-history 1 "SYS: DRAW MATCH") (redraw) (setq r (gmk:show-gameover-dialog "Stalemate! The board is full.") *gmk-active* nil pa (= r 1)) ) (progn (gmk:set-turn 2) (princ "\n[Gomoku] AI is thinking...") (setq st (gmk:get-time-seconds) am (gmk:ai-move) dt (- (gmk:get-time-seconds) st) *gmk-p2-total* (+ *gmk-p2-total* dt)) (gmk:update-dynamic-text '*gmk-ui-p2-time-ent* (list (+ uxl (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 6.4)) 0.0) (strcat (rtos dt 2 3) "s") (* *gmk-cell* 0.3) 8) (gmk:update-dynamic-text '*gmk-ui-p2-tot-ent* (list (+ uxl (* *gmk-cell* 4.1)) (- mdim (* *gmk-cell* 6.9)) 0.0) (strcat (rtos *gmk-p2-total* 2 2) "s") (* *gmk-cell* 0.3) 8) (gmk:set-cell (car am) (cadr am) 2) (gmk:draw-solid-circle (list (* (car am) *gmk-cell*) (* (cadr am) *gmk-cell*)) *gmk-radius* *gmk-p2-color*) (gmk:add-history 2 (strcat "Blue: " (gmk:format-move (car am) (cadr am)))) (if (setq win (gmk:check-win (car am) (cadr am) 2)) (progn (gmk:add-history 2 "Blue: MATCH WIN!") (gmk:draw-thick-line (list (* (car win) *gmk-cell*) (* (cadr win) *gmk-cell*)) (list (* (nth 2 win) *gmk-cell*) (* (nth 3 win) *gmk-cell*)) *gmk-win-color* (* *gmk-cell* 0.4)) (redraw) (setq r (gmk:show-gameover-dialog "Defeat! The Local AI claims victory.") *gmk-active* nil pa (= r 1)) ) (if (not (member 0 *gmk-board*)) (progn (gmk:add-history 2 "SYS: DRAW MATCH") (redraw) (setq r (gmk:show-gameover-dialog "Stalemate! The board is full.") *gmk-active* nil pa (= r 1)) ) (progn (gmk:set-turn 1) (setq st (gmk:get-time-seconds)) (princ "\n[Gomoku] Your turn.") ) ) ) ) ) ) ) ) ) ;; Exit (Right Click or Enter/Space) ((member ccode '(11 2 25)) (gmk:clear-hover) (setq *gmk-active* nil pa nil) ) ;; Catch-all for robust input handling (e.g. middle mouse pan) (t nil) ) ) ) ) ) ) (princ "\n[Gomoku] Game session ended.") (setq r (gmk:show-cleanup-dialog)) (if (= r 1) (progn (princ " Board entities kept as standard CAD objects.") (gmk:cleanup)) (progn (princ " Cleaning up board...") (gmk:purge-board) (gmk:cleanup)) ) (setvar "CMDECHO" o-cmd) (setvar "OSMODE" o-osm) (princ "\n[Gomoku] Type GOMOKU to enter Lobby.") (princ) ) (princ "\n[CadCade] Gomoku Engine (Local PvE Edition) v0.3 loaded. Type GOMOKU to play.") (princ)2 points
-
I think your overlooking the AUTOLOAD function, yes in my Autoload.lsp loads on startup there are 37 defuns, most are very small like DTR, RTD, then there are 38 Autoload's the way Autoload works is you type a command and a lisp program is loaded, so you limit how many lisps are loaded on startup, In the pop there is (load "myprogram") "nowrunit" so again only loaded when you need the program. (autoload "COPY0" '("COPY0")) (autoload "COPYCOMMAND" '("ZZZ")) (autoload "COVER" '("COVER"))2 points
-
Whatever store there is on the internet will suffer similarly from Al generated code, a store where code is uploaded quickly will just become very large, lose its value when there are too many resources to choose all doing something very similar. I think I prefer the forum format (probably always will do), that in creating an answer to the problems asked there is some peer review going on, explanation as what does what and the ability to ask for explanations or how to modify a code supplied to a more unique solution - which is all in itself a great learnign tool2 points
-
@indiancad @Javier Longa there may be a way of using Array if a new UCS OB is used to orient the grid. In the changed rotation need to rotate the block as well. A question @Javier Longa " since I have no programming knowledge whatsoever" then how did you come by the code ? It is considered good manners to acknowledge who wrote the code, if known, or mention Author unknown.2 points
-
2 points
-
I thought I might write some samples to help guide lisp users that are interested in trying out Python. Long time lisp users will feel right at home using result buffers (DXF Lists). In PyRx, it’s wrappers around the old school C ADS functions, I.e. ads_entget, yay, like driving an F-150 with a toilet bowl plunger as the gear shift. In Python, most of these old functions reside in Db.Core The resbuf* linked lists are wrapped into a list of tuples.. does this output look familiar? from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit0() -> None: #entsel with a filter ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) #get the result buffer rb = Db.Core.entGet(id) print(rb) # [ # (-1, PyDb.ObjectId(1de8bf954d0)), # (0, 'LINE'), # (330, PyDb.ObjectId(1de8bf9a1f0)), # (5, '265'), # (100, 'AcDbEntity'), # (67, 0), # (410, 'Model'), # (8, '0'), # (100, 'AcDbLine'), # (10, PyGe.Point3d(0.00000000000000,0.00000000000000,0.00000000000000)), # (11, PyGe.Point3d(100.00000000000000,100.00000000000000,0.00000000000000)), # (210, PyGe.Point3d(0.00000000000000,0.00000000000000,1.00000000000000)) # ]2 points
-
There is also PyInstaller to create an executable. PyInstaller Manual — PyInstaller 6.21.0 documentation pip install -U pyinstaller pyinstaller your_program.py2 points
-
The Ax Space. Ax is the wrapper for ActiveX as described here https://help.autodesk.com/view/OARX/2025/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30 It’s going to look familiar if you’ve done any VBA or Visual Lisp. The big difference is that all Points, Vectors, Matrices, use AcGe classes instead of variants. from pyrx import Ap, Ax, Db, Ed, Ge, Rx @Ap.Command() def doitx1(): # get the application, document, and modelspace using ActiveX automation axApp = Ap.Application.acadApplication() axDoc = axApp.activeDocument() axModel = axDoc.modelSpace() # add a lines to modelspace, then access it properties # use Ge.Point3d class instead of a variant axLine1 = axModel.addLine(Ge.Point3d(0, 0, 0), Ge.Point3d(100, 100, 0)) axLine2 = axModel.addLine(Ge.Point3d(0, 100, 0), Ge.Point3d(100, 0, 0)) interdata = axLine1.intersectWith(axLine2, Ax.AcExtendOption.acExtendNone) if len(interdata) == 0: print("\nDoes not intersect:") return axCircle = axModel.addCircle(interdata[0], 10) axCircle.setColor(Ax.AcColor.acCyan) #scale and rotate xform = Ge.Matrix3d.scaling(2,axCircle.center()) xform *= Ge.Matrix3d.rotation(0.7854, Ge.Vector3d.kZAxis, axCircle.center()) axLine1.transformBy(xform) axLine2.transformBy(xform)2 points
-
Casting objects. Every database object has a static cast method, it is your responsibility to check the type from pyrx import Ap, Ax, Db, Ed, Ge, Rx import traceback @Ap.Command() def doitx3(): try: # Get ActiveX application instance axApp = Ap.Application.acadApplication() axDoc = axApp.activeDocument() axUtil = axDoc.utility() # Prompt user to pick an entity axEnt, pnt = axUtil.getEntity("\nPick a line") # Verify that the picked entity is a LINE if axEnt.objectName() != "AcDbLine": raise RuntimeError("oops!: ") # Cast to AcadLine axLine = Ax.AcadLine.cast(axEnt) # change color to green (RGB: 0, 255, 0) axLine.setTrueColor(Ax.AcadAcCmColor(0, 255, 0)) # Print information about the selected entity print(axEnt.objectName(), pnt) except Exception as err: traceback.print_exception(err)2 points
-
here's an example of creating a table and selecting a sub region from pyrx import Ap, Ax, Db, Ed, Ge, Rx import traceback @Ap.Command() def doitx2(): try: axApp = Ap.Application.acadApplication() axDoc = axApp.activeDocument() axModel = axDoc.modelSpace() ps , point = Ed.Editor.getPoint("\nPick table location: ") if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) # Creates a table with 7 rows and 5 columns axTable = axModel.addTable(point, 7, 5, 1, 5) #fill up the table for col in range(axTable.columns()): for row in range(2, axTable.rows()): axTable.setText(row, col, "{},{}".format(row, col)) #get the cell extents, is a list of 3d points cex11 = axTable.cellExtents(1, 1, False) cex43 = axTable.cellExtents(4, 3, False) # Create a selection region using ActiveX selection methods sssub = axTable.selectSubRegion( cex11[0], cex43[3], Ge.Vector3d.kZAxis, Ge.Vector3d.kXAxis, Ax.AcSelectType.acTableSelectCrossing, False, ) # Apply the selection to the table using ActiveX selection methods axTable.setSubSelection(*sssub) # Perform hit testing and geometric calculations using ActiveX services # Ge space makes it easier to do math pnt = cex11[0] + (cex43[3] - cex11[0]) * 0.5 bhit, row, col = axTable.hitTest(pnt, Ge.Vector3d.kZAxis) if(bhit): # Modify cell properties using ActiveX methods axTable.setCellTextHeight(row, col, 0.8) axTable.setText(row, col, "Bingo") # since were open source we can add stuff like suppost html colors axTable.setCellBackgroundColor(row, col, Ax.AcadAcCmColor("#228B22")) except Exception: print(traceback.format_exc())2 points
-
Start here https://github.com/CEXT-Dan/PyRx#python-for-autocad 1, watch the short YouTube video and download Python 3.14 from the link provided 2, download in install VS Code, install python extension pack 3, try out some of the samples, https://github.com/CEXT-Dan/PyRx/tree/main/PySamples2 points
-
There are some items in the database, where the only option is to use entGet, I.e. ACAD_FIELDLIST is not exposed to ARX See: https://www.cadtutor.net/forum/topic/99220-python-change-precision-of-all-fields-in-a-drawing/2 points
-
And top it off with entMake from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit5() -> None: Db.Core.entMake([(0 , "LINE"),(10, Ge.Point3d(0, 0, 0)),(11, Ge.Point3d(100, 100, 0))])2 points
-
This might be better example, maybe similar to the COND expression? from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit4() -> None: ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) #get the result buffer rb = Db.Core.entGet(id) # Process the result buffer using structural pattern matching updated_rb = [] for item in rb: match item: case (10, _): updated_rb.append((10, Ge.Point3d(0, 0, 0))) case (11, _): updated_rb.append((11, Ge.Point3d(100, 100, 0))) case _: updated_rb.append(item) # Apply changes back to the AutoCAD database Db.Core.entMod(updated_rb)2 points
-
In Python, tuples are immutable, so if we want to modify the list, you have to replace it. In this sample we modify the start and end of a line from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit3() -> None: #entsel with a filter ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) #get the result buffer rb = Db.Core.entGet(id) # Loop through the result buffer list and modify matching DXF codes for i, item in enumerate(rb): dxf_code = item[0] if dxf_code == 10: rb[i] = (10, Ge.Point3d(0, 0, 0)) elif dxf_code == 11: rb[i] = (11, Ge.Point3d(100, 100, 0)) # Apply changes back to the AutoCAD database Db.Core.entMod(rb)2 points
-
In Python, there isn’t an assoc function, we can iterate through and search for a DXF code from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit1() -> None: # entsel with a filter ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) # get the result buffer rb = Db.Core.entGet(id) # 1. Analog to Lisp: (assoc 8 rb) -> Returns the full pair (8, "LayerName") dxf_code, value = next((item for item in rb if item[0] == 8), None) # 2. Extract just the value safely if dxf_code: print(f"The layer is: {value}")2 points
-
those are attribute references of a block. Since vla-fieldcode only works on Text and mtext i used Lee Macs fieldcode instead https://www.lee-mac.com/fieldcode.html It should work on Blocks Attributereferences as well now. (defun c:change_prec (/ *error* acdoc undo-mark ss target index ename obj att field-string revised-string) (defun *error* (msg) (if undo-mark (progn (vl-catch-all-apply 'vla-EndUndoMark (list acdoc)) (setq undo-mark nil) ) ) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) ) (princ (strcat "\nError: " msg)) ) (princ) ) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))) (prompt "\nSelect text, MText, or attributed blocks: ") (while (null (setq ss (ssget '((0 . "TEXT,MTEXT,INSERT"))))) (prompt "\nNo valid text, MText, or blocks selected.") ) (initget 1 "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Current") (setq target (getkword "\nTarget precision [0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/Current]: ")) (vla-StartUndoMark acdoc) (setq undo-mark T) (repeat (setq index (sslength ss)) (setq index (1- index) ename (ssname ss index) obj (vlax-ename->vla-object ename) ) (cond ;; Text or MText ((wcmatch (vla-get-ObjectName obj) "AcDbText,AcDbMText") (setq field-string (vla-FieldCode obj)) (if (and field-string (setq revised-string (replacePrecision field-string target)) ) (vla-put-TextString obj revised-string) ) ) ;; Block reference with editable attributes ((vlax-method-applicable-p obj 'GetAttributes) (foreach att (vlax-invoke obj 'GetAttributes) (setq field-string (LM:fieldcode (vlax-vla-object->ename att))) (if (and field-string (setq revised-string (replacePrecision field-string target)) ) (vla-put-TextString att revised-string) ) ) ) ) ) (vla-EndUndoMark acdoc) (setq undo-mark nil) (vla-Regen acdoc acActiveViewport) (princ) ) (defun replacePrecision (fieldStr target / nbs prec_source return) (setq nbs 0) (cond ((vl-string-search "%<\\" fieldStr nbs) (while nbs (if (setq nbs (vl-string-search "%pr" fieldStr (setq tmp_nbs nbs))) (setq prec_source (itoa (atoi (substr fieldStr (+ nbs 4) 2))) fieldStr (vl-string-subst (if (eq target "Current") (strcat "%pr" (itoa (getvar "LUPREC"))) (strcat "%pr" target) ) (strcat "%pr" prec_source) fieldStr tmp_nbs ) nbs (1+ nbs) ) ) ) (setq return fieldStr) ) ) return ) ;; Field Code - Lee Mac ;; Returns the field expression associated with an entity (defun LM:fieldcode ( ent / replacefield replaceobject fieldstring enx ) (defun replacefield ( str enx / ent fld pos ) (if (setq pos (vl-string-search "\\_FldIdx" (setq str (replaceobject str enx)))) (progn (setq ent (assoc 360 enx) fld (entget (cdr ent)) ) (strcat (substr str 1 pos) (replacefield (fieldstring fld) fld) (replacefield (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx))) ) ) str ) ) (defun replaceobject ( str enx / ent pos ) (if (setq pos (vl-string-search "ObjIdx" str)) (strcat (substr str 1 (+ pos 5)) " " (LM:ObjectID (vlax-ename->vla-object (cdr (setq ent (assoc 331 enx))))) (replaceobject (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx))) ) str ) ) (defun fieldstring ( enx / itm ) (if (setq itm (assoc 3 enx)) (strcat (cdr itm) (fieldstring (cdr (member itm enx)))) (cond ((cdr (assoc 2 enx))) ("")) ) ) (if (and (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION") (setq enx (cdr (assoc 360 enx))) (setq enx (dictsearch enx "ACAD_FIELD")) (setq enx (dictsearch (cdr (assoc -1 enx)) "TEXT")) ) (replacefield (fieldstring enx) enx) ) ) ;; ObjectID - Lee Mac ;; Returns a string containing the ObjectID of a supplied VLA-Object ;; Compatible with 32-bit & 64-bit systems (defun LM:ObjectID ( obj ) (eval (list 'defun 'LM:ObjectID '( obj ) (if (and (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring) ) (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false) '(itoa (vla-get-objectid obj)) ) ) ) (LM:ObjectID obj) ) ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) )2 points
-
Here is another for allowing explode... Solved: Re: Allow exploding outside the block editor - Autodesk Community Are these drawings from AutoCAD Civil 3D or some other CAD? (defun c:AllBlkYHtchN (/ ss i ent) (vl-load-com) ;;-------------------------------------------------- ;; Set Allow Exploding = Yes for all block definitions ;;-------------------------------------------------- (vlax-map-collection (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) '(lambda (blk) (if (vlax-property-available-p blk 'Explodable) (vlax-put-property blk 'Explodable :vlax-true) ) ) ) ;;-------------------------------------------------- ;; Set all hatches Annotative = No ;;-------------------------------------------------- (if (setq ss (ssget "_X" '((0 . "HATCH")))) (progn (setq i 0) (repeat (sslength ss) (setq ent (ssname ss i)) (vl-catch-all-apply '(lambda () (setpropertyvalue ent "Annotative" 0) ) ) (setq i (1+ i)) ) ) ) (princ (strcat "\nUpdated " (itoa (if ss (sslength ss) 0)) " hatch(es). All explodable block definitions enabled." ) ) (princ) ) Do you need nested hatches and blocks, dynamic and/or anonymous blocks?2 points
-
Just a comment in Bricscad V25 the setpropertyvalue does not work, the get does work. One of those odd bugs2 points
-
So did you ever figure out how to do it, OP? I don't know how someone doesn't manually save like every 5 min. I can tell now that this is not a natural reaction for everyone. I am a millennial and it's been metaphorically beaten in my head throughout my all school years to save often. I save after every small bit of changes that I make. Hope you found a way that works for you, though!!2 points
-
AI + AutoCAD, Python is the way, connect to agents in AutoCAD’s process space, I connect to LM studio2 points
-
One that’s free : ), Gemini, also GLM is pretty good a lisp. With AI, don’t try to one shot it, work though the ACIS/SAT patterns and ask questions2 points
-
Spoken dialogue passes through the ears to the brain, the written word causes the eyes to glaze over... I used to know phone numbers, worked in a job where I had to phone many people up - and now with mobile phone contact list and calling over the internet using Teams or Skype contact lists... I cannot remember my home phone number! Yes there is some truth in that RLX AI everything... because it is new and trending, not because it is necessary. AI enabled fridges... because they can and not to make the milk in my morning coffee any better.2 points
-
Hello everyone, Advanced notice Every few years, the software used for this forum goes through a major point upgrade and that time has come round again. At some point in the next few days, I will close the forum for a short while, maybe 24 hours, so that the new software can be installed and the forum can be configured and themed. I'll be in touch with more details shortly.1 point
-
@Danielm103 Thank you for the explanations and code examples. I will compare the suggested methods, decide which one is the most suitable, and start testing it. You mentioned that one of the code examples was generated with AI. Which AI tools do you use for writing or improving AutoLISP, Python, .NET, or ObjectARX code? Do you have any recommendations based on your experience?1 point
-
Thank you. My concern is not damaging the original solid, but losing topology after exploding the copy. I need to identify each face, its boundary edges, edge lengths, and which faces share the same edge. Would exploding a copy preserve enough information to determine these relationships reliably?1 point
-
something like this (AI generated) ;;; ========================================================================= ;;; AutoLISP ACIS/SAT Geometric Decoder Script - Print to Screen ;;; Decodes scrambled DXF groups 1 and 3 data and prints it to the command line ;;; ========================================================================= (defun c:DecodeSatPrint ( / ent enx dxfPair strBytes itm lin cha decodedStr) (vl-load-com) ;; 1. User prompts to select a valid 3D Solid or Region (setq ent (car (entsel "\nSelect 3D Solid or Region to decode: "))) (if ent (progn (setq enx (entget ent)) ;; Verify if the entity type actually holds ACIS data (if (member (cdr (assoc 0 enx)) '("3DSOLID" "REGION" "SURFACE" "BODY")) (progn (princ "\n--- START OF DECODED ACIS SAT DATA ---\n") ;; 2. Parse and Loop through DXF group codes 1 and 3 (while (setq dxfPair (car enx)) (if (member (car dxfPair) '(1 3)) (progn ;; Convert string to ASCII character byte-list and reverse it (setq strBytes (reverse (vl-string->list (cdr dxfPair))) itm nil lin nil) ;; Rebuild scrambled bytes using standard bitwise operators (while strBytes (setq cha (car strBytes) strBytes (cdr strBytes)) (cond ((= cha 95)) ;; Skip formatting delimiters ((= cha 86) (setq itm (cons 73 itm))) ((= cha 32) (setq lin (cons (if itm (vl-list->string itm) "") lin) itm nil)) ((boole 6 cha 95) (setq itm (cons (boole 6 cha 95) itm))) ) ) ;; Print structural line streams directly to the command line (setq decodedStr (vl-list->string itm)) (if (/= decodedStr "") (princ (strcat decodedStr "\n")) ) ) ) (setq enx (cdr enx)) ) (princ "--- END OF DECODED ACIS SAT DATA ---\n") (princ "\nTip: Press F2 to open the AutoCAD Text Window to copy the full log.") ) (princ "\nError: Selected entity does not contain ACIS geometry data.") ) ) ) (princ) ) (princ "\nACIS SAT Decoder (Print version) Loaded. Type 'DecodeSatPrint' to execute.") (princ) asmheader body lump transform shell face face loop plane-surface face loop plane-surface coedge face loop plane-surface coedge coedge coedge coedge edge I'd bet you could make AI make a mini brep for lisp1 point
-
It’s possible with lisp, but really hard. When you entget a solid, you see the garbage at the end that looks like “{kn rn {rn {km rnqhlokhlhhjjnimjmoll {kl nqhlokhlhhjjnimjmoll”, you can actually decode that and get vertices, edges and faces. Python, .NET, or ObjectARX you can use AcDbAssocPersSubentIdPE, It’s like a BRep shortcut. Or use Brep from pyrx import Ap, Db, Ed, Ge, Br print("added command pygetsubents") def pygetsubents(ent: Db.Entity): pe = Db.AssocPersSubentIdPE(ent.queryX(Db.AssocPersSubentIdPE.desc())) print("vertex") for vtx in pe.getAllSubentities(ent, Db.SubentType.kVertexSubentType): # Get the geometric position of each vertex pos = pe.getVertexSubentityGeometry(ent, vtx) print(pos) print("edge") for edge in pe.getAllSubentities(ent, Db.SubentType.kEdgeSubentType): curve = pe.getEdgeSubentityGeometry(ent, edge) print(curve.getStartPoint(), curve.getEndPoint()) print("surface") for face in pe.getAllSubentities(ent, Db.SubentType.kFaceSubentType): brface = Br.Face() brface.setSubentPath(Db.FullSubentPath(ent.objectId(), face)) print("Area", brface.getArea()) @Ap.Command() def doit(): es, id, pnt = Ed.Editor.entSel("\nPick it: \n") ent = Db.Entity(id) pygetsubents(ent) Command: DOIT Pick it: vertex (117.71953884538620,11.77489209746249,100.00000000000000) (117.71953884538620,16.43799615292209,100.00000000000000) (17.71953884538620,16.43799615292209,100.00000000000000) (17.71953884538620,11.77489209746249,100.00000000000000) (117.71953884538620,16.43799615292209,0.00000000000000) (117.71953884538620,11.77489209746249,0.00000000000000) (17.71953884538620,11.77489209746249,0.00000000000000) (17.71953884538620,16.43799615292209,0.00000000000000) edge (17.71953884538620,16.43799615292209,100.00000000000000) (117.71953884538620,16.43799615292209,100.00000000000000) (117.71953884538620,16.43799615292209,0.00000000000000) (17.71953884538620,16.43799615292209,0.00000000000000) (17.71953884538620,11.77489209746249,100.00000000000000) (17.71953884538620,16.43799615292209,100.00000000000000) (17.71953884538620,16.43799615292209,100.00000000000000) (17.71953884538620,16.43799615292209,0.00000000000000) (17.71953884538620,16.43799615292209,0.00000000000000) (17.71953884538620,11.77489209746249,0.00000000000000) (117.71953884538620,11.77489209746249,100.00000000000000) (17.71953884538620,11.77489209746249,100.00000000000000) (17.71953884538620,11.77489209746249,100.00000000000000) (17.71953884538620,11.77489209746249,0.00000000000000) (17.71953884538620,11.77489209746249,0.00000000000000) (117.71953884538620,11.77489209746249,0.00000000000000) (117.71953884538620,16.43799615292209,100.00000000000000) (117.71953884538620,16.43799615292209,0.00000000000000) (117.71953884538620,16.43799615292209,100.00000000000000) (117.71953884538620,11.77489209746249,100.00000000000000) (117.71953884538620,11.77489209746249,100.00000000000000) (117.71953884538620,11.77489209746249,0.00000000000000) (117.71953884538620,11.77489209746249,0.00000000000000) (117.71953884538620,16.43799615292209,0.00000000000000) surface Area 466.31040554595984 Area 466.31040554595984 Area 10000.0 Area 466.31040554595984 Area 10000.0 Area 466.310405545959841 point
-
Often times I would make a copy of a polyline explode it and work over its sub-parts deleting them as i go. no reason you shouldn't do the same here keep the original un touched, make a copy either to a new location or layer and explode and process each part. you shouldn't avoid explode just use it on the copy. -edit https://www.cadtutor.net/forum/topic/34725-autocad2012-3d-solidsurface-into-3d-face/#findComment-2817871 point
-
Not saying what you have done is not worthwhile but a search here would possibly have found this "Table to excel.lsp". I also know there are a few others out there. ; simple table to excel ; expects Title header and data ; BY Alanh Jan 2022 ; do not have excel open You may be interested in this it contains multiple Excel defuns to carry out task to do with Excel. A big help was FIXO who did some great Excel stuff but is no longer of this world. It is a work in progress as more functions are added. Just copy and paste the defun needed. Alan Excel library.lsp1 point
-
;;------------------------------------------------------------------------- ;; TBL2XL.lsp | Version 1.0 ;; Date: 2026-07-20 ;; NEW TOOL - Pick one AutoCAD TABLE. Copies its full grid (all rows and ;; columns, same layout) straight into Excel - uses your open Excel if ;; there is one, otherwise opens a fresh one, starting from wherever your ;; cursor is in the sheet. ;; Changelog: ;; v1.0 - initial release ;;------------------------------------------------------------------------- (vl-load-com) ;; Returns the VLA Active Document Object (defun t2x_acdoc nil (eval (list 'defun 't2x_acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (t2x_acdoc) ) ;; Opens an Undo Group. (defun t2x_startundo ( doc ) (t2x_endundo doc) (vla-startundomark doc) ) ;; Closes an Undo Group. (defun t2x_endundo ( doc / tries ) (setq tries 0) (while (and (= 8 (logand 8 (getvar 'undoctl))) (< tries 5)) (vl-catch-all-apply 'vla-endundomark (list doc)) (setq tries (1+ tries)) ) ) ;; Write a value into a cell (row, col) via the Cells collection's Item property (defun t2x_write_cell ( xlCells row col val ) (vlax-put-property xlCells "Item" row col val) ) ;; Main command (defun c:TBL2XL ( / *error* xlApp xlRun xlBooks xlBook xlSheets xlSheet xlCells xlCell es ent tbl rows cols r c cellval baseRow baseCol wr skipped ) (defun *error* ( msg ) (if xlBooks (vl-catch-all-apply 'vlax-release-object (list xlBooks))) (if xlApp (vl-catch-all-apply 'vla-put-visible (list xlApp :vlax-true)) ;; leave visible so Ajmal keeps the data ) (if xlApp (vl-catch-all-apply 'vlax-release-object (list xlApp))) (t2x_endundo (t2x_acdoc)) (if (and msg (not (wcmatch (strcase msg t) "*break*,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (t2x_startundo (t2x_acdoc)) (setq es (entsel "\nSelect the table: ")) (if (not es) (princ "\nNothing selected.") (progn (setq ent (car es)) (if (/= "ACAD_TABLE" (cdr (assoc 0 (entget ent)))) (princ "\nThat's not a table.") (progn (setq tbl (vlax-ename->vla-object ent)) (setq rows (vla-get-Rows tbl) cols (vla-get-Columns tbl) ) ;; use Excel if one is already open, otherwise open a fresh one (setq xlApp (vlax-get-or-create-object "Excel.Application") xlRun (vlax-get-property xlApp 'Visible) ) (if (= xlRun :vlax-false) (progn (setq xlBooks (vlax-get-property xlApp "Workbooks") xlBook (vlax-invoke-method xlBooks "Add") xlSheets (vlax-get-property xlBook "Sheets") xlSheet (vlax-get-property xlSheets "Item" 1) ) (vla-put-visible xlApp :vlax-true) ) (setq xlSheet (vlax-get-property xlApp 'ActiveSheet)) ) (setq xlCells (vlax-get-property xlSheet "Cells")) ;; start writing from wherever the cursor is in Excel right now (setq xlCell (vlax-get-property xlApp 'ActiveCell)) (setq baseRow (vlax-get-property xlCell 'Row) baseCol (vlax-get-property xlCell 'Column) ) (setq skipped 0) (princ (strcat "\nTable is " (itoa rows) " rows x " (itoa cols) " columns. Copying...")) (setq r 0) (repeat rows (setq c 0) (repeat cols (setq cellval (vl-catch-all-apply 'vla-GetText (list tbl r c))) (if (vl-catch-all-error-p cellval) (setq skipped (1+ skipped)) ;; likely a merged cell - leave blank (progn (setq wr (vl-catch-all-apply 't2x_write_cell (list xlCells (+ baseRow r) (+ baseCol c) cellval))) (if (vl-catch-all-error-p wr) (princ (strcat "\nExcel write error at row " (itoa r) " col " (itoa c) ": " (vl-catch-all-error-message wr))) ) ) ) (setq c (1+ c)) ) (setq r (1+ r)) ) (princ (strcat "\nDone. " (itoa rows) "x" (itoa cols) " table copied to Excel." (if (> skipped 0) (strcat " (" (itoa skipped) " merged cell(s) left blank)") ""))) ) ) ) ) (vl-catch-all-apply '*error* (list nil)) (princ) ) (princ "\n:: TBL2XL.lsp | Version 1.0 :: Type TBL2XL to run.") (princ)1 point
-
;;------------------------------------------------------------------------- ;; TXT2XL.lsp | Version 1.0 ;; Date: 2026-07-20 ;; NEW TOOL - Pick text entities one by one in AutoCAD. Each pick is sent ;; straight into Excel (uses your open Excel if there is one, otherwise ;; opens a fresh one), starting from wherever your cursor is in the sheet. ;; Keep picking - press ENTER or ESC to stop. ;; Changelog: ;;------------------------------------------------------------------------- (vl-load-com) ;; Returns the VLA Active Document Object (defun t2x_acdoc nil (eval (list 'defun 't2x_acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (t2x_acdoc) ) ;; Opens an Undo Group. (defun t2x_startundo ( doc ) (t2x_endundo doc) (vla-startundomark doc) ) ;; Closes an Undo Group. (defun t2x_endundo ( doc / tries ) (setq tries 0) (while (and (= 8 (logand 8 (getvar 'undoctl))) (< tries 5)) (vl-catch-all-apply 'vla-endundomark (list doc)) (setq tries (1+ tries)) ) ) ;; Write a value into a cell (row, col) via the Cells collection's Item property (defun t2x_write_cell ( xlCells row col val ) (vlax-put-property xlCells "Item" row col val) ) ;; Gets the clean text string from a TEXT or MTEXT entity, else nil (defun t2x_get_text_value ( ent / obj etype ) (setq etype (cdr (assoc 0 (entget ent)))) (if (member etype '("TEXT" "MTEXT")) (progn (setq obj (vlax-ename->vla-object ent)) (vla-get-textstring obj) ) ) ) ;; Main command (defun c:TXT2XL ( / *error* xlApp xlRun xlBooks xlBook xlSheets xlSheet xlCells xlCell es ent val row col wr ) (defun *error* ( msg ) (if xlBooks (vl-catch-all-apply 'vlax-release-object (list xlBooks))) (if xlApp (vl-catch-all-apply 'vla-put-visible (list xlApp :vlax-true)) ;; leave visible so Ajmal keeps the data ) (if xlApp (vl-catch-all-apply 'vlax-release-object (list xlApp))) (t2x_endundo (t2x_acdoc)) (if (and msg (not (wcmatch (strcase msg t) "*break*,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (t2x_startundo (t2x_acdoc)) ;; use Excel if one is already open, otherwise open a fresh one (setq xlApp (vlax-get-or-create-object "Excel.Application") xlRun (vlax-get-property xlApp 'Visible) ) (if (= xlRun :vlax-false) (progn (setq xlBooks (vlax-get-property xlApp "Workbooks") xlBook (vlax-invoke-method xlBooks "Add") xlSheets (vlax-get-property xlBook "Sheets") xlSheet (vlax-get-property xlSheets "Item" 1) ) (vla-put-visible xlApp :vlax-true) ) (setq xlSheet (vlax-get-property xlApp 'ActiveSheet)) ) (setq xlCells (vlax-get-property xlSheet "Cells")) ;; start writing from wherever the cursor is in Excel right now, so an ;; existing sheet's data never gets overwritten (setq xlCell (vlax-get-property xlApp 'ActiveCell)) (setq row (vlax-get-property xlCell 'Row) col (vlax-get-property xlCell 'Column) ) (princ "\nTXT2XL running - pick text, ENTER/ESC to stop.") (while (setq es (entsel "\nSelect text: ")) (setq ent (car es)) (setq val (vl-catch-all-apply 't2x_get_text_value (list ent))) (cond ( (vl-catch-all-error-p val) (princ (strcat "\nRead error: " (vl-catch-all-error-message val))) ) ( val (setq wr (vl-catch-all-apply 't2x_write_cell (list xlCells row col val))) (if (vl-catch-all-error-p wr) (princ (strcat "\nExcel write error: " (vl-catch-all-error-message wr))) (progn (princ (strcat "\n-> Row " (itoa row) " : " val)) (setq row (1+ row)) ) ) ) ( t (princ "\nNot a TEXT/MTEXT entity - skipped.") ) ) ) (princ "\nDone. Excel left open with your data.") (vl-catch-all-apply '*error* (list nil)) (princ) ) (princ "\n:: TXT2XL.lsp | Version 1.0 :: Type TXT2XL to run.") (princ)1 point
-
You’re going to want to use .NET or ObjectARX for something like this. - The routine would need a fast KD-tree so as not to do brute force curve evaluations - AcGeCurveCurveInt3d. This class contains query methods that return intervals of overlap between the two curves. - Other items like TEXT or MText, I would use custom hashing routine to bypass slow O(N^2) comparison loop, in theory speed would be O(1) - you would need a GUI for properties to be excluded. I.e. layer. - Attribute defs are owned by the block table record, while Attribute refs are owned by Block reference. you'll need to define the behavior - You cannot safely run this on a dynamic block, if one of the items that is deleted is part of an action, the block has undefined behavior. I did some work on comparing blocks by hash here [Python] https://www.theswamp.org/index.php?topic=60513 Actually, I would consider prototyping in Python before porting to C++. Python already has a hasher for points. .NET has some hashing stuff too, but I’ve never used it. good luck1 point
-
Due to my workload and a busy weekend, it will be sometime next week before I fix the one I have posted. I have so far a working DXF-DWG, DWG-DXF, and DWG-DWG (change the version) on the Multi-file Batch Convertor using ODBX, I plan to add DGN, SAT, PDF, and maybe more, but those aren't exposed to ODBX AFAIK, but I am not going to use Express Tools. Thanks for the inspiration and help to get back on this. Besides the original DGN batch convertor I found and adapted, I was surprised nobody ever tried to make an improved version before.1 point
-
I have mixed feelings about Clippy the AI , at least the one from Google , sure its fast and it can give some relevant answers but you have to double check everything. I am trying to create a dcl editor. Wasn't sure where to start so asked Clippy and it gave me some good ideas on where to begin. But as things got complexer it really started to mess things up. And every time you use it you need to explain every thing all over again because at least the free / unregistered version remembers (saves) nothing . But I learned from my mistakes and started to write a very extensive manual so next time I can upload that so we can better pick up from where we started. My biggest concern is that it creates a black box. You ask something , it gives you something back and you paste and test the code , great , moving on to next part. After a while you end up with a bunch of working code until it doesn't any more and that's where the trouble begins and you notice you have lost your grip on the code because Clippy did it all for you. Like your daddy did all your homework for you and you have to take the exam and ...oops , daddy aint around now is he?1 point
-
There is no doubt that AI is replacing (and will do so even more in the future) the need to interact with something or someone in order to find ideas and the motivation to pursue them. I don’t know which AI tools are the best for programming (I’ve only used Chatgpt so far), but my experience has been positive in terms of how stimulating it is to have someone to discuss ideas with and refine them while solving problems. This was something that, in the past, could only be found in forums like this one. However, the code suggested by Chatgpt is almost always lengthy and often fails. I suppose that will change over time.1 point
-
1 point
