Paul Li Posted Sunday at 05:09 PM Posted Sunday at 05:09 PM Attached is an improved version of getfiled that implements powershell with the option to select single or multiple files returning a list of the selected item(s): Examples: (pl:getfiledps "Select Files" (getvar"dwgprefix") "dwg" 0) ; for single selection of file type dwg (pl:getfiledps "Select Files" (strcat (getenv "userprofile") "\\downloads") "dwg;dxf" 1) ; for multiple selection of file types dwg & dxf Feedback & comments are welcome. pl_getfiledps.lsp 5 Quote
SLW210 Posted Monday at 11:40 AM Posted Monday at 11:40 AM Many work computers are likely limited for using Powershell. Unrelated to Powershell being blocked, I get an error loading. error: string too long on input Quote
Steven P Posted Monday at 12:06 PM Posted Monday at 12:06 PM String too long - just a guess, file path and file name string length? - going back old school when we had 256? characters for it all - but just a guess Quote
SLW210 Posted Monday at 12:28 PM Posted Monday at 12:28 PM I'm not going to troubleshoot it since Powershell is blocked at work, but if the load has that error, then it's something in the Code, probable in the DCL write-line part. 1 Quote
Paul Li Posted Monday at 09:11 PM Author Posted Monday at 09:11 PM Thanks for troubleshooting. That could definitely be caused by having a write-line statement that's way too long. I've made the changes to reduce the write-line on the dcl. Kindly troubleshoot some more for offices that do allow for running powershell with the attached revised version...thanks in advance. pl_getfiledps.lsp Quote
GLAVCVS Posted Monday at 11:43 PM Posted Monday at 11:43 PM (edited) One observation: in older versions of AutoCAD (2000 and 2002, at least), 'vla-get-HWND' applies to the Document object rather than the Acad object. Edited Monday at 11:45 PM by GLAVCVS 1 Quote
BIGAL Posted Monday at 11:49 PM Posted Monday at 11:49 PM (edited) Works great often do old fashioned DOS to get file names list or use the VL files functions. A suggestion remove "result" from the local variables list. As the answer disappears. Or ; Example: ; (setq files (pl:getfiledps "Select Files" (getvar"dwgprefix") "dwg" 1)) A side comment I have used Powershell with Bricscad and sometimes does not work. Your code may help as you do a deeper dive into running Powershell. I generally only do a "Power shell and script" I have used it to change programs, I jump to Excel from CAD. Edited Monday at 11:51 PM by BIGAL 1 Quote
Paul Li Posted Tuesday at 04:48 PM Author Posted Tuesday at 04:48 PM On 9/14/2026 at 5:28 AM, SLW210 said: I'm not going to troubleshoot it since Powershell is blocked at work, but if the load has that error, then it's something in the Code, probable in the DCL write-line part. Could you test if this PowerShell-p function would return nil on your powershell blocked computers? ; PowerShell-p function to check if powershell is available to run...Returns T if available (defun PowerShell-p (/ shell result) (setq shell (vlax-create-object "WScript.Shell") result (vl-catch-all-apply 'vlax-invoke-method (list shell 'Run "powershell.exe -NoProfile -Command \"exit 0\"" 0 T)) ) (vlax-release-object shell) (and (not (vl-catch-all-error-p result)) (= result 0) ) ) Quote
Paul Li Posted Tuesday at 04:49 PM Author Posted Tuesday at 04:49 PM 17 hours ago, GLAVCVS said: One observation: in older versions of AutoCAD (2000 and 2002, at least), 'vla-get-HWND' applies to the Document object rather than the Acad object. so does the pl:getfiledps function still run properly on those older AutoCAD versions? Quote
SLW210 Posted Tuesday at 09:35 PM Posted Tuesday at 09:35 PM 21 hours ago, GLAVCVS said: One observation: in older versions of AutoCAD (2000 and 2002, at least), 'vla-get-HWND' applies to the Document object rather than the Acad object. 4 hours ago, Paul Li said: so does the pl:getfiledps function still run properly on those older AutoCAD versions? Yes, I was working on that for my home computer with 2000i. Since I had some home time today with AutoCAD 2000i, I did some updating to your code. Seems to work great with minimal testing. Here is my Test Code... ; ================================================================ ; Test command ; ================================================================ (defun c:SelectDWGs (/ files) (setq files (pl:getfiledps "Select DWG Files" (getvar "DWGPREFIX") "dwg" 1 ) ) (if files (progn (princ "\nSelected files:" ) (foreach file files (princ (strcat "\n" file ) ) ) ) (princ "\nNo files selected." ) ) (princ) ) pl_getfiledps_2000i.lsp 3 Quote
Paul Li Posted Tuesday at 10:27 PM Author Posted Tuesday at 10:27 PM @SLW210 Your revised version works beautifully and can now support older versions of AutoCAD...thanks a bunch!!! Quote
GLAVCVS Posted Wednesday at 02:47 PM Posted Wednesday at 02:47 PM (edited) 22 hours ago, Paul Li said: so does the pl:getfiledps function still run properly on those older AutoCAD versions? Yes: as @SLW210 says, it seems to work well. On the other hand: Have you considered having the script written only if it does not already exist in the expected directory, and keeping PowerShell running from the initial load? This would make the dialog box load faster on subsequent calls. In this regard, the script check/creation could be done when the code is loaded. This would also improve the speed of the first execution slightly. Edited Wednesday at 02:51 PM by GLAVCVS 1 Quote
Paul Li Posted Wednesday at 07:15 PM Author Posted Wednesday at 07:15 PM @GLAVCVS thanks for the feedback. I assume to use a single Powershell session you would have to run a batch file that launches Powershell first before starting autocad? Then when autocad closes or crashes out that session of Powershell also closes. 1 Quote
SLW210 Posted yesterday at 10:44 AM Posted yesterday at 10:44 AM I added a note in the file where to change to keep PowerShell open. ; ---------------------------------------------------------- ; Wait until PowerShell finishes. ; ---------------------------------------------------------- (vlax-invoke-method shell "Run" cmd 0 ; <=== Change 0 to 1 if you want PowerShell to stay open. :vlax-true ) (vlax-release-object shell) ) ) I was running some tests at work to see if there was a method to determine if PowerShell was blocked to give a message... (princ "\nPowerShell access is blocked.") (princ "\nPowerShell access is allowed.")) Right now all I get on the commandline is... error: Automation Error. Description was not provided. Though I had to get to some of my "paid to do" work done yesterday. This is probably above my pay grade. I just realized who the OP is, a big time Guru over at Autodesk forums and AUGI. 2 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.