adrath Posted 1 hour ago Posted 1 hour ago Hello all! I work in the land development field and I'm trying to use Microsoft Copilot to write some LISP routines to make our sheet production easier on multi-phase subdivision projects. Each phase will have a separate job folder with separate xref's, C3D data files and a sheetset. Our base files will follow a naming convention that includes the unit number. So for unit 1 the base file would be X-BASE-UN01 and so on. In our base files for a given unit, we'll have a file called X-BASE-PREV-UNXX. This will have no data in and of itself, but will contain attached xref's of previous unit base files that need to be shown as existing on the current unit plans. It's essentially a one stop shop so I don't have to go hunting through 4 different job folders to find the previous unit base files every time I set up a new sheet. I'm wanting this LISP routine to do the following: 1. Prompt the user for a path to look for xref's. 2. Prompt the user for the current phase number 3. Prompt the user for previous phase numbers 4. Bring in all dwg files in the supplied location, with the exception of the titleblock, legend base and detail base. 5. Place the xref's on the X-REF layer (and make one if it doesn't exist) and lock it. 6. Analyze the layers in the drawing and change the colors of any layer in an xref that matches the user input for previous phases to 251. Eventually, I'll expand this into several LISP routines and have them do specific layer control for the sheet depending on the discipline (i.e. one for street sheets, one for sewer, one for water one for drainage). That's why I have it asking for the current unit number. But I need to get this basic framework in place first. The code that Copilot is giving me will go through the first three steps just fine but then returns an ;error too few arguments when it comes time to bring in the references. I've pasted the code below. I appreciate any light y'all can shed on this since I know very little about LISP coding or how it works (why I'm trying to use CoPilot to do this). (defun c:BatchXref ( / folder files file skipList fullpath curPhase prevPhases phaseList layerTable layerName xrefParts matched layerEnt layerData) (setq skipList '("X-TTLB.dwg" "X-DETL.dwg" "X-LGND.dwg")) ;; Prompt for folder path using file dialog (setq folder (getfiled "Select any DWG file in target folder" "" "dwg" 8)) (if folder (progn ;; Ensure folder ends with a backslash (setq folder (vl-filename-directory folder)) (if (/= (substr folder (strlen folder)) "\\") (setq folder (strcat folder "\\"))) ;; Prompt for current phase number (setq curPhase (getstring "\nEnter current phase number (e.g., 03): ")) ;; Prompt for previous phase numbers (setq prevPhases (getstring "\nEnter previous phase numbers (comma-separated, e.g., 01,02): ")) (setq phaseList (mapcar (function (lambda (x) (strcase (strcat "X-BASE-UN" x)))) (vl-remove "" (mapcar 'vl-string-trim (vl-string->list (vl-string-translate "," " " prevPhases)))) ) ) ;; Display phase info (princ (strcat "\nCurrent Phase: X-BASE-UN" curPhase)) (princ (strcat "\nPrevious Phases: " (apply 'strcat (mapcar (function (lambda (p) (strcat " " p))) phaseList)))) ;; Create X-REF layer if needed (if (not (tblsearch "LAYER" "X-REF")) (command "_.-LAYER" "_Make" "X-REF" "_Color" "7" "X-REF" "") ) ;; Get DWG files (setq files (vl-directory-files folder "*.dwg" 1)) ;; Insert XREFs (foreach file files (if (not (member (strcase file) (mapcar 'strcase skipList))) (progn (setq fullpath (strcat folder file)) (command "_.-XREF" "_Overlay" fullpath '(0 0 0) 1 1 0) (command "_.CHPROP" "L" "" "_LA" "X-REF" "") ) ) ) ;; Lock the layer (command "_.-LAYER" "_Lock" "X-REF" "") ;; Change color of layers with previous phase names in XREF or nested XREF (setq layerTable (tblnext "LAYER" T)) (while layerTable (setq layerName (cdr (assoc 2 layerTable))) (setq matched nil) ;; Split layer name into parts (XREF nesting) (setq xrefParts (vl-string-split layerName "|")) ;; Check each part for a match with previous phase names (foreach part xrefParts (if (member (strcase part) phaseList) (setq matched T) ) ) ;; If matched, change layer color using entmod (if matched (progn (setq layerEnt (tblobjname "LAYER" layerName)) (if layerEnt (progn (setq layerData (entget layerEnt)) (if (assoc 62 layerData) (setq layerData (subst (cons 62 251) (assoc 62 layerData) layerData)) (setq layerData (append layerData (list (cons 62 251)))) ) (entmod layerData) (entupd layerEnt) ) ) ) ) (setq layerTable (tblnext "LAYER")) ) (princ "\nOverlay XREFs added. Layers in matching XREFs and nested XREFs set to color 251.") ) (princ "\nNo folder selected.") ) (princ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.