Jump to content
Ahankhah

How to control OPEN command via reactors?

Recommended Posts

Ahankhah

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

Share this post


Link to post
Share on other sites
SOliver

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

Share this post


Link to post
Share on other sites
BlackBox

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.

Share this post


Link to post
Share on other sites
Ahankhah
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.

Share this post


Link to post
Share on other sites
Ahankhah
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?

Share this post


Link to post
Share on other sites
BlackBox
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.

Share this post


Link to post
Share on other sites
Ahankhah

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

I appreciate greatly your help. :D

Share this post


Link to post
Share on other sites
BlackBox
Thank you very much RenderMan, it really helps. :)

 

You're welcome. :)

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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