Nikon Posted January 31 Posted January 31 (edited) Good day to all! I'm trying to open the folder from the command string: _open C:\Users\Username\Desktop\Drawings24 or _open D:\OBJECTS Whatever the path is, the first open folder opens. Edited February 2 by Nikon Quote
Steven P Posted January 31 Posted January 31 Not sure if this will help you, it opens the current drawings folder: (defun c:GetFolder( / ) ;;opens the current drawing folder (startapp "explorer" (strcat "/e,\"" (vl-string-right-trim "\\" (getvar 'dwgprefix)) "\"")) (princ) ) You can put the file path that you want to use instead of (strcat......) 1 Quote
Nikon Posted January 31 Author Posted January 31 (edited) thanks, @Steven P Unfortunately, nothing has changed... Whatever the path is, the first open folder opens... AutoCAD does not see the path... Edited January 31 by Nikon 1 Quote
lastknownuser Posted January 31 Posted January 31 Maybe this, it opens C drive, you add your folder path, but be sure it is correct, best way is to copy path from file explorer and add correct backslashes (startapp (strcat "EXPLORER /e," "C:\\")) 1 Quote
Nikon Posted January 31 Author Posted January 31 (edited) 2 hours ago, lastknownuser said: (startapp (strcat "EXPLORER /e," "C:\\")) I write it down like this: (startapp (strcat "EXPLORER /e", "C:\Objects24\Drawing77.dwg\)) But nothing happens... In the command string, it appears (("_> Edited January 31 by Nikon Quote
Steven P Posted January 31 Posted January 31 Try this syntax, the code will open windows explorer in the folder you specify. In the file path the \ needs to be double \\, a single \ indicates that the next character is a specail character, so have to be doubled to be a \ (and if you ever want double \\, it is entered as \\\\) Don't need drawing name and file path at the end Got to check that you have the right number of pairs of ", (startapp "explorer" (strcat "/e,\"" (vl-string-right-trim "\\" "C:\\Users\\WhoAmI\\temp\\") "\"")) 1 Quote
Nikon Posted January 31 Author Posted January 31 (edited) On 1/31/2024 at 8:17 PM, Steven P said: (startapp "explorer" (strcat "/e,\"" (vl-string-right-trim "\\" "C:\\Users\\WhoAmI\\temp\\") "\"")) @Steven P Thanks a lot. This code works! This string opens the file .dwg (startapp "explorer" (strcat "/e,\"" (vl-string-right-trim "\\" "D:\\Work24\\Office3.dwg\\") "\"")) Edited February 2 by Nikon 1 Quote
BIGAL Posted January 31 Posted January 31 (edited) Why not just use Getfile you can set a start location like current dwg path, then just use (command "Open" fname). (setq fname (getfiled "Select dwg File" "" "dwg" 16)) (setq fname (getfiled "Select DWG File" (getvar 'dwgprefix) "dwg" 16)) Edited January 31 by BIGAL 1 Quote
Nikon Posted February 1 Author Posted February 1 (edited) @BIGAL Thanks On 2/1/2024 at 2:04 AM, BIGAL said: (setq fname (getfiled "Select dwg File" "" "dwg" 16)) where to add the path to the dwg file and the open command... Edited February 2 by Nikon Quote
Nikon Posted February 1 Author Posted February 1 This is how you can open a DWG file using a macro: ^C^C(startapp "explorer.exe" (findfile "c:/Users/username/Desktop/Drawings24/Office3.dwg")) Quote
lastknownuser Posted February 1 Posted February 1 Put it where PATH HERE is (setq fname (getfiled "Select dwg File" "PATH HERE" "dwg" 16)) (getvar 'dwgprefix) is if you want to open folder where the current drawing in which you are calling lisp is Then open the drawing using this (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) fname)) 1 Quote
Nikon Posted February 1 Author Posted February 1 (edited) 34 minutes ago, lastknownuser said: (setq fname (getfiled "Select dwg File" "PATH HERE" "dwg" 16)) @lastknownuser Thanks, It works... 34 minutes ago, lastknownuser said: (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) fname)) I don't understand the second string... Edited February 1 by Nikon Quote
Nikon Posted February 1 Author Posted February 1 (edited) This code performs the task: (defun c:OpenFolder( / ) ;;opens the drawing folder and the drawing dwg (startapp "explorer" (strcat "/e,\"" (vl-string-right-trim "\\" "C:\\Users\\Username\\Drawings24\\Office3.dwg\\") "\"")) (princ) ) Edited February 1 by Nikon Quote
lastknownuser Posted February 1 Posted February 1 7 minutes ago, Nikon said: @lastknownuser Thanks, It works... I don't understand the second string... vla thing? forgot to add (vl-load-com) before, you need that too, its for using ActiveX methods, read more here: https://help.autodesk.com/view/ACDLT/2024/ENU/?guid=GUID-A0459510-CE7A-4206-9EAA-E25AAB569B20 And if you want to understand more you can google and read about each vla function used (vla-open, vla-activate,...) I use this way of opening drawing by lisp when needed, but I'm sure there are other ways I'd suggest using this method because its faster than opening folder and then opening drawing manually, but its up to you 1 Quote
pkenewell Posted February 1 Posted February 1 (edited) @Nikon You have something unnecessary in there: you manually set the string with the drawing file with a "\\" on the end, which would be invalid for a drawing file path, then strip it off using (vl-string-right-trim)? (startapp "explorer" (strcat "/e,\"" (vl-string-right-trim "\\" "C:\\Users\\Username\\Drawings24\\Office3.dwg\\") "\"")) ;; Could be just this: (startapp "explorer" (strcat "/e,\"" "C:\\Users\\Username\\Drawings24\\Office3.dwg" "\"")) ;; in fact, you don't even need (strcat) if the path is hard-coded: (startapp "explorer" "/e,\"C:\\Users\\Username\\Drawings24\\Office3.dwg\"") Am I missing something? Edited February 1 by pkenewell 1 Quote
Nikon Posted February 1 Author Posted February 1 (edited) 18 hours ago, pkenewell said: (startapp "explorer" "/e,\"C:\\Users\\Username\\Drawings24\\Office3.dwg\"") @pkenewell Thanks, this code opens the dwg file. Edited February 2 by Nikon Quote
pkenewell Posted February 1 Posted February 1 (edited) @Nikon Why not just used the (vla-open) Method? ;; OPENDWG ;; Argument: dwg = string; the full path and file name of the drawing, or just the file name if in the search path. (defun opendwg (dwg) (vl-load-com) (vla-open (vla-get-documents (vlax-get-acad-object)) dwg) ) ;;Test (opendwg "C:\\Users\\Username\\Drawings24\\Office3.dwg") Edited February 2 by pkenewell 1 Quote
Nikon Posted February 1 Author Posted February 1 (edited) 1 hour ago, pkenewell said: ;;Test (opendwg "C:\\Users\\Username\\Drawings24\\Office3.dwg") I'm not a programmer, it's hard for me to evaluate, there are so many options! Thank you for your help! Edited February 1 by Nikon Quote
pkenewell Posted February 1 Posted February 1 @Nikon 39 minutes ago, Nikon said: Thank you for your help! You're welcome! 34 minutes ago, Nikon said: I'm not a programmer, No offense taken or given, but please note that this is a forum for "programmers helping programmers". You will get better help and understanding by learning a little AutoLISP, rather than just requesting free code. Quote
BIGAL Posted February 2 Posted February 2 If you know the name of the dwg why go through all the merry go round stuff. Just open the correct dwg, put in say a menu or use tool palettes, ^c^COpen "C:\\Users\\Username\\Drawings24\\Office3.dwg" Need " if dwg name has spaces else not required and can use a single "\". 1 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.