sean112 Posted July 13, 2016 Posted July 13, 2016 So I designed a Button in DCL and it displays fine. However, I am trying to program it in Autolisp that when I click on the button, it will open a file in my computer. My code is: SVNHRC.dwg (action_tile "b1" "command "_.FILEOPEN"D:\\Typical\\SVNHRC.dwg ") I do not know what is the proper way to pull up a command from autocad. Since you have to use quotation, and we have to use another quotation for the command. Any help guys? Thanks anyone in advance. Quote
Tharwat Posted July 13, 2016 Posted July 13, 2016 You can not use a command call in action_tile so you need to replace it with a function. Quote
Lee Mac Posted July 13, 2016 Posted July 13, 2016 Here is a quick example for you to play with: [color=GREEN];; Open File Example - Lee Mac[/color] [color=GREEN];; www.cadtutor.net/forum/showthread.php?97521[/color] ([color=BLUE]defun[/color] c:myopen ( [color=BLUE]/[/color] dch dcl des idx lst rtn ) ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] dch)) ([color=BLUE]<[/color] 0 dch)) ([color=BLUE]unload_dialog[/color] dch) ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] dcl)) ([color=BLUE]findfile[/color] dcl)) ([color=BLUE]vl-file-delete[/color] dcl) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color]))) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg)) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]cond[/color] ( ([color=BLUE]null[/color] ([color=BLUE]setq[/color] lst ([color=BLUE]vl-directory-files[/color] ([color=BLUE]getvar[/color] 'dwgprefix) [color=BLUE]nil[/color] 1))) ([color=BLUE]princ[/color] [color=MAROON]"\nNo files found in the current directory."[/color]) ) ( ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] dcl ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"myopen.dcl"[/color])) ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] dcl [color=MAROON]"w"[/color])) ([color=BLUE]foreach[/color] str '( [color=MAROON]"mybutt : button"[/color] [color=MAROON]"{"[/color] [color=MAROON]" width = 15;"[/color] [color=MAROON]" height = 3;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" fixed_height = true;"[/color] [color=MAROON]"}"[/color] [color=MAROON]"myopen : dialog"[/color] [color=MAROON]"{"[/color] [color=MAROON]" key = \"dcl\";"[/color] [color=MAROON]" spacer_1;"[/color] [color=MAROON]" : list_box"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"lst\";"[/color] [color=MAROON]" width = 50;"[/color] [color=MAROON]" height = 20;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" fixed_height = true;"[/color] [color=MAROON]" fixed_width_font = true;"[/color] [color=MAROON]" allow_accept = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" spacer;"[/color] [color=MAROON]" : row"[/color] [color=MAROON]" {"[/color] [color=MAROON]" alignment = centered;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" : mybutt"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"accept\";"[/color] [color=MAROON]" label = \"Open\";"[/color] [color=MAROON]" is_default = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" : mybutt"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"cancel\";"[/color] [color=MAROON]" label = \"Exit\";"[/color] [color=MAROON]" is_cancel = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" }"[/color] [color=MAROON]" spacer;"[/color] [color=MAROON]"}"[/color] ) ([color=BLUE]write-line[/color] str des) ) ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des))) ([color=BLUE]<[/color] 0 ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] dcl))) ([color=BLUE]new_dialog[/color] [color=MAROON]"myopen"[/color] dch) ) ) ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to write & load dialog."[/color]) ) ( ([color=BLUE]set_tile[/color] [color=MAROON]"dcl"[/color] [color=MAROON]"Select a File to Open"[/color]) ([color=BLUE]start_list[/color] [color=MAROON]"lst"[/color]) ([color=BLUE]foreach[/color] itm lst ([color=BLUE]add_list[/color] itm)) ([color=BLUE]end_list[/color]) ([color=BLUE]set_tile[/color] [color=MAROON]"lst"[/color] ([color=BLUE]setq[/color] idx [color=MAROON]"0"[/color])) ([color=BLUE]action_tile[/color] [color=MAROON]"lst"[/color] [color=MAROON]"(setq idx $value)"[/color]) ([color=BLUE]setq[/color] rtn ([color=BLUE]start_dialog[/color])) ) ) (*error* [color=BLUE]nil[/color]) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 rtn) (LM:open ([color=BLUE]strcat[/color] ([color=BLUE]getvar[/color] 'dwgprefix) ([color=BLUE]nth[/color] ([color=BLUE]atoi[/color] idx) lst))) ) ([color=BLUE]princ[/color]) ) [color=GREEN];; Open - Lee Mac[/color] [color=GREEN];; A wrapper for the 'Open' method of the Shell Object[/color] [color=GREEN];; target - [int/str] File, folder or ShellSpecialFolderConstants enum[/color] ([color=BLUE]defun[/color] LM:open ( target [color=BLUE]/[/color] rtn shl ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]or[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] target)) ([color=BLUE]setq[/color] target ([color=BLUE]findfile[/color] target))) ([color=BLUE]setq[/color] shl ([color=BLUE]vla-getinterfaceobject[/color] ([color=BLUE]vlax-get-acad-object[/color]) [color=MAROON]"shell.application"[/color])) ) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] rtn ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vlax-invoke[/color] ([color=BLUE]list[/color] shl '[color=BLUE]open[/color] target))) ([color=BLUE]vlax-release-object[/color] shl) ([color=BLUE]if[/color] ([color=BLUE]vl-catch-all-error-p[/color] rtn) ([color=BLUE]prompt[/color] ([color=BLUE]vl-catch-all-error-message[/color] rtn)) [color=BLUE]t[/color] ) ) ) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) The above uses my Open function. Quote
sean112 Posted July 13, 2016 Author Posted July 13, 2016 Thanks Lee Mac, I do not know if the last reply went out or not. But this is a brilliant program. However, for my program specifically, I already know what file I wanted to open before I click the button, since I already sorted the options out from former menus. Thus, I just need to open a certain dwg file in the certain location. I tried something like this: (action_tile "b1" "(OPFL)") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun OPFL () (command "_.FILEOPEN" "D:\\Typical\\Template") ) Autocad froze every time when I click the button. Sorry for the long extra question, Thanks. Quote
Lee Mac Posted July 13, 2016 Posted July 13, 2016 Thanks Lee Mac,I do not know if the last reply went out or not. But this is a brilliant program. Thank you. However, for my program specifically,I already know what file I wanted to open before I click the button, since I already sorted the options out from former menus. Thus, I just need to open a certain dwg file in the certain location. I tried something like this: (action_tile "b1" "(OPFL)") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun OPFL () (command "_.FILEOPEN" "D:\\Typical\\Template") ) Autocad froze every time when I click the button. As per my example above, you should evaluate the expression to open your file outside of the action_tile statement for your dialog tile, and after the dialog has been dismissed. Since DCL dialogs are modal, AutoCAD cannot take focus whilst the dialog is displayed and will therefore freeze if attempting to evaluate a command without first dismissing the dialog. Quote
BrianTFC Posted July 14, 2016 Posted July 14, 2016 I didn't write this but works great. ;;; Opens the Architectural Standard details file. (defun c:OpenMySTD ( / _OpenDwg ) (vl-load-com) (defun _OpenDwg (dwg readOnly / doc) ;; BlackBox... Inspired by RenderMan, CADTutor.net ;; Example: (_OpenDwg "FilePath\\FileName.dwg" T) ;; Return: T, if successful; otherwise nil. (and (not (vl-catch-all-error-p (setq doc (vl-catch-all-apply 'vla-open (list (vla-get-documents (vlax-get-acad-object)) dwg (if readOnly :vlax-true :vlax-false ) ) ) ) ) ) (not (vla-activate doc)) ) ) (_OpenDwg "F:\\name of folder\\drawing name.DWG" [color=red][b];;; you need to change this line to where the file is that you want open.[/b][/color] T) (princ)) Quote
rkmcswain Posted July 14, 2016 Posted July 14, 2016 Since DCL dialogs are modal, AutoCAD cannot take focus whilst the dialog is displayed and will therefore freeze if attempting to evaluate a command without first dismissing the dialog. Well said, sir! Quote
sean112 Posted July 14, 2016 Author Posted July 14, 2016 I have a follow up question, before you define LM:open, you wrote: (setq rtn (start_dialog)) Does it run the dialog and give an return value? and does it effect the function LM:open? Thank you! Quote
Lee Mac Posted July 14, 2016 Posted July 14, 2016 you wrote:(setq rtn (start_dialog)) Does it run the dialog and give an return value? and does it effect the function LM[noparse]:open?[/noparse] Yes, per the documentation for start_dialog: The start_dialog function returns the optional status passed to done_dialog. The default value is 1 if the user presses OK, 0 if the user presses Cancel, or -1 if all dialog boxes are terminated with term_dialog. If done_dialog is passed an integer status greater than 1, start_dialog returns this value, whose meaning is determined by the application.There is a conditional statement at the end of the function definition for c:myopen which ensures [noparse]LM:open[/noparse] is only evaluated with the selected filename if rtn=1. Quote
Lee Mac Posted July 14, 2016 Posted July 14, 2016 Here is a simplified version: [color=GREEN];; Open File Example - Lee Mac[/color] [color=GREEN];; www.cadtutor.net/forum/showthread.php?97521[/color] ([color=BLUE]defun[/color] c:myopen ( [color=BLUE]/[/color] dch dcl des dfn dwg rtn ) ([color=BLUE]setq[/color] dfn [color=MAROON]"D:\\Typical\\SVNHRC.dwg"[/color]) [color=GREEN];; File to open[/color] ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] dch)) ([color=BLUE]<[/color] 0 dch)) ([color=BLUE]unload_dialog[/color] dch) ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] dcl)) ([color=BLUE]findfile[/color] dcl)) ([color=BLUE]vl-file-delete[/color] dcl) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color]))) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg)) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]cond[/color] ( ([color=BLUE]not[/color] ([color=BLUE]setq[/color] dwg ([color=BLUE]findfile[/color] dfn))) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] dfn [color=MAROON]" not found."[/color])) ) ( ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] dcl ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"myopen.dcl"[/color])) ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] dcl [color=MAROON]"w"[/color])) ([color=BLUE]foreach[/color] str '( [color=MAROON]"mybutt : button"[/color] [color=MAROON]"{"[/color] [color=MAROON]" width = 15;"[/color] [color=MAROON]" height = 3;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" fixed_height = true;"[/color] [color=MAROON]"}"[/color] [color=MAROON]"myopen : dialog"[/color] [color=MAROON]"{"[/color] [color=MAROON]" key = \"dcl\";"[/color] [color=MAROON]" spacer;"[/color] [color=MAROON]" : row"[/color] [color=MAROON]" {"[/color] [color=MAROON]" alignment = centered;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" : mybutt"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"accept\";"[/color] [color=MAROON]" label = \"Open\";"[/color] [color=MAROON]" is_default = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" : mybutt"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"cancel\";"[/color] [color=MAROON]" label = \"Exit\";"[/color] [color=MAROON]" is_cancel = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" }"[/color] [color=MAROON]" spacer;"[/color] [color=MAROON]"}"[/color] ) ([color=BLUE]write-line[/color] str des) ) ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des))) ([color=BLUE]<[/color] 0 ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] dcl))) ([color=BLUE]new_dialog[/color] [color=MAROON]"myopen"[/color] dch) ) ) ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to write & load dialog."[/color]) ) ( ([color=BLUE]set_tile[/color] [color=MAROON]"dcl"[/color] [color=MAROON]"Click to Open the File"[/color]) ([color=BLUE]setq[/color] rtn ([color=BLUE]start_dialog[/color])) ) ) (*error* [color=BLUE]nil[/color]) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 rtn) (LM:open dwg)) ([color=BLUE]princ[/color]) ) [color=GREEN];; Open - Lee Mac[/color] [color=GREEN];; A wrapper for the 'Open' method of the Shell Object[/color] [color=GREEN];; target - [int/str] File, folder or ShellSpecialFolderConstants enum[/color] ([color=BLUE]defun[/color] LM:open ( target [color=BLUE]/[/color] rtn shl ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]or[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] target)) ([color=BLUE]setq[/color] target ([color=BLUE]findfile[/color] target))) ([color=BLUE]setq[/color] shl ([color=BLUE]vla-getinterfaceobject[/color] ([color=BLUE]vlax-get-acad-object[/color]) [color=MAROON]"shell.application"[/color])) ) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] rtn ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vlax-invoke[/color] ([color=BLUE]list[/color] shl '[color=BLUE]open[/color] target))) ([color=BLUE]vlax-release-object[/color] shl) ([color=BLUE]if[/color] ([color=BLUE]vl-catch-all-error-p[/color] rtn) ([color=BLUE]prompt[/color] ([color=BLUE]vl-catch-all-error-message[/color] rtn)) [color=BLUE]t[/color] ) ) ) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote
Tripledot Posted July 15, 2016 Posted July 15, 2016 Can have option to open other predefined (added) drawings within this lisp? eg. myopen1 open A.dwg myopen2 open B.dwg Here is a simplified version: [color=GREEN];; Open File Example - Lee Mac[/color] [color=GREEN];; www.cadtutor.net/forum/showthread.php?97521[/color] ([color=BLUE]defun[/color] c:myopen ( [color=BLUE]/[/color] dch dcl des dfn dwg rtn ) ([color=BLUE]setq[/color] dfn [color=MAROON]"D:\\Typical\\SVNHRC.dwg"[/color]) [color=GREEN];; File to open[/color] ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] dch)) ([color=BLUE]<[/color] 0 dch)) ([color=BLUE]unload_dialog[/color] dch) ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'file ([color=BLUE]type[/color] des)) ([color=BLUE]close[/color] des) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] dcl)) ([color=BLUE]findfile[/color] dcl)) ([color=BLUE]vl-file-delete[/color] dcl) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] msg ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg [color=BLUE]t[/color]) [color=MAROON]"*break,*cancel*,*exit*"[/color]))) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg)) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]cond[/color] ( ([color=BLUE]not[/color] ([color=BLUE]setq[/color] dwg ([color=BLUE]findfile[/color] dfn))) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\n"[/color] dfn [color=MAROON]" not found."[/color])) ) ( ([color=BLUE]not[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] dcl ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"myopen.dcl"[/color])) ([color=BLUE]setq[/color] des ([color=BLUE]open[/color] dcl [color=MAROON]"w"[/color])) ([color=BLUE]foreach[/color] str '( [color=MAROON]"mybutt : button"[/color] [color=MAROON]"{"[/color] [color=MAROON]" width = 15;"[/color] [color=MAROON]" height = 3;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" fixed_height = true;"[/color] [color=MAROON]"}"[/color] [color=MAROON]"myopen : dialog"[/color] [color=MAROON]"{"[/color] [color=MAROON]" key = \"dcl\";"[/color] [color=MAROON]" spacer;"[/color] [color=MAROON]" : row"[/color] [color=MAROON]" {"[/color] [color=MAROON]" alignment = centered;"[/color] [color=MAROON]" fixed_width = true;"[/color] [color=MAROON]" : mybutt"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"accept\";"[/color] [color=MAROON]" label = \"Open\";"[/color] [color=MAROON]" is_default = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" : mybutt"[/color] [color=MAROON]" {"[/color] [color=MAROON]" key = \"cancel\";"[/color] [color=MAROON]" label = \"Exit\";"[/color] [color=MAROON]" is_cancel = true;"[/color] [color=MAROON]" }"[/color] [color=MAROON]" }"[/color] [color=MAROON]" spacer;"[/color] [color=MAROON]"}"[/color] ) ([color=BLUE]write-line[/color] str des) ) ([color=BLUE]not[/color] ([color=BLUE]setq[/color] des ([color=BLUE]close[/color] des))) ([color=BLUE]<[/color] 0 ([color=BLUE]setq[/color] dch ([color=BLUE]load_dialog[/color] dcl))) ([color=BLUE]new_dialog[/color] [color=MAROON]"myopen"[/color] dch) ) ) ([color=BLUE]princ[/color] [color=MAROON]"\nUnable to write & load dialog."[/color]) ) ( ([color=BLUE]set_tile[/color] [color=MAROON]"dcl"[/color] [color=MAROON]"Click to Open the File"[/color]) ([color=BLUE]setq[/color] rtn ([color=BLUE]start_dialog[/color])) ) ) (*error* [color=BLUE]nil[/color]) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 rtn) (LM:open dwg)) ([color=BLUE]princ[/color]) ) [color=GREEN];; Open - Lee Mac[/color] [color=GREEN];; A wrapper for the 'Open' method of the Shell Object[/color] [color=GREEN];; target - [int/str] File, folder or ShellSpecialFolderConstants enum[/color] ([color=BLUE]defun[/color] LM:open ( target [color=BLUE]/[/color] rtn shl ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]or[/color] ([color=BLUE]=[/color] 'int ([color=BLUE]type[/color] target)) ([color=BLUE]setq[/color] target ([color=BLUE]findfile[/color] target))) ([color=BLUE]setq[/color] shl ([color=BLUE]vla-getinterfaceobject[/color] ([color=BLUE]vlax-get-acad-object[/color]) [color=MAROON]"shell.application"[/color])) ) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] rtn ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vlax-invoke[/color] ([color=BLUE]list[/color] shl '[color=BLUE]open[/color] target))) ([color=BLUE]vlax-release-object[/color] shl) ([color=BLUE]if[/color] ([color=BLUE]vl-catch-all-error-p[/color] rtn) ([color=BLUE]prompt[/color] ([color=BLUE]vl-catch-all-error-message[/color] rtn)) [color=BLUE]t[/color] ) ) ) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote
Lee Mac Posted July 15, 2016 Posted July 15, 2016 Sure - without DCL the code can be simply: (defun c:open1 nil (LM:open "C:\\YourDrawing1.dwg") (princ)) (defun c:open2 nil (LM:open "C:\\YourDrawing2.dwg") (princ)) (defun c:open3 nil (LM:open "C:\\YourDrawing3.dwg") (princ)) ;; Open - Lee Mac ;; A wrapper for the 'Open' method of the Shell Object ;; target - [int/str] File, folder or ShellSpecialFolderConstants enum (defun LM:open ( target / rtn shl ) (if (and (or (= 'int (type target)) (setq target (findfile target))) (setq shl (vla-getinterfaceobject (vlax-get-acad-object) "shell.application")) ) (progn (setq rtn (vl-catch-all-apply 'vlax-invoke (list shl 'open target))) (vlax-release-object shl) (if (vl-catch-all-error-p rtn) (prompt (vl-catch-all-error-message rtn)) t ) ) ) ) (vl-load-com) (princ) Quote
Tripledot Posted July 15, 2016 Posted July 15, 2016 Thanks Lee Mac. Sure - without DCL the code can be simply: (defun c:open1 nil (LM:open "C:\\YourDrawing1.dwg") (princ)) (defun c:open2 nil (LM:open "C:\\YourDrawing2.dwg") (princ)) (defun c:open3 nil (LM:open "C:\\YourDrawing3.dwg") (princ)) ;; Open - Lee Mac ;; A wrapper for the 'Open' method of the Shell Object ;; target - [int/str] File, folder or ShellSpecialFolderConstants enum (defun LM:open ( target / rtn shl ) (if (and (or (= 'int (type target)) (setq target (findfile target))) (setq shl (vla-getinterfaceobject (vlax-get-acad-object) "shell.application")) ) (progn (setq rtn (vl-catch-all-apply 'vlax-invoke (list shl 'open target))) (vlax-release-object shl) (if (vl-catch-all-error-p rtn) (prompt (vl-catch-all-error-message rtn)) t ) ) ) ) (vl-load-com) (princ) Quote
sean112 Posted July 15, 2016 Author Posted July 15, 2016 Here is a simplified version: Thank you, sir. I am still trying to understand the code, but it works perfectly. Quote
BIGAL Posted July 16, 2016 Posted July 16, 2016 Another way to look at it using a DCl with say a list box containing A B C D pick B you want to open "Drawing2" so after running the DCL you just need to set the name for the filename the (LM:OPEN TARGET / rtn shell) the value of Target is set to "Drawing2" something like this (cond ((= picked "A")(LM:open "C:\\YourDrawing1.dwg")) ((= picked "B")(LM:open "C:\\YourDrawing2.dwg")) .... .... ) Quote
sean112 Posted July 17, 2016 Author Posted July 17, 2016 As per my example above, you should evaluate the expression to open your file outside of the action_tile statement for your dialog tile, and after the dialog has been dismissed. Since DCL dialogs are modal, AutoCAD cannot take focus whilst the dialog is displayed and will therefore freeze if attempting to evaluate a command without first dismissing the dialog. (action_tile "accept" "(setq Project_Manager (get_tile \"name\")") (print Project_Manager) (setq p1 '(604 88.2)) (command "_text" p1 1 0 Project_Manager "") In this case, why is it still not considered have the command outside of the action_tile? Thanks Quote
Roy_043 Posted July 17, 2016 Posted July 17, 2016 Let's first correct a syntax error: A closing parenthesis is missing here: (action_tile "accept" "(setq Project_Manager (get_tile \"name\")") It should be: (action_tile "accept" "(setq Project_Manager (get_tile \"name\"))") Quote
Lee Mac Posted July 17, 2016 Posted July 17, 2016 Thank you, sir. I am still trying to understand the code, but it works perfectly. Excellent - you're welcome. (action_tile "accept" "(setq Project_Manager (get_tile \"name\")") (print Project_Manager) (setq p1 '(604 88.2)) (command "_text" p1 1 0 Project_Manager "") In this case, why is it still not considered have the command outside of the action_tile? Your expressions to perform operations in AutoCAD will need to be evaluated after the start_dialog expression. The process is as follows: load_dialog loads the contents of a DCL file into memory; the contents may define one or more modal dialogs. new_dialog displays the modal dialog corresponding to the dialog definition of the given name, defined within the loaded DCL file. set_tile/mode_tile expressions may be used to configure the various DCL tiles. action_tile statements define a set of expressions that are to be evaluated when the user interacts with the DCL tile with the given key. done_dialog may be evaluated to dismiss the displayed dialog and will return the position of the dialog when dimissed. start_dialog allows the user to interact with the displayed dialog after processing all set_tile/mode_tile/action_tile statements to configure the behaviour of the dialog. This function will return the integer supplied by the done_dialog function. As such, the dialog won't be displayed and cannot be configured until the new_dialog function is evaluated, but the displayed dialog is not operational until the start_dialog function is evaluated - therefore, if your code were to evaluate the new_dialog expression without a corresponding start_dialog expression, the modal dialog would be displayed but would not be able to be dismissed (AutoCAD must in terminated in this scenario). 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.