broncos15 Posted September 28, 2015 Share Posted September 28, 2015 I have a quick question about creating a read only code. I know how to create the code to open a read only document, however I am having an issue with modifying it so that the lisp routine will open up windows explorer in the current document's folder. The read only code: (defun c:openReadOnly (/ sel1) (if (setq sel1 (getfiled "Open Drawing" "" "dwg" ) ; (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34)sel1(chr 34)", true" ) ) ) (princ) ) Editing the existing code, but I am having issues with it. (defun c:openReadOnly (/ sel1) (if (setq sel1 (getfiled "Open Drawing" "" "dwg" ) ; (startapp "explorer /e,/select," (strcat (getvar "dwgprefix")(getvar "dwgname") (chr 34)sel1(chr 34)", true" ) ) ) (princ) ) I know that the issue has to do with my startapp function, but I am confused on what I need to change. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted September 28, 2015 Author Share Posted September 28, 2015 My first attempt I made a stupid mistake. However, this is still having issues. (defun c:openReadOnly (/ sel1) (if (setq sel1 (startapp "explorer /e,/select," (strcat (getvar "dwgprefix")(getvar "dwgname"))) (command "vbastmt" (strcat "AcadApplication.Documents.Open" (chr 34)sel1(chr 34)", true" ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 29, 2015 Share Posted September 29, 2015 This is missing a bracket (setq sel1 (startapp "explorer /e,/select," (strcat (getvar "dwgprefix")(getvar "dwgname"))) ) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted September 29, 2015 Share Posted September 29, 2015 Do you need to use VBA? Why not just something like this (vl-load-com) (defun c:demo (/ dwg) (if (setq dwg (getfiled "Open Drawing" (getvar 'dwgprefix) "dwg" 0)) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) (strcat "\"" dwg "\"") :vlax-true) ) ) (princ) ) Henrique Quote Link to comment Share on other sites More sharing options...
broncos15 Posted September 29, 2015 Author Share Posted September 29, 2015 This is missing a bracket (setq sel1 (startapp "explorer /e,/select," (strcat (getvar "dwgprefix")(getvar "dwgname"))) ) BigAl, wow that was a silly mistake, thanks for pointing it out! I am running it now, and it opens up windows explorer in the current drawing's folder. However, when I click on a drawing to open, I get the following message prompt: "OPENREADONLY Initializing VBA System...; error: bad argument type: stringp 33 Expression:" Quote Link to comment Share on other sites More sharing options...
broncos15 Posted September 29, 2015 Author Share Posted September 29, 2015 Do you need to use VBA?Why not just something like this (vl-load-com) (defun c:demo (/ dwg) (if (setq dwg (getfiled "Open Drawing" (getvar 'dwgprefix) "dwg" 0)) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) (strcat "\"" dwg "\"") :vlax-true) ) ) (princ) ) Henrique Henrique, I was using VBA because I knew how to do it within VBA and I am not as good with Visual Lisp. When I uploaded your code I get the error "; error: malformed list on input". I am wanting to get better at Visual Lisp, so I had few questions about your code as well if you don't mind: 1) Why is the (vl-load-com) before the command definition? 2) What does the portion below do exactly? (strcat "\"" dwg "\"") :vlax-true) Quote Link to comment Share on other sites More sharing options...
ROBP Posted September 29, 2015 Share Posted September 29, 2015 Read only file hummmm protected in someway maybe? seen it often when opened from e-mail one could always save it on the desktop or a folder and them open it from there then you can edit..Threfore i do not see the use of a lisp or vba for it Keep me posted and tell me how to achieve such file protection without the use of a password to remove the protection. Best R Quote Link to comment Share on other sites More sharing options...
broncos15 Posted September 29, 2015 Author Share Posted September 29, 2015 I was able to find a code posted in a previous thread that works, however it doesn't make use of the windows explorer. Is there a way to modify it so that it does make use of it? (defun C:OPR (/ fname sd) (or (vl-load-com)) (setq sd (getvar "sdi")) (setvar "sdi" 0) (setq fname (getfiled "Select drawing to open read-only" (getvar "dwgprefix") "dwg" 4) ) (if (vl-catch-all-error-p (vl-catch-all-apply (function (lambda() (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) fname :vlax-true) ) ) ) ) ) (alert "Unable to open in read-only mode") ) (setvar "sdi" sd) (princ) ) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted September 29, 2015 Share Posted September 29, 2015 Henrique, I was using VBA because I knew how to do it within VBA and I am not as good with Visual Lisp. When I uploaded your code I get the error "; error: malformed list on input". I am wanting to get better at Visual Lisp, so I had few questions about your code as well if you don't mind:1) Why is the (vl-load-com) before the command definition? 2) What does the portion below do exactly? (strcat "\"" dwg "\"") :vlax-true) Hi broncos15, the code I posted It should be loaded without error, make sure you copy all the code. (strcat "\"" dwg "\"") is to prevent error with spaces in the file path, will return something like "c:/the/full/path/filename.dwg" The :vlax-true, is from the vla-open function, :vlax-true => read-only :vlax-false => full open Henrique Quote Link to comment Share on other sites More sharing options...
broncos15 Posted September 29, 2015 Author Share Posted September 29, 2015 Hi broncos15,the code I posted It should be loaded without error, make sure you copy all the code. (strcat "\"" dwg "\"") is to prevent error with spaces in the file path, will return something like "c:/the/full/path/filename.dwg" The :vlax-true, is from the vla-open function, :vlax-true => read-only :vlax-false => full open Henrique Henrique, thanks for the information, that is really useful to know. I copied all of your code, but I am still getting the error unfortunately. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted September 29, 2015 Share Posted September 29, 2015 Henrique, thanks for the information, that is really useful to know. You're welcome! I copied all of your code, but I am still getting the error unfortunately. That's weird... Could you please copy/paste your code in the next msg? Henrique Quote Link to comment Share on other sites More sharing options...
broncos15 Posted September 29, 2015 Author Share Posted September 29, 2015 You're welcome! That's weird... Could you please copy/paste your code in the next msg? Henrique I realized what the error was. The last parenthesis wasn't getting copied over correctly, so I was missing a parenthesis. Thank you for the help! Quote Link to comment Share on other sites More sharing options...
hmsilva Posted September 29, 2015 Share Posted September 29, 2015 I realized what the error was. The last parenthesis wasn't getting copied over correctly, so I was missing a parenthesis. Thank you for the help! Glad you got it working. Henrique Quote Link to comment Share on other sites More sharing options...
broncos15 Posted October 1, 2015 Author Share Posted October 1, 2015 Glad you got it working. Henrique Henrique, I actually have one more question haha. So I am trying to make a new lisp routine that makes use of your lisp routine, but acts like the xopen command. Is there an easy way to use the xopen command for opening read only? I have searched online, but I can't find anything so far that is helpful. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted October 1, 2015 Share Posted October 1, 2015 Henrique, I actually have one more question haha. So I am trying to make a new lisp routine that makes use of your lisp routine, but acts like the xopen command. Is there an easy way to use the xopen command for opening read only? I have searched online, but I can't find anything so far that is helpful. Hi broncos15, perhaps something like this (vl-load-com) (defun c:demo (/ blk path sel) (if (and (setq sel (entsel "\nSelect a Xref: ")) (setq blk (vlax-ename->vla-object (car sel))) (vlax-property-available-p blk 'Path) (setq path (vla-get-path blk)) ) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) (strcat "\"" path "\"") :vlax-true) ) ) (princ) ) Hope this helps, Henrique Quote Link to comment Share on other sites More sharing options...
broncos15 Posted October 1, 2015 Author Share Posted October 1, 2015 Henrique, That code works really well. I making sure that I understand how it works correctly: (setq blk (vlax-ename->vla-object (car sel))) ) 1) What exactly does this part do? I know that it is setting the variable blk equal to an attribute from the selection (the sel variable grabbed from entsel), but what exactly is that attribute? I am learning Visual Lisp right now and want to make sure that I understand. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted October 1, 2015 Share Posted October 1, 2015 Henrique, That code works really well. I making sure that I understand how it works correctly: (setq blk (vlax-ename->vla-object (car sel))) ) 1) What exactly does this part do? I know that it is setting the variable blk equal to an attribute from the selection (the sel variable grabbed from entsel), but what exactly is that attribute? I am learning Visual Lisp right now and want to make sure that I understand. (setq blk (vlax-ename->vla-object (car sel))) The variable 'sel' is a list returned from the 'entsel' function, the first element is the entity name of the chosen object 'car' and vlax-ename->vla-object transforms the entity to a VLA-object Henrique Quote Link to comment Share on other sites More sharing options...
broncos15 Posted October 1, 2015 Author Share Posted October 1, 2015 (setq blk (vlax-ename->vla-object (car sel))) The variable 'sel' is a list returned from the 'entsel' function, the first element is the entity name of the chosen object 'car' and vlax-ename->vla-object transforms the entity to a VLA-object Henrique That makes sense, thank you for the information! Thank you as well for all the help, I really appreciate it. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted October 1, 2015 Share Posted October 1, 2015 That makes sense, thank you for the information! Thank you as well for all the help, I really appreciate it. You're welcome, broncos15 Glad I could help Henrique Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 3, 2015 Share Posted October 3, 2015 The brackets are unbalanced like me type too. quick (Strcat "\" "deg" "\" ) 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.