restric number of uses for a code

restric number of uses for a code

dani-perez
Advocate Advocate
986 Views
8 Replies
Message 1 of 9

restric number of uses for a code

dani-perez
Advocate
Advocate

Hello all,

 

I'd like to restrict the number of uses for a lisp. Not to create a time deadline, but you can only call the code 3 times  in each different complitation of it for example.

 

Thanks all

0 Likes
Accepted solutions (1)
987 Views
8 Replies
Replies (8)
Message 2 of 9

Satish_Rajdev
Advocate
Advocate
Accepted solution
0 Likes
Message 3 of 9

pbejse
Mentor
Mentor

@dani-perez wrote:

 

I'd like to restrict the number of uses for a lisp. Not to create a time deadline, but you can only call the code 3 times  in each different complitation of it for example.


 

The posted link does create a "time deadline".  Is that what you really wanted all along?  Confusing ....

 

0 Likes
Message 4 of 9

Sea-Haven
Mentor
Mentor

One simple way is write to the registery and consequently read from. REGEDIT is only for those who think to look and if you use some form of common naming will be hard to find. Again not foolproof but probably 99%.

0 Likes
Message 5 of 9

dani-perez
Advocate
Advocate

Hello   

 

When I said "Not to create a time deadline" I meant not a date-expiring license. I meant to be able to restrict a code after executing it X times. 

 

sorry if confusing

0 Likes
Message 6 of 9

dani-perez
Advocate
Advocate

Hello  Satish_Rajdev  

 

I tried the code, and if  I use the routine in other pc, it is able to use again.

 

Hello sea.haven

 

It would work in another different pc¿?

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@pbejse wrote:
....

The posted link does create a "time deadline".  ....


 

If you're saying that because of the wording:

 

  (alert "\nEvalution Period has Expired ..."

 

that's a misleading way that they worded it.  Its evaluation is not about "Period" [of time] but about number of times it's been called.  So it should be okay on the same computer, as the OP has noted, but if it should be limited to a total number of uses by all Users, I assume something else would need to be done, most likely either re-writing or appending something to the end of the file that defines the routine, or maybe editing a file in the same folder with some kind of associated name.  Either assumes the file is in a shared Server location that can be affected by usage of the routine by anyone who gets it from that Server.

Kent Cooper, AIA
0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....  if it should be limited to a total number of uses by all Users, I assume something else would need to be done, ... maybe editing a file in the same folder with some kind of associated name.  ....


 

If your routine is called MyFile.lsp, defining a command called MyCommandName, and you want it to be used no more than 5 times, try building it something like this [minimally tested]:

(defun C:MyCommandName (/ txtfile counter count); add to other localized variables
  (if
    (and
      (setq txtfile (findfile "MyFile.txt")); associated counter file established already?
      (setq counter (open txtfile "r"))
      (= (read-line counter) "5")
    ); and
    (progn ; then
      (alert "This routine has already been used 5 times.")
      (close counter)
      (quit)
    ); progn
    (progn ; else -- go ahead, and increment counter
      (.... the command's operational code ....)
      (if
        (setq txtfile (findfile "MyFile.txt")); counter file established already?
        (progn ; then
          (setq
            counter (open txtfile "r"); for reading
            count (atoi (read-line counter)); how many times used, as number
          ); setq
          (close counter)
        ); progn
      ); if
      (setq counter
        (open ; file called MyFile.txt in same folder location
          (strcat (substr (setq pathname (findfile "MyFile.lsp")) 1 (- (strlen pathname) 3)) "txt")
          "w" ; for writing
        ); open
      ); setq
      (write-line (itoa (if count (1+ count) 1)) counter); increment number of uses, as text
      (close counter)
    ); progn
  ); if
  (princ)
); defun

Again, it needs to be in one  location that all Users load it from, and not installed separately on each User's computer.  A clever-enough User might still be able to figure out [especially if the .lsp file is readable and they understand how it works] that there's a file that controls this, and edit or delete it to get around the limitation.  And there's the possibility that more than one User could call it at close enough to the same time to get around it, or even if not collectively exceeding the limit, to interfere with both/all successfully upgrading the counter.

Kent Cooper, AIA
0 Likes
Message 9 of 9

scot-65
Advisor
Advisor
Three times per session?
Three times per specific DWG file?
Three times total access to the routine?
Post is not clear on this.

Session:
Introduce a session gremlin. Format can be USER_[RoutineName]
and not declared as a local variable inside the defun section.
(defun c:AA bla bla bla
(or USER_AA (setq USER_AA 0))
(if (> (setq USER_AA (1+ USER_AA)) 3)
(progn (alert "Program usage has reached it's limit.")(exit)))
(defun *error* bla bla bla
bla bla bla...

Specific DWG:
Look into VLAX-LDATA-PUT and VLAX-LDATA-GET to access the file's dictionary.
Follow the format as shown in the Session section above (checking for file name
[or a portion of the name] should be included as part of the recorded information).

External file or registry methods for the last one - depending on user or group.

???

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

0 Likes