Author Topic: Open read-only with code ...  (Read 4148 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Open read-only with code ...
« on: August 05, 2010, 07:22:04 PM »
Is there a way to use code to run the 'open drawing' dialog box BUT open a selected file 'read-only' ??

Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

kpblc

  • Bull Frog
  • Posts: 396
Re: Open read-only with code ...
« Reply #1 on: August 06, 2010, 08:09:40 AM »
Code: [Select]
(vla-open (vla-get-documents (vlax-get-acad-object)) FileName :vlax-true)
Sorry for my English.

JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: Open read-only with code ...
« Reply #2 on: August 06, 2010, 09:08:02 AM »
To expand on what kpblc has offered, here is the dialog box part.

I hope this helps.

Code: [Select]
(vla-open
   (vla-get-documents (vlax-get-acad-object))
   (getfiled "Select Drawing" "" "dwg" 0) :vlax-true)
   

Now for my questions:
Does two (2) question marks mean this is a hypothetical question?
Where was "open drawing"  and "read-only" previously mentioned?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Open read-only with code ...
« Reply #3 on: August 06, 2010, 10:04:21 AM »

oh,oh Hangman is in trouble  :police:

 :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Open read-only with code ...
« Reply #4 on: August 06, 2010, 02:12:35 PM »
 :-D

Hangman

  • Swamp Rat
  • Posts: 566
Re: Open read-only with code ...
« Reply #5 on: August 09, 2010, 11:17:45 AM »

oh,oh Hangman is in trouble  :police:

 :-)

You know, I've always learn't by examples.  I guess that's why after a few times in the slammer for jay walk'n and talk'n back to the officer, I finally learn't that call'n the guy a 'putz' doesn't get you any browny points with the enforcer, but the judge is certainly enjoying the entertainment.    ^-^


< ... >
Now for my questions:
Does two (2) question marks mean this is a hypothetical question?
Where was "open drawing"  and "read-only" previously mentioned?

Well, ...  now you've done it !!!   Gone an open'd a box a worms (although this is the most enjoyable part for the judge, the explanations.  He sais I can come up with some good ones).    ;-)

Alright, first of all, the two question marks:
I use to use three (3), but then I'd end up with this  ???  icon.  Didn't work very well when asking questions, seriously.
But I get ahead of myself, so lemme back up a bit.  Have you ever had a question that ended in a seven (no pun intended) ?7?7?   :-D
For some reason, there seems to be some confusion as to whether I'm making statements or simply trying to irritate someone.  So I started using the tripple question marks to show I'm asking a question.  As you can see, with three you get an icon, so I had to revert to two.  So that way everyone can see that the post I put out there is a question, not a statement!  Otherwise people start asking me silly questions like, "what do you mean by 'statementi'?".  And then there's the next person who'd post to the effect of "you've gotta go learn how to spell, ... what is this 'statementi?' crap and what does it mean?"  And so you return trying to smooth things over by explaining in some long drawnout post that it wasn't 'statementi', or 'statementi?', or 'statement!7', it was simply to explain that I wasn't making a statement, I was simply asking a question".  Of course by now the question is completely irrelevant as you have twenty people commenting about your spelling and punctuation and the conversation goes on for weeks without a single mention as to an answer to a question you no longer remember asking.

So then sometime later as you are slaving away, sweat rolling down your forehead and beading about your brow, concentrating to the extent you hear nothing going on around you as you pound feverishly on your keyboard trying to finish the project you've been working on for eleven weeks straight.  Hoping that today of all days, you will be able to finish this drawn out job and move on to something fresh.  As you are getting close to your goal, you attempt to run a routine that, inadvertently crashes and cause you to halt your progress and assess the cituation.  As you rack your brain for an answer to this dilemma of a routine not working properly, you recollect that at some point in the not too distant past you had posted a question regarding this very thing at 'the_Swamp'.  So you access your Internet Explorer and drill down on your favorites bar seeking the link to 'the_Swamp'.  You don't remember the outcome of your initial question, and out of fear of reviving old posts, you decide to readdress the question only to get a comment back saying, "Please don't ask the question twice when once will suffice" and a link to your previous post.  You know, the one that had something to do with your punctuation!

As for the "open drawing" and "read-only", and of course the color used, we'll assume you will go back to the question posted earlier 'cause you see, the question was asked in the forum regarding code.  But nobody seemed to catch that part and the post was eventually moved to the 'general' section and people kept telling you how you needed to fix your punctuation and for cry'n out loud, there's an arrow next to the 'open' button on the bottom right side of the drawing screen.  When you press that button, you will find four (4) options and "read-only" is one of those options.  USE IT!  And of course somebody else's comment would be something to the effect of "What does ITI mean and where do you find it, in a pulldown menu?".

So you are using color to try to distinguish the topic of your question and offer people the opportunity to understand your question the first time without having to re-explain your question several different times.  We can understand that Se7en.  And you use the punctuation loosly so those reading your posts will (hopefully) understand that you are truly asking a question and not making statements that make absolutely no sense to the rest of us.  But for pete's sake Se7en, you cannot go around trying to change the english language and recreate the wheel of punctuation.  It isn't the proper way to go about it and you won't get much sympathy from us here, we are 'coders', not english professors.    :lmao:

Hopefully you understand now why jello wiggles the way it does and why there's no such thing as 'jay-walking'.

So please Se7en, let's stop talking about your incessant punctuation and misspelling errors and get back to your topic at hand shall we?
And, holy cow, that yellow and white text is REALLY hard to read !!!  Geez, and they say I should be in a mental home.   :roll:

 :-D   :lmao:   :-D   :lmao:   :-D   :ugly:   :-D   :lmao:
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: Open read-only with code ...
« Reply #6 on: August 09, 2010, 11:26:19 AM »
OK, critique time.  How did I do at turning that whole thing around so it appeared Se7en was the guilty culprit ??  What did you think about the jello explanation ??  Did I answer the questions sufficiently ??


PS:  Don't try this trick in front of an municipal court judge, it doesn't work as well as it does with an appeals court judge.  I don't think they have much of a sense of humor.    ;-)
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Open read-only with code ...
« Reply #7 on: August 09, 2010, 12:03:27 PM »
Code: [Select]
(vla-open (vla-get-documents (vlax-get-acad-object)) FileName :vlax-true)

maybe you should start by...
Code: [Select]
(if (= (getvar 'SDI) 0)...

?
Keep smile...

JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: Open read-only with code ...
« Reply #8 on: August 09, 2010, 12:08:13 PM »
*blink-blink*

Hangman (walking down street): "Sir, Sir. Do you happen to have the time?"
Se7en: "Why yes it is <blah>-0'clock. ...and just so you know for the next occasion you may need the time, the bell tower gives very accurate time and you can see it throughout the entire town."
Hangman: "You're daft, absolutely daft! The purple giraffe flies at night."



BTW, *I* dont see avatars, signatures or smiles because i have them turned off in my profile. So when someone puts in a smiley into their post i dont see it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Hangman

  • Swamp Rat
  • Posts: 566
Re: Open read-only with code ...
« Reply #9 on: August 09, 2010, 01:19:21 PM »
*blink-blink*

Hangman (walking down street): "Sir, Sir. Do you happen to have the time?"
Se7en: "Why yes it is <blah>-0'clock. ...and just so you know for the next occasion you may need the time, the bell tower gives very accurate time and you can see it throughout the entire town."
Hangman: "You're daft, absolutely daft! The purple giraffe flies at night."



BTW, *I* dont see avatars, signatures or smiles because i have them turned off in my profile. So when someone puts in a smiley into their post i dont see it.

Ahhh, I see, ...  figuratively speaking of course.  I forgot you can turn those off and some people do in fact, turn them off.
I didn't see the bell tower as I'm still looking at my two left feet.  I'm still in awe that they work the way they do, it has me mesmorized.

It's all in good humor Se7en, no ill intentions intended.  I do really appreciate your help and your comments like these you have given here.  It helps me recognize the way others perceive my posts so I can work on improving them.  I do have a bad habit of using the double or tripple questions marks.


Anyways, thank you for the tip:
Code: [Select]
(vla-open
   (vla-get-documents (vlax-get-acad-object))
   (getfiled "Select Drawing" "" "dwg" 0) :vlax-true)
and one more question regarding such;  It does open the drawing, but it also minimizes it within AutoCAD so if I have another drawing open and I use this code, the new drawing is opened 'read-only', minimized behind the current drawing.  And I can't remember what the name or command is to capture or make active the new drawing being opened 'read-only', to bring it to the front.  How would I do that?


Code: [Select]
(vla-open (vla-get-documents (vlax-get-acad-object)) FileName :vlax-true)

maybe you should start by...
Code: [Select]
(if (= (getvar 'SDI) 0)...

?
Good point Andrea.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

JohnK

  • Administrator
  • Seagull
  • Posts: 10660
Re: Open read-only with code ...
« Reply #10 on: August 09, 2010, 01:43:01 PM »
I know its all in good fun.

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

friendsofid

  • Guest
Re: Open read-only with code ...
« Reply #11 on: August 27, 2010, 10:11:57 PM »
guys,, sorry to interrupt your very good conversation here,,but how do i exactly use the posted code while im in autocad environment,, (still learning lisp  :-o) i too would like to open existing drawings as read only for references so i don't accidentally save any changes i might have done,,,,

should i use (defun c:openasreadonly () -->> followed by those codes above?

sorry for for my bad english,,not my native tongue  :|

thanks

Hangman

  • Swamp Rat
  • Posts: 566
Re: Open read-only with code ...
« Reply #12 on: August 30, 2010, 11:17:48 AM »
... how do i exactly use the posted code while im in autocad environment, ...
... should i use (defun c:openasreadonly () -->> followed by those codes above?

thanks

Welcome to the Swamp.
Yes, you can use what you posted and the code posted earlier, like so:
Code: [Select]
(defun c:OpenAsReadOnly (/ SDImode)
 (if (= (getvar "SDI") 1)   ;;; if user is using single drawing mode
  (progn
   (setq SDImode (getvar "SDI"))   ;;; save user info
   (setvar "SDI" 0)   ;;; change Single Drawing mode to multiple
  )
 )
 (vl-load-com)   ;;; Be sure this is in the routine or loaded earlier as it is required for the following
 (vla-open
  (vla-get-documents (vlax-get-acad-object))
  (getfiled "Select Drawing" "" "dwg" 0) :vlax-true)
)

You may have to grab the drawing after it is open and make it current.  Mine usually gets minimized to the background.
Perhaps someone can shed some light on how to get the drawing after it's open to make it current.  I've got a meet'n to get to.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Open read-only with code ...
« Reply #13 on: August 30, 2010, 11:24:46 AM »
Perhaps:

Code: [Select]
(defun OpenAsReadOnly ( file / sdi )
  (vl-load-com)

  (setq sdi (getvar 'sdi))
  (setvar 'sdi 0)

  (vla-Activate
    (vla-open (vla-get-Documents (vlax-get-acad-object)) file :vlax-true)
  )

  (setvar 'sdi sdi)
)

(defun c:test ( / f )

  (if (setq f (getfiled "Select Drawing" "" "dwg" 16))
    (OpenAsReadOnly f)
  )

  (princ)
)

Hangman

  • Swamp Rat
  • Posts: 566
Re: Open read-only with code ...
« Reply #14 on: August 30, 2010, 12:55:41 PM »
Yes Lee, that is precisely what I was trying to think of (vla-Activate).
I've seen another way of activating a drawing as well, but it's been a while and I can't think of how it was set up.  I remember it being several lines of code though.

Anyway, I love seeing your code, it's so intriguing.  There's lots to be learned from it.
And I am still puzzled on how you get the corrolation between the 'file' from the function "OpenAsReadOnly" and the 'f' from the function "test".
Is there an internal definition to 'file' so when it's used as you have it there, it automatically takes 'f' as it's arguement ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Open read-only with code ...
« Reply #15 on: August 30, 2010, 01:26:10 PM »
'file' is just a symbol to represent the single argument taken by the OpenAsReadOnly function, when you call this function with valid argument data (a filename string), the symbol 'file' now points to that string wherever it is referenced in that function.

I'm not too good at explaining things, but perhaps this will help:

http://www.bookshelf.jp/texi/onlisp/onlisp_3.html#SEC14

It is written for Common LISP, but the logic still applies.

Lee