MikeP Posted May 18, 2012 Share Posted May 18, 2012 I want something like this. Obviously this does not work though and there is a lot im missing. but how can I make it work (defun c:opend ( / dwg1 dwg2 dwg3) (setq dwg1 (C:\Jobs\dwg1.dwg)) (setq dwg2 (C:\Jobs\dwg2.dwg)) (setq dwg3 (C:\Jobs\dwg3.dwg)) (prompt "\nwhat drawing would you like to open?") (command "open" dwg2) Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 18, 2012 Share Posted May 18, 2012 Since you are using an AutoCAD version that still supports VBA: (setq dwg1 "\"C:\\Jobs\\dwg1.dwg\"") (command "_VBASTMT" (strcat "AcadApplication.Documents.Open " dwg1)) But, please keep in mind that each drawing has his own namespace. As general rule, when want to store a path on a variable: [s](setq dwg1 (C:\Jobs\dwg1.dwg))[/s] (setq dwg1 [color=red]"[/color]C:\[color=red]\[/color]Jobs\[color=red]\[/color]dwg1.dwg[color=red]"[/color]) Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 18, 2012 Author Share Posted May 18, 2012 am i getting closer? (defun c:opend ( / dwg1 ) (setq dwg1 "C:\\Jobs\\dwg1.dwg")) ((setq dwg (getkword "\nwhat drawing would you like to open? <>")) (command "_VBASTMT" (strcat "AcadApplication.Documents.Open dwg)) ) Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 18, 2012 Share Posted May 18, 2012 Or, using VisualLISP extension: (vl-load-com) (setq dwg1 "\"C:\\Jobs\\dwg1.dwg\"") (vla-open (vla-get-documents (vla-get-application (vlax-get-acad-object))) "C:\\d1.dwg") Quote Link to comment Share on other sites More sharing options...
MSasu Posted May 18, 2012 Share Posted May 18, 2012 Something like this? Although I'm really not sure what are you looking to achieve by that... (defun c:opend ( / dwgName dwgPath ) (setq dwgPath "C:\\Jobs\\") (initget 1 "DWG1 DWG2 DWG3") (setq dwgName (getkword "\nWhat drawing would you like to open? (Dwg1/Dwg2/Dwg3):")) (setq dwgName (strcat dwgPath "\"" dwgName ".dwg" "\"")) (command "_VBASTMT" (strcat "AcadApplication.Documents.Open " dwgName)) ) You must be more careful with usage of parenthesis! Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 18, 2012 Author Share Posted May 18, 2012 i ave a few drawings I like a access quickly and i figured a list that i can type a nickname would be easiest, rather than opening it using the open box Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 18, 2012 Share Posted May 18, 2012 FWIW - I use this for many commonly opened reference drawings. Can also be used in a toolbar/ribbon button macro. (defun _OpenDwg (dwg readOnly / f oDwg) [color=green];; RenderMan, CADTutor.net ;; Example: (_OpenDwg "[/color][color=red]FilePath[/color][color=green]\\[/color][color=blue]FileName[/color][color=green].dwg" T)[/color] (vl-load-com) (if (and (setq f (findfile dwg)) (/= 1 (getvar 'sdi))) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) f (cond ((= T readOnly) :vlax-true) ((:vlax-false))))) (cond (f (prompt "\n** Command not available in SDI mode ** ")) ((prompt (strcat "\n** \"" (strcase (vl-filename-base dwg)) "\" cannot be found ** "))))) (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 18, 2012 Share Posted May 18, 2012 You can use this to open any file: http://lee-mac.com/open.html Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 18, 2012 Share Posted May 18, 2012 you can use this to open any file or folder: http://lee-mac.com/open.html ... FTFY Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 18, 2012 Share Posted May 18, 2012 Lee - Out of curiosity, how has that code worked with multiple versions (and the whole which version is default scenario)...? I haven't test LM:Open for myself yet, but we've got Land Desktop 2009, Raster Design 2009, Civil 3D 2011, Map 3D 2011, Raster Design 2011, Civil 3D 2012, AMEP 2012, Raster Design 2012 all installed. I'm wondering if the Shell.Application InterfaceObject knows to open the drawing argument with the Active version calling the function or not. Cheers! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 18, 2012 Share Posted May 18, 2012 Lee - Out of curiosity, how has that code worked with multiple versions (and the whole which version is default scenario)...? The behaviour of the Open method of the Shell.Application object I believe is the same as double-clicking the file in Explorer to open it - i.e. it will open with the default application associated with the filetype. Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 24, 2012 Author Share Posted May 24, 2012 FWIW - I use this for many commonly opened reference drawings. Can also be used in a toolbar/ribbon button macro. (defun _OpenDwg (dwg readOnly / f oDwg) [color=green];; RenderMan, CADTutor.net ;; Example: (_OpenDwg "[/color][color=red]FilePath[/color][color=green]\\[/color][color=blue]FileName[/color][color=green].dwg" T)[/color] (vl-load-com) (if (and (setq f (findfile dwg)) (/= 1 (getvar 'sdi))) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) f (cond ((= T readOnly) :vlax-true) ((:vlax-false))))) (cond (f (prompt "\n** Command not available in SDI mode ** ")) ((prompt (strcat "\n** \"" (strcase (vl-filename-base dwg)) "\" cannot be found ** "))))) (princ)) how do i modify this to open the specific dwg i want? I dont see where to enter the file path Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 24, 2012 Share Posted May 24, 2012 (edited) Edited May 24, 2012 by BlackBox Screenshot updated for clarity. Note - only an 'example' Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 24, 2012 Author Share Posted May 24, 2012 [ATTACH=CONFIG]34975[/ATTACH] [ATTACH=CONFIG]34974[/ATTACH] Thanks dick..... only reason I'm confused is because the ;; tells the program to ignore that line...... Obviously im not the best at lisp Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 24, 2012 Author Share Posted May 24, 2012 ^^^ that was sarcastic btw. Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 24, 2012 Author Share Posted May 24, 2012 So I did this. (defun ODwg (dwg readOnly / f oDwg) ;; RenderMan, CADTutor.net ;; Example: (_OpenDwg "S:\Blocks\SBUX Shop Drawings\Countertops\Saved\Temporary Ctop Library\Master Ctop Drawing.dwg" T) (vl-load-com) (if (and (setq f (findfile dwg)) (/= 1 (getvar 'sdi))) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) f (cond ((= T readOnly) :vlax-true) ((:vlax-false))))) (cond (f (prompt "\n** Command not available in SDI mode ** ")) ((prompt (strcat "\n** \"" (strcase (vl-filename-base dwg)) "\" cannot be found ** "))))) (princ)) I enter "_OPENDWG" at the command line And it tells me unknown command Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 24, 2012 Share Posted May 24, 2012 Perhaps I was unclear... _OpenDwg is a sub-function that requires two arguments: dwg - a file (path and/or name) as string readOnly - T or nil In order to call this sub-function from the command line, you must encapsulate the call with parens, like so: (_OpenDwg "S:\\Blocks\\SBUX Shop Drawings\\Countertops\\Saved\\Temporary Ctop Library\\Master Ctop Drawing.dwg" T) ** Note the double back-slashes "\\" The comments (the lines prefixed by ";;" are meant to be useful to you, the user, alone, and are not passed onto the command line, or the VLIDE. A sample macro, for your CUI command could be: ^C^C^P(_OpenDwg "S:\\Blocks\\SBUX Shop Drawings\\Countertops\\Saved\\Temporary Ctop Library\\Master Ctop Drawing.dwg" T)^P HTH Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 24, 2012 Share Posted May 24, 2012 FWIW - The purpose of a sub-function, generally speaking, is to isolate a specific task, or series of (in this case to open a drawing), in order to be used multiple times, sometimes in a row, or sometimes simply to allow the user (in this case you) to feed the sub-function a different parameter (aka argument)... in this instance, the sub-function can perform the same task on any valid drawing file that you supply to the sub-function as an argument. Is this starting to make (more?) sense now...? Quote Link to comment Share on other sites More sharing options...
MikeP Posted May 24, 2012 Author Share Posted May 24, 2012 FWIW - The purpose of a sub-function, generally speaking, is to isolate a specific task, or series of (in this case to open a drawing), in order to be used multiple times, sometimes in a row, or sometimes simply to allow the user (in this case you) to feed the sub-function a different parameter (aka argument)... in this instance, the sub-function can perform the same task on any valid drawing file that you supply to the sub-function as an argument. Is this starting to make (more?) sense now...? Honestly, just barely. *If I enter (_OpenDwg "S:\\Blocks\\SBUX Shop Drawings\\Countertops\\Saved\\Temporary Ctop Library\\Master Ctop Drawing.dwg" T) * into the command line it opens the dwg. *the LISP file does not want to work though The part that I am confused about it, What command do I enter to open this file path? Should typing"_opendwg" open the dwg? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted May 24, 2012 Share Posted May 24, 2012 Okay, let's back up for a moment. If you want to create a LISP Command that can be invoked at the command line by typing in the command name, this is the syntax: ;; Define the function (defun [color=red][b]c:[/b][/color][color=blue]HelloWorld[/color] () (princ "\nHello World! ") (princ) ) Sample command line output: Command: [color=blue]HelloWorld[/color] Hello World! Command: Where the c: prefix (optional) to the Defun function's Symbol argument tells AutoCAD to allow this function to be called from the command line, and HelloWorld is the command that one would type at the command line. Together these are the function's Symbol. This syntax does not accept arguments. By not including the c: prefix, the Defun function's Symbol argument is treated as a sub-function... Something that can accept arguments (optional), and can only be invoked by encapsulating the call within parenthesis (aka parens), like so: ;; Define the sub-function (defun [color=blue]SayIt [/color]( [color=magenta]string [/color]) (prompt [color=magenta]string[/color]) (princ) ) Sample command line output: Command: ([color=blue]SayIt [color=magenta]"\nHello World!"[/color][/color]) Hello World! Command: Note that any Defun can be invoke when encapsulated in parens, like so: Command: ([color=red][b]c:[/b][/color][color=blue]HelloWorld[/color]) Hello World! Command: Now, the _OpenDwg sub-function... The LISP *is* working, and you've successfully called the sub-function with the required arguments. Does any of this help, or are you still lost in a world of [developer] malarkey? Quote Link to comment Share on other sites More sharing options...
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.