lisp file locking

lisp file locking

Gaganpatel
Collaborator Collaborator
3,715 Views
14 Replies
Message 1 of 15

lisp file locking

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

 

I want to lisp file use in one computer is working ,any other computer use this lisp file is locking process.

Please share lisp file.

0 Likes
3,716 Views
14 Replies
Replies (14)
Message 2 of 15

Scottu2
Advocate
Advocate

Hello  kalandipaital1989,

 

I'm thinking when the lisp Routine starts it reads a text file and it must be blank or has the same username, then overwrites the file with the username and date&time.  When the program is finished it overwrites the file as a new blank file.

A different computer runs the Routine and it reads the text file but the username does not match so the Routine displays "Can't proceed, In use by another user: xxxxx at mm:dd:yyyy hh:m:ss" and exits.

 

However, my question would be how critical is it to lockout other computers from running the same Routine?

1. There may be a time someone can not run the Routine because the station stopped working with the password screen lock or out of the office.  Does this person have to wait? Or can a person select an option to take ownership of the lockfile by overwriting with their username and date&time?

 

2. Does running the lisp Routine in multiple drawings on same computer the cause any problems?

 

This situation would be like editing an excel spread sheet, by read-only for others until the person editing the file exits.

 

Scott U

 

0 Likes
Message 3 of 15

Moshe-A
Mentor
Mentor

@Gaganpatel  hi,

 

here is a function (sp:user_validate) that returns T if a user coming from his computer is allowed to process a lisp function. the data for (vl-some) function is two list of names, 1st user names and 2nd computer names. made them  lists so that you can reword in future more peoples Smiley LOL

 

enjoy

moshe

 

 

(defun sp:user_validate ()
 (vl-some
   '(lambda (AllowedUserName AllowedComputername)
      (and
        (eq (strcase (getenv "UserName"))     (strcase AllowedUserName))
        (eq (strcase (getenv "ComputerName")) (strcase AllowedComputerName))
      )
   )
   '("Sandip" 	     "user2" 	 "user3")	; allowed user names
   '("Sandip-Paital" "Computer2" "Computer3")   ; allowed computer names
 ); vl-some
); user_validate


(defun c:test ()
 (if (not (sp:user_validate))
  (prompt "\nCommand is Locked.")
  (progn 
   ; do your Command 
   ; ...........
   ; .........
   ; .......
   ; .....
  ); progn
 ); if

 (princ)
)

0 Likes
Message 4 of 15

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

how to use this lisp.

Please share me.

0 Likes
Message 5 of 15

Moshe-A
Mentor
Mentor

@Gaganpatel ,

 

let's say you have a lisp file calls tagins.lsp that insert a specific tag block (s-tag) in your drawing - ok?

could be somethings like this:

 

(defun c:tagins ()
 (if (null (tblsearch "layer" "tags")) 
  (command "._layer" "_make" "tags" "_color" 3 "tags" "")
 )
 (command-s ".insert" "s-tag")  
)

and you want to allow only to Sandip & Joe & Sandy to run it.

 

open the tagins.lsp in notepad and copy paste the blue lines code inside:

 

(defun sp:user_validate (AllowedUserNames^ AllowedComputerNames^)
 (vl-some
   '(lambda (AllowedUserName AllowedComputername)
      (and
        (eq (strcase (getenv "UserName"))     (strcase AllowedUserName))
        (eq (strcase (getenv "ComputerName")) (strcase AllowedComputerName))
      )
   )
   '("Sandip" 	     "Joe"     "Sandy")	      ; allowed user names
   '("Sandip-Paital" "Joe-w10" "Sandy-w10")   ; allowed computer names
 ); vl-some
); user_validate

(defun c:tagins ()
 (if (not (sp:user_validate))
  (prompt "\nCommand is Locked.")
  (progn 
   (if (null (tblsearch "layer" "tags")) 
    (command "._layer" "_make" "tags" "_color" 3 "tags" "")
   ); if
  
   (command-s ".insert" "b-tag")
  ); progn
 ); if
); tagins 

if this doesn't help you i'm 'coming' over Smiley LOL

 

0 Likes
Message 6 of 15

Scottu2
Advocate
Advocate

Hello  kalandipaital1989,

 

Did I misunderstand your original post?

  Should the lisp routine only run on one machine one at time?

  Should the lisp routine only run when the specific User and Computer name matches the list?

 

Scott

 

0 Likes
Message 7 of 15

dani-perez
Advocate
Advocate

Hello Moshe-A,

 

Nice function. Could you combine it with a password function?

 

Thanks in advance.

0 Likes
Message 8 of 15

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

I am not professional of lisp programmer.

your program in use lisp middle position,i am trying your program but not working.

please share me easy type use program (program starting use another program ending use)

Please share me sir.

0 Likes
Message 9 of 15

Moshe-A
Mentor
Mentor

@Gaganpatel  hi,

 

this code is only sample of what you can do, how do you expect to take it from here if you do not have autolisp programming skill?

 

you do aware that this protection is base on user login name plus computer name - yes?

then how can i give you specific help if up to this point you didn't think to provide these details and i even do not know what is the lisp program you want to protect?!

 

here is an update code:

 

(defun sp:user_validate ()
 (vl-some
   '(lambda (AllowedUserName AllowedComputername)
      (and
        (eq (strcase (getenv "UserName"))     (strcase AllowedUserName))
        (eq (strcase (getenv "ComputerName")) (strcase AllowedComputerName))
      )
   )
   '("Sandip" 	     "Joe"     "Sandy")	      ; allowed user names
   '("Sandip-Paital" "Joe-w10" "Sandy-w10")   ; allowed computer names
 ); vl-some
); user_validate


(defun c:tagins ()
 (if (not (sp:user_validate))
  (prompt "\nCommand is Locked.")
  (progn 
   (if (null (tblsearch "layer" "tags")) 
    (command "._layer" "_make" "tags" "_color" 3 "tags" "")
   ); if
  
   (command-s ".insert" "b-tag")
  ); progn
 ); if
); tagins 
0 Likes
Message 10 of 15

Gaganpatel
Collaborator
Collaborator

 

Dear Sir,

suppose one lisp file inner four types of program use.

How to use your lisp locking program.

Please share process.

0 Likes
Message 11 of 15

Moshe-A
Mentor
Mentor

@Gaganpatel wrote: suppose one lisp file inner four types of program use.

 i do not understand what that means?

and if what have i gave you is not helping than i can not help more - sorry

 

 

0 Likes
Message 12 of 15

Gaganpatel
Collaborator
Collaborator

Dear Sir,

My Computer Name-Paital

Please see the lisp program and your lisp locking program use this program.

Please help.

 

 

(vl-load-com)
(defun C:DimSum (/ i n sumtxt ss sn dobj mea ovr OldVars VarList)
(setq
i 0
n -1
sumtxt "" ; initially empty string
); setq
(if (setq ss (ssget '((0 . "DIMENSION"))))
(progn ; then
(while (setq sn (ssname ss (setq n (1+ n))))
(setq
dobj (vlax-ename->vla-object sn)
i ; accumulating total
(+
i ; total so far
(setq mea ; measurement of this Dimension
(if (= (setq ovr (vla-get-TextOverride dobj)) ""); no override
(vla-get-measurement dobj); then -- measured length
(if (wcmatch ovr "<>*"); else [override] -- just real measurement with suffix [of either kind]?
(vla-get-measurement dobj); then -- measured length
(distof ; else -- numerical equivalent of override
(substr ovr 1 ; start at beginning
(vl-string-search
(if (wcmatch ovr "*%*") "%" "\\"); plus-or-minus vs. new-line
ovr
); vl-string-search
); substr
); distof
); if [real-with-suffix vs. forced]
); if [no-override vs. override]
); setq & mea
); + & i
sumtxt (strcat sumtxt (rtos mea 2 4) "\\P"); add line to Mtext content
); setq
); while
(if (> i 0)
(progn ; then
(prompt (strcat "\nTotal measuremnts : < " (rtos i 2 4) " > ."))
(setq OldVars (mapcar 'getvar (setq VarList '(cmdecho clayer))))
(setvar 'cmdecho 0)
(command "_.layer" "_make" "DimSums" "_plot" "_no" "" "")
(entmake
(list
'(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText")
'(8 . "DimSums"); Layer
(cons 10 (getvar 'viewctr)); insertion point
'(40 . 12); height
'(41 . 0.0); ref. rectangle width
'(71 . 1); top-left justification
'(72 . 5); direction by Style
(cons 1 (strcat sumtxt "total = " (rtos i 2 4))); content
'(7 . "STANDARD"); Style
'(50 . 0.0); rotation
); list
); entmake
(command "_move" "_last" "" (getvar 'viewctr) pause)
(mapcar 'setvar VarList OldVars)
); progn
); if
); progn
(prompt "\nNo Dimension(s) selected."); else
); if
(princ)
); defun

0 Likes
Message 13 of 15

Moshe-A
Mentor
Mentor

@Gaganpatel 

 

My Computer Name- Paital

computer name is not enough a login name is also needed.

so in code i painted the login name + computer name to red if your login name is not sandip? then you should change it to the exact login name.

 

remember:

the login name + computer name that appears in list are allowed to run the lisp

i do not know if your lisp is working and did not test it either.

 

cheers

moshe

 

 

(defun sp:user_validate ()
 (vl-some
   '(lambda (AllowedUserName AllowedComputername)
      (and
        (eq (strcase (getenv "UserName"))     (strcase AllowedUserName))
        (eq (strcase (getenv "ComputerName")) (strcase AllowedComputerName))
      )
   )
   '("Sandip"  "Joe"     "Sandy")	; allowed user names
   '("Paital"  "Joe-w10" "Sandy-w10")   ; allowed computer names
 ); vl-some
); user_validate

(vl-load-com)
(defun dimension_sum (/ i n sumtxt ss sn dobj mea ovr OldVars VarList)
(setq
i 0
n -1
sumtxt "" ; initially empty string
); setq
(if (setq ss (ssget '((0 . "DIMENSION"))))
(progn ; then
(while (setq sn (ssname ss (setq n (1+ n))))
(setq
dobj (vlax-ename->vla-object sn)
i ; accumulating total
(+
i ; total so far
(setq mea ; measurement of this Dimension
(if (= (setq ovr (vla-get-TextOverride dobj)) ""); no override
(vla-get-measurement dobj); then -- measured length
(if (wcmatch ovr "<>*"); else [override] -- just real measurement with suffix [of either kind]?
(vla-get-measurement dobj); then -- measured length
(distof ; else -- numerical equivalent of override
(substr ovr 1 ; start at beginning
(vl-string-search
(if (wcmatch ovr "*%*") "%" "\\"); plus-or-minus vs. new-line
ovr
); vl-string-search
); substr
); distof
); if [real-with-suffix vs. forced]
); if [no-override vs. override]
); setq & mea
); + & i
sumtxt (strcat sumtxt (rtos mea 2 4) "\\P"); add line to Mtext content
); setq
); while
(if (> i 0)
(progn ; then
(prompt (strcat "\nTotal measuremnts : < " (rtos i 2 4) " > ."))
(setq OldVars (mapcar 'getvar (setq VarList '(cmdecho clayer))))
(setvar 'cmdecho 0)
(command "_.layer" "_make" "DimSums" "_plot" "_no" "" "")
(entmake
(list
'(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText")
'(8 . "DimSums"); Layer
(cons 10 (getvar 'viewctr)); insertion point
'(40 . 12); height
'(41 . 0.0); ref. rectangle width
'(71 . 1); top-left justification
'(72 . 5); direction by Style
(cons 1 (strcat sumtxt "total = " (rtos i 2 4))); content
'(7 . "STANDARD"); Style
'(50 . 0.0); rotation
); list
); entmake
(command "_move" "_last" "" (getvar 'viewctr) pause)
(mapcar 'setvar VarList OldVars)
); progn
); if
); progn
(prompt "\nNo Dimension(s) selected."); else
); if
); defun


(defun c:dimsum ()
 (if (not (sp:user_validate))
  (prompt "\nCommand is Locked.")
  (dimension_sum) 
 ); if
 (princ)
) 

0 Likes
Message 14 of 15

scot-65
Advisor
Advisor
This looks better - not woven into the program as you showed earlier.
[I would have used (exit), which otherwise I would never use]

Other possible solutions:
a) Registry key initiated into the workstation by the proprietor [can be a time bomb].
b) (if (not (and (load (findfile "CheckName.fas")) (CheckName "<LoginName>" "<ComputerName>")))
(progn (alert "Command is locked.") (exit))
);if

untested.

???

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

0 Likes
Message 15 of 15

Scottu2
Advocate
Advocate

This appears to be a menu option, one lisp file with 4 programs.

 

@kalandipaital1989 wrote: suppose one lisp file inner four types of program use.

 

This program will add dimensions and place the result on a different layer.

Enter Password: xxx

if xxxx = "111" then run program1

if xxxx = "222" then run program2

if xxxx = "33" then run program3

if xxxx = "44" then run program4

 

0 Likes