Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open drawings in previous format "Read Only"

8 REPLIES 8
Reply
Message 1 of 9
DMFACER
600 Views, 8 Replies

Open drawings in previous format "Read Only"

I know nothing about customization, and am hoping that this is even going in the right group. 

 

I am looking for a way to force all DWG files created with previous versions of AutoCAD to automatically open "Read Only".  For example, using Civil 3D 2011, I open a file that is a 2007 format DWG.  I want this file to automatically open read only, and inform the user that it has opened read only. 

 

I'm hoping that this is possible, since opening a 2007 format DWG in a newer AutoCAD already tells you that it's an older format in the command line, and files can already be opened as read only.  I'm just looking for a way to tie these two together.

 

Anyone out there have any suggestions, ideas, or want to take a stab at creating this?


"The most dangerous phrase in the language is 'We've always done it this way.'" - Rear Admiral Grace Hopper
8 REPLIES 8
Message 2 of 9
pbejse
in reply to: DMFACER

One way

 

(defun c:VerOpen ( / f file version)
  (setq f (getfiled "Select file" "" "dwg" 8))
  (setq	File	(open f "R")
	version	(substr (read-line file) 1 6)
  )
  (close file)
  (vla-activate
    (vla-open (vla-get-documents (vlax-get-acad-object))
	      (findfile f)
	      (if (eq version "AC1024")
		:vlax-false
		:vlax-true
	      )
    )
  )
)

 

Or we can use a reactor? it thats what you need.

 

HTH

 

 

Message 3 of 9
DMFACER
in reply to: pbejse

Thank you for taking the time to respond.  Like I said in my original post, I know nothing about customization, so can you please point me in the right direction of what I should do with this code now that I have it?

 

Thank you.


"The most dangerous phrase in the language is 'We've always done it this way.'" - Rear Admiral Grace Hopper
Message 4 of 9
Patchy
in reply to: DMFACER

Message 5 of 9
pbejse
in reply to: DMFACER


@DMFACER wrote:

Thank you for taking the time to respond.  Like I said in my original post, I know nothing about customization, so can you please point me in the right direction of what I should do with this code now that I have it?

 

Thank you.


Question for you. would you want this to be permanent? no matter where you invoke the open command i.e.

Toolbar

Ctrl S

Command prompt,

 

Short of saying redefining the open command? or will it be use for special cases only?  I cant really tell how newer cad  detects versions, for all i know there might be no need for a lisp code to achive what you want. 

 

so if is indeed "redefining" the open command, you'll be better off  using reactors.

Otherwise save the code (veropen.lsp) <or any other name> and include it on startup suite

Appload...

Contents...

Add...

Browse...

 

You may want to change the routine name to (defun c:VO (.... ) prior to saving the file

 

Or thru acaddoc.lsp, <may need to explain this to you further> or Tutorial

 

HTH

Message 6 of 9
DMFACER
in reply to: pbejse

If possible, we would want to make this permanent, so any user using Open (toolbar, command prompt, etc.).  We are trying to protect old data.  I appreciate your help so far.


"The most dangerous phrase in the language is 'We've always done it this way.'" - Rear Admiral Grace Hopper
Message 7 of 9
southernamp
in reply to: DMFACER

Might I suggest changing the attribute of the files on the server to read-only, so that it is handled as soon as it is opened by AutoCAD automatically. No need for code or anything special, just tag them Read-Only in the directory...

 

Just a thought...

Message 8 of 9
DMFACER
in reply to: southernamp

We work on hundreds of small projects each year, and have the same projects come back to life on a regular basis, so all of our past projects are active on our server (and backed up, obviously).  Going through thousands of projects, identifying which are 2007 format, and which now are 2010 format, and making them all read only would be almost impossible. 

 

I know we're probably asking for the hard way, but we think it's the best way for us right now.


"The most dangerous phrase in the language is 'We've always done it this way.'" - Rear Admiral Grace Hopper
Message 9 of 9
pbejse
in reply to: DMFACER


@DMFACER wrote:

We work on hundreds of small projects each year, and have the same projects come back to life on a regular basis, so all of our past projects are active on our server (and backed up, obviously).  Going through thousands of projects, identifying which are 2007 format, and which now are 2010 format, and making them all read only would be almost impossible. 

 

I know we're probably asking for the hard way, but we think it's the best way for us right now.


southernamp does have a point there,changing the attribute of the files on the server to read-only. that is if you want it permanently as read-only.

 

 But I guess we cant do anything about those files that were 2007 format  and now 2010. unless you use the back-up files

 

As for those still saved at earlier versions buit not yet taggesd as read-only, what we can do is change the attribute to read-only on the fly and make it permanent.

 

I initially thought of using reactors but there's a helluvah of issues that goes with it.

 

So:

(defun CvtoRO	(/ aDoc f File Version fso fle)
  (vl-load-com)
  (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (cond	((and
	   (not	(zerop (strlen (setq f
				      (vla-get-fullname
					aDoc
				      )
			       )
		       )
		)
	   )
	   (eq (vla-get-ReadOnly aDoc) :vlax-false)
	   (progn
	     (setq File	   (open f "R")
		   version (substr (read-line file) 1 6)
	     )
	     (close file)
	     version
	   )
	   (not (eq version "AC1024"))
	   (setq fso (vlax-create-object "Scripting.FileSystemObject"))
	   (setq fle (vlax-invoke fso 'GetFile f))
	   (progn (vlax-put-property fle 'Attributes 33)
		  (vlax-release-object fle)
		  (vlax-release-object fso)
	   )
	   (alert "\nDrawing File is write protected")
	 )
	)
  )
  (princ)
)
(CvtoRO)

 

Now if you looked into the link i posted earlier regarding acaddoc.lsp you will be able to make this work for you,  otherwise

here it is again  Loading Programs Automatically

 

Holler if you need more help

 

HTH

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost