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

expire date for a lisp function

24 REPLIES 24
SOLVED
Reply
Message 1 of 25
aqdam1978
4246 Views, 24 Replies

expire date for a lisp function

Hi friends,

 

I want to define en expiration date in registry, after that date the some LISP programs does not allow to run.

I think that suitable commands are SetEnv and GetEnv.

define a ExpDt variable that contains Expiry Date as a string.

and add some statements inside of the LISP program to call this variable and check it with today's date.

 

I should define once time in autocad:

(setenv "expdt" "130101"); YYMMDD date for validation period (2013.01.01)

 

and check this every time that a lisp program should be execeute:

(getenv "expdt") ; if today's date(with YYMMDD format) ">" expdt then lisp program doen not allow to run and should be halted.

for e.g. on 2013.02.28: "130228" > "130101" ==> so the lisp function should be halted and will not work!

(without any alert or message)


a sample list function: (how can implemente on this lisp function?)

 

(defun c:3()
(setq w t)
(while w
(setq a (getpoint "\npick point:"))
(setq p1 (list (- (car a) 0.5)(- (cadr a) 0.5)))
(setq p2 (list (+(car a) 0.5)(+(cadr a) 0.5)))
(command "erase" "w" p1 p2 "")
(command "INSERT" "*3" a "" "" "0")
)
(if (= a nil)(setq w nil))
)

 

 

so, does anybody know how can implemete this idea in LISP function?

 

Thank you in advance.

 

 

24 REPLIES 24
Message 2 of 25
Kent1Cooper
in reply to: aqdam1978


@aqdam1978 wrote:

.... 

I want to define en expiration date in registry, after that date the some LISP programs does not allow to run.

.... 

I should define once time in autocad:

(setenv "expdt" "130101"); YYMMDD date for validation period (2013.01.01)

 

and check this every time that a lisp program should be execeute:

(getenv "expdt") ; if today's date(with YYMMDD format) ">" expdt then lisp program doen not allow to run and should be halted.

for e.g. on 2013.02.28: "130228" > "130101" ==> so the lisp function should be halted and will not work!

(without any alert or message)

.... 


This will give you the current date in that kind of format, as a text string:

 

(substr (rtos (getvar 'cdate) 2 0) 3)

 

So, something like:

 

(if (<= (atoi (substr (rtos (getvar 'cdate) 2 0) 3)) (atoi (getenv "expdt")))

  (progn ; then

    (... go ahead with the routine ...)

  ); progn

); if

 

Unless you would only ever have one such routine that you want to assign an expiration date to, I would suggest that you name that environment variable something that includes an element of the name of the specific routine for which it is the expiration date, so that you can have different dates for different routines.

 

Another consideration:  Environment variables exist only on individual computers.  So if you do it that way, you would need to define the expiration date on each computer, which you can avoid by forgetting the environment variable and building it into the definition of the routine itself as a numerical value, for instance:

(if (<= (atoi (substr (rtos (getvar 'cdate) 2 0) 3)) 130101)

Or, you could keep the environment variable, and the test as before, but include the (setenv) function at the beginning of the routine's definition.  Either way, the expiration date is built into the function definition, so it's covered on any computer that calls that function.  And you can hasten or extend or eliminate the expiration date if you want, by changing that aspect in just one file.

 

Or, to avoid needing to do that, you could put the expiration date as a single line in a text file that lives in a server folder where all computers can access it, and read that line for the expiration test, rather than using an environment variable.

Kent Cooper, AIA
Message 3 of 25
aqdam1978
in reply to: Kent1Cooper

Hi Kent Cooper,

Thank you for your help.

 

I have some questions:

1- I think that we don't need "atoi" convert command, because "<" or ">" work on strings variables too. Am I right?

2- suppose that if we not define ExpDt variable on aother PC, so (getenv "expdt") returns nil.

     what happen to lisp program? I want to halt lisp in this case too.

 

Thanks for your help.

 

Message 4 of 25
Kent1Cooper
in reply to: aqdam1978


@aqdam1978 wrote:

....

1- I think that we don't need "atoi" convert command, because "<" or ">" work on strings variables too. Am I right?

2- suppose that if we not define ExpDt variable on aother PC, so (getenv "expdt") returns nil.

     what happen to lisp program? I want to halt lisp in this case too.

....


I guess you're right on number 1, provided the text strings are all the same length and consist of only numerical digits.

[If they're not the same length, the text-string and integer tests won't always be equivalent:

Command: (< "123" "32")
T

Command: (< 123 32)
nil

And non-numerical characters have different effects, depending on where they are in the string.]

 

On number 2:  You could add a test as to whether that environment variable has been defined on that computer:

 

(if

  (and

    (getenv "expdt"); will return nil if not defined

    (<= (substr (rtos (getvar 'cdate) 2 0) 3) (getenv "expdt"))

  ); and

  (progn ; then

    ....

 

but I don't think you need to do that -- a nil return seems to be treated like 0 in such comparisons:

 

Command: (<= "130101" nil)
nil

Command: (<= nil "130101")
T

 

So with the comparison in that particular direction, you should be able to just leave the same test with the (atoi) wrappers removed [because (atoi) won't like nil as an argument if the environment variable is not defined].

Kent Cooper, AIA
Message 5 of 25
aqdam1978
in reply to: Kent1Cooper

Hi Kent,

 

I prefer to use negative condition in the first of lisp program: (because it needs more little changes in lisp program)

 

(defun c:3()  <---- sample lisp program

(if (> (substr (rtos (getvar 'cdate) 2 0) 3) (getenv "expdt")) (exit))   <--- just one line add to each lisp program!

.....

.....

)

 

but the "exit" command shows a message: (and I don't like it!)

; error: quit / exit abort

 

Is there any halt/exit/quit/break command that does not show a message?

 

Message 6 of 25
hmsilva
in reply to: aqdam1978

aqdam1978,

perhaps something like

 

(defun c:3 ()
  (if (> (substr (rtos (getvar 'cdate) 2 0) 3) (getenv "expdt"))
    (princ)
    (progn
      (setq w t)
      (while w
	(setq a (getpoint "\npick point:"))
	(setq p1 (list (- (car a) 0.5) (- (cadr a) 0.5)))
	(setq p2 (list (+ (car a) 0.5) (+ (cadr a) 0.5)))
	(command "erase" "w" p1 p2 "")
	(command "INSERT" "*3" a "" "" "0")
      )
      (if (= a nil)
	(setq w nil)
      )
    ); progn
  ); if
); 3

 Henrique

EESignature

Message 7 of 25
Kent1Cooper
in reply to: aqdam1978


@aqdam1978 wrote:

.... 

I prefer to use negative condition in the first of lisp program: ....

 

(defun c:3()  <---- sample lisp program

(if (> (substr (rtos (getvar 'cdate) 2 0) 3) (getenv "expdt")) (exit))   <--- just one line add to each lisp program!

.... 

but the "exit" command shows a message: (and I don't like it!)

; error: quit / exit abort

 

Is there any halt/exit/quit/break command that does not show a message?


If you do it the other way, you won't have this problem -- it will simply do nothing if the expiration date has passed.  But if you prefer the (exit) approach, to keep it quiet about it, you will need an error handler.  That can be defined like a localized variable, so AutoCAD's regular one will come back into effect when the routine is finished, e.g. something like:

 

(defun c:3 (/ *error* other localized variables go here if any)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)); [still prints error message from any "real" problem]
    ); if
    (... reset something or other ...)
    (... etc ...)
    (princ); <-- this makes it "exit quietly" with no message if it was cancelled by (exit)

  ); defun - *error*

  (if (> (substr (rtos (getvar 'cdate) 2 0) 3) (getenv "expdt")) (exit))

  .....

  .....

)

Kent Cooper, AIA
Message 8 of 25
scot-65
in reply to: aqdam1978

Set a predetermined date inside the file using CDATE

as the reference, then FAS the program and distribute.

 

(if (<= (fix (getvar 'CDATE)) 20130101)

 (progn

  [your program here]

 );progn

 (alert "Routine has expired.   ")

);if

 

Regarding the stations that do not have a REG key defined, you

will have to include a declaration part inside the program as well,

so why bother with the registry in the first place? Also, some

stations may not have administrator rights which means the

current user's profile cannot write to the registry (XP & 7).

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 9 of 25
aqdam1978
in reply to: scot-65

Hi scot-65,

 

your idea is very intersting....

but i don't know anything about FAS!

what is the easy way to encrypt our lisp program? which encoder programs are good for this purpose?

 

 

Thanks,

 

Message 10 of 25
Kent1Cooper
in reply to: aqdam1978

A few other things that could be streamlined, if you're interested....

 

If the (progn) in hmsilva's routine is acceptable after all, then you can eliminate the (princ) do-nothing part by comparing in the other direction as scot-65 and I have it, and having no 'else' argument at all.

 

I believe you can do without the 'w' variable entirely.  And I expect the original will have a problem if the User hits Enter/space at the pick-a-point prompt, because 'a' will be nil, but it will still have to plow through the p1 & p2 calculations and Erase and Insert commands, though it won't make it because it will be interrupted in that by an error for the nil value, before it gets to changing 'w' to end the (while) loop.

 

[Even though I suggest eliminating it, you can replace (= a nil) with just (not a) or (null a).]

 

You can include more than one command in a single (command) function.

 

There's a more concise way to define relative points.  [It could also be done with (polar) instead of what I have below.]

 

Any variable that is used only once can usually be eliminated, if you just use whatever it is that put a value in it, right where you would use the variable [p1 & p2].

 

Zero degrees is always the default rotation angle in Insert, so the "0" can just be "" [Enter].

 

Because of some of the above streamlinings, there's only one function [the (while) loop] left in what has to happen for the 'then' argument, so the (progn) wrapper is no longer needed.

 

Incoporating scot-65's suggestion about the simplified date test, leaving the 20 at the beginning....

 

(defun c:3 ()
  (if (<= (fix (getvar 'cdate)) 20130101)
    (while (setq a (getpoint "\npick point:")); 'then' [returns nil on Enter]
      (command

        "erase" "w" (mapcar '- a '(0.5 0.5 0)) (mapcar '+ a '(0.5 0.5 0)) ""
        "INSERT" "*3" a "" "" ""

      ); command
    ); while
  ); if [no 'else' argument]
); 3

Kent Cooper, AIA
Message 11 of 25
Kent1Cooper
in reply to: scot-65


@scot-65 wrote:

... FAS the program and distribute.

....


Or, just have it in a location on a Server that's in everyone's Support File Search Path list, and no distribution is necessary, either initially or any time you have reason to edit it.  Have it loaded or autoloaded by something like acaddoc.lsp, also in a shared location, and everyone will have it, and always the current version if it ever changes, without your needing to do anything other than make such changes in the one file.  If appropriate, make that location off-limits to alteration by unauthorized people, and it shouldn't be necessary to encrypt the code.

Kent Cooper, AIA
Message 12 of 25
aqdam1978
in reply to: scot-65

Hi scot-65,

is this program enough to creat protected FAS file?

 

(defun c:Lsp2Fas (/ #File)
(vl-load-com)
(and (setq #File (getfiled "Convert .LSP file to .FAS" "" "lsp" 16))
(c:vlide)
(vlisp-compile 'st #File)
(alert (strcat "LSP -> FAS Complete!\n\n" (vl-string-subst ".fas" ".lsp" (strcase #File T))))
) ;_ and
(princ)
) ;_ defun

 

 

Message 13 of 25
3wood
in reply to: aqdam1978

Do you know people can easily change the system date in 2 seconds?

Message 14 of 25
scot-65
in reply to: aqdam1978


@aqdam1978 wrote:

Hi scot-65,

is this program enough to creat protected FAS file?

 

(defun c:Lsp2Fas (/ #File)
(vl-load-com)
(and (setq #File (getfiled "Convert .LSP file to .FAS" "" "lsp" 16))
(c:vlide)
(vlisp-compile 'st #File)
(alert (strcat "LSP -> FAS Complete!\n\n" (vl-string-subst ".fas" ".lsp" (strcase #File T))))
) ;_ and
(princ)
) ;_ defun

 

 


For the few times I have created FAS files, I was wondering if there was an easier way to do this

in lieu of opening the vlide editor and manually creating these FAS files. What you have here appears

to be what I am looking for!!!

 

Another suggestion in lieu of SETENV or VL-REG-WRITE is to use SETCFG.

Administrator rights are not observed here.

 

As far as Kent's latest suggestion, my line of thought was more geared to the individuals who contract

out and do not have the means to connect to our server while they are not present in this office. This also

includes the individuals who do work in this office, and have brought in their personal computer (lap/desk)

so they can take home the projects as needed and work from there.

 

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 15 of 25
scot-65
in reply to: 3wood


@3wood wrote:

Do you know people can easily change the system date in 2 seconds?


I did on occasion, but the network I am on automatically restores the time setting.

By not saying anything, or hinting that there is a date stamp inside, the normal

user would be clueless as how to proceed.

 

Also, anti-virus software depends on the computer time so updates

and checks can be performed. I know of a computer that Hiccupped

to where the date jumped by a full year and got an error message that

would not go away until I finally figured out what the problem was

(the date in the tray showed 2012-12-11).

 

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 16 of 25
scot-65
in reply to: aqdam1978

I have taken your provided code and made it more user friendly

as well as expediting the process where multiple files are involved.

Note that all files show in the dialog, which is nice to see which files

have or have not been converted to FAS.

 

1. Place a "test" drawing inside the folder that contains all the files that will be converted.

2. Open this drawing.

3. Run the program.

 

Here is the revised code:

 

;;  LSP2FAS.lsp                                    ; Scot Harris  11-29-2012
;;   Minimizes the sequence needed to create FAS files.
;;   Help facility added.
;;   Streamlined from original program provided by aqdam1978.

(defun c:LSP2FAS-Help (/)
 (alert (strcat
  "\tLisp (LSP) to Fast and Secure (FAS) Help"
  "\n "
  "\nFile dialog begins in the current directory.   "
  "\nIt is suggested to place and open a drawing (DWG)   "
  "\ninside the input folder you wish to batch process.   "
  "\n "
  "\nOutput file will be in the same folder as the file selected.   "
  "\n "
  "\nThere is no provisional check for an existing FAS file of the same name.   "
 ))
);end LSP2FAS-Help

(defun c:LSP2FAS ( / a )
 (vl-load-com)
 (prompt " Lisp to Fast and Secure (FAS). LSP2FAS-Help available. ")
 (if (wcmatch (strcase (setq a (getfiled "Convert LSP File to FAS" (getvar "DWGPREFIX") "" 16))) "*.LSP")
  (progn
   (c:vlide)(vlisp-compile 'st a)
   (princ (strcat "\n File " (vl-string-subst ".fas" ".lsp" a) " created. "))
  );progn
  (alert "File extension must be \".LSP\"   ")
 );if
 (princ)
);end LSP2FAS

 

Scot-65

 

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 17 of 25
pbejse
in reply to: scot-65


@scot-65 wrote:

......By not saying anything, or hinting that there is a date stamp inside, the normal

user would be clueless as how to proceed.....

 

Scot-65

 


Good observation Scott 🙂

 

 

Message 18 of 25

Hi everyone,

Is it possible for me to set an expiration date for any .vlx file I found on the net? Many thanks.

Message 19 of 25

Doubtful as vlx is compiled already, even if you compile some code that has check date and loads the vlx you can still run it outside of your command.

 

Why are you time bombing some one elses code ? If they have offered free code you should not be turning it off.

Message 20 of 25

It's just that I want to limit the time when I share it with my team members, but I can not insert your code time. 

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

Post to forums  

Autodesk Design & Make Report

”Boost