Ahankhah Posted November 17, 2011 Posted November 17, 2011 Hi CADmates, as most of you know, CommandWillStart and CommandEnded are two reactors triggered just when a command called and a command ended. I am looking for a way to control OPEN command after selecting a drawing and before actually OPENing it. Is this mission possible? Any suggestions and help greatly appreciated. Quote
SOliver Posted November 17, 2011 Posted November 17, 2011 Instead of using the "open" command you could create a function containing something similar to this setq filePath (getfiled "Select file" "" "dwg" ) That way you'll only return the file path, allowing you to do whatever you want prior to opening the file. Hope this helps Quote
BlackBox Posted November 17, 2011 Posted November 17, 2011 Ahankhah - Please clarify... I am not understanding what you want to do to a drawing, prior to opening it? SOliver - Unfortunately GETFILED does not make available one's saved shortcuts (the links to the left side of the standard OPEN dialog), nor does it "remember" last opened directory (without additional coding, perhaps using GETENV/SETENV?), which is why I too use reactors with standard OPEN, XATTACH, etc. commands. However, in newer versions of AutoCAD though, I had to modify my code to include a preceding (INITDIA) in order to force the dialog version of certain commands. Quote
Ahankhah Posted November 17, 2011 Author Posted November 17, 2011 Instead of using the "open" command you could create a function containing something similar to this setq filePath (getfiled "Select file" "" "dwg" ) That way you'll only return the file path, allowing you to do whatever you want prior to opening the file. Hope this helps SOliver, thank you very much for your suggestion, but changing OPEN command doesn't affect .OPEN (internal ommand), so any code invoking "_.OPN" or ".OPEN" will bypass my way of catching files to be opened. Quote
Ahankhah Posted November 17, 2011 Author Posted November 17, 2011 Ahankhah - Please clarify... I am not understanding what you want to do to a drawing, prior to opening it? RenderMan, I want to: 1- Find out if the drawing is read-only. 2- In some cases (depending on the log-in (user)'s name) open it without any message as read-only, even if it is not actualy read-only. 3- For some condions open it as AutoCAD does. I hope it is clear enough? Quote
BlackBox Posted November 17, 2011 Posted November 17, 2011 RenderMan, I want to:1- Find out if the drawing is read-only. 2- In some cases (depending on the log-in (user)'s name) open it without any message as read-only, even if it is not actualy read-only. 3- For some condions open it as AutoCAD does. I hope it is clear enough? Yes, that is very helpful. Unfortunately, given what conditional steps you've outlined, you will have to use the GETFILED option. Here's a small example, which incorporates Lee's _FileOpen-p function to determine read-only status: (defun c:FOO (/ _FileOpen-p _Open f) (princ "\rFOO ") (vl-load-com) (defun _FileOpen-p (fileName / f) ;; Lee Mac, 2011 ;; filename = filename of file to test ;; Returns T if specified file is open (if (setq f (open fileName "a")) (close f) T)) (defun _Open (acApp f o) (vla-activate (vla-open (vla-get-documents acApp) f o))) (if (setq f (getfiled "Select file" "" "dwg" ) ((lambda (acApp user / s) (cond ;; If user is a member, open read-only ((vl-position user '([color=red]"user1" "user2" "user3"[/color])) (_Open acApp f :vlax-true)) ;; If available, open normally, else open read-only ((if (_FileOpen-p f) (progn (alert "File is already open. ") (_Open acApp f :vlax-true)) (_Open acApp f :vlax-false))))) (vlax-get-acad-object) (getvar 'loginname))) (princ)) Hope this helps! ** Edit - Also be aware of GETFILED's behavior when selecting a drawing that is located within (getvar 'dwgprefix), as you will need to add the active directory using STRCAT. Quote
Ahankhah Posted November 18, 2011 Author Posted November 18, 2011 Unfortunately, given what conditional steps you've outlined, you will have to use the GETFILED option. Here's a small example, which incorporates Lee's _FileOpen-p function to determine read-only status: ... . . . Hope this helps! ** Edit - Also be aware of GETFILED's behavior when selecting a drawing that is located within (getvar 'dwgprefix), as you will need to add the active directory using STRCAT. Thank you very much RenderMan, it really helps. Lee, as always, you have answers to any kind of problem in AutoCAD coding. I appreciate greatly your help. Quote
BlackBox Posted November 18, 2011 Posted November 18, 2011 Thank you very much RenderMan, it really helps. You're welcome. 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.