Jump to content

Recommended Posts

Posted (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 by Nikon
Posted

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......)

  • Thanks 1
Posted (edited)

thanks, @Steven P

Unfortunately, nothing has changed...

Whatever the path is, the first open folder opens...

AutoCAD does not see the path...

Edited by Nikon
  • Like 1
Posted

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:\\"))

 

  • Thanks 1
Posted (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 by Nikon
Posted

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\\") "\""))

 

  • Like 1
Posted (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 by Nikon
  • Like 1
Posted (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 by BIGAL
  • Thanks 1
Posted (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 by Nikon
Posted

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"))

 

Posted

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))

 

  • Thanks 1
Posted (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 by Nikon
Posted (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 by Nikon
Posted
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

  • Thanks 1
Posted (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 by pkenewell
  • Like 1
Posted (edited)
18 hours ago, pkenewell said:
(startapp "explorer" "/e,\"C:\\Users\\Username\\Drawings24\\Office3.dwg\"")

@pkenewell

Thanks,  this code opens the dwg file.

Edited by Nikon
Posted (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 by pkenewell
  • Like 1
Posted (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 by Nikon
Posted

@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.

Posted

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 "\".

 

  • Thanks 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...