Jump to content

Open read only


broncos15

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • broncos15

    13

  • hmsilva

    9

  • BIGAL

    2

  • ROBP

    1

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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