Jump to content

smal code to find itself LOL


DGRL

Recommended Posts

Dear coders

 

 

I was playing a little with the find file function and pure for learning I was wondering if it is possible to make a lisp that will find himself

 

 

ATM I don't know what code to use to get the filename and the path of the LSP file

I am not looking for another file then where the code is written in

Link to comment
Share on other sites

You can check if a command is loaded with '(if c:my-func ... or with atoms-family , but you would still have to know in advance the filename containing your function definition. Or you would have to instruct your lisp file to set a global variable / list / array with it's path in it. Of course if you have many files that use a function called test that would be a little problematic. Also possible would be consistency between name of function and name of lisp file , function c:mylisp1 -> mylisp1.lsp. Whatever way , it can be done but think it has to be by design. Else you have scan for all lisp files , open them and see if a certain function lives inside... so if you want it , you have to plan it.

 

 

gr. Rlx

Link to comment
Share on other sites

@rlx

 

 

Well that is hard coz I do not know where the file will be saved but I do need to do stuff with it like setting attributes (read-only o.i.d.) or simply delete the file or move it from where it is now to an specific folder

Link to comment
Share on other sites

And the (dos_lisplist [T]) is not reliable because it gives back more then my custom loaded lsp files but less then what you can see with appload LOL

Link to comment
Share on other sites

that's why all my (active) lisp files live together as one big little house on the prairie family in the same folder and this folder is at the top of my supportpath so findfile will always find it. Think Lee has a find-file routine , I have one too in my batch generator, don't know if I have all the subfunctions else search for RlxBatch

 

 

; find drawing objects - Thanks to TonyT, (probably) no way I would have been able to think this up, credit where credit's due
; just compressed and tweaked it a little bit
(defun load_fso_scripting ( / server fso:progid fso:prefix )
 (setq fso:progid "Scripting.FileSystemObject" fso:prefix "wsh-")
 (if (not wsh-get-drives)
   (if (not (setq server (CoGetClassServer fso:progid)))
     (alert "Error: Windows Scripting Host is not installed")
     (vlax-import-type-library
:tlb-filename Server :methods-prefix fso:prefix :properties-prefix fso:prefix
:constants-prefix (strcat ":" fso:prefix)))))
(defun ProgID->CLSID (ProgID)(vl-registry-read (strcat "HKEY_CLASSES_ROOT\\" progid "[url="file://\\CLSID"]\\CLSID[/url]")))
(defun CoGetClassServer (progid) (CoGetClassProperty progid "InprocServer32"))
(defun CoGetClassProperty (ProgID property / clsid)
 (if (setq clsid (ProgID->CLSID ProgID)) (vl-registry-read (strcat "HKEY_CLASSES_ROOT\\CLSID\\" clsid "\\" property))))
; FInd Drawing Objects - test : (setq lst (fido (dos_path "d:/temp/lisp")))
; network test : (setq lst (fido (dos_path "//sabiccorp.sabic.com/eur/boz/Technical_Department/Acad.net/templates")))
(defun fido ( $f / fso fld rslt)
 (load_fso_scripting)
 (setq fso (vla-getInterfaceObject (vlax-get-acad-object) "Scripting.FileSystemObject")
fld (wsh-GetFolder fso $f) rslt (fifo fld "*.dwg")) (vlax-release-object fld) (vlax-release-object fso) rslt)
; (setq lst (find-files (dos_path "d:/temp") "*.tif"))
(defun find-files ( $f $e / fso fld rslt)
 (load_fso_scripting)
 (setq fso (vla-getInterfaceObject (vlax-get-acad-object) "Scripting.FileSystemObject")
fld (wsh-GetFolder fso $f) rslt (fifo fld $e)) (vlax-release-object fld) (vlax-release-object fso) rslt)
; find in folders fl=file ,fls=files, sf=subfolder, sfl=subfolderlist, res=result
(defun fifo ( %dir %ext / fl fls sf sfl res)
 (vlax-for fl (setq fls (wsh-get-files %dir))
   (if (wcmatch (strcase (wsh-get-name fl) t) %ext)(setq res (cons (wsh-get-path fl) res)))(vlax-release-object fl))
 (vlax-release-object fls)
 (vlax-for sf (setq sfl (wsh-get-SubFolders %dir)) (setq res (append res (fifo sf %ext)))(vlax-release-object sf))
 (please_release_me_let_me_go (list sfl)) res)



(defun dos_path  ( $p ) (if (= (type $p) 'str) (strcase (vl-string-translate "/" "\\" $p))   ""))


(defun please_release_me_let_me_go (lst)
 (mapcar '(lambda(x)
     (if (and (= 'vla-object (type x)) (not (vlax-object-released-p x)))
       (vlax-release-object x))(set (quote x) nil)) lst))



Link to comment
Share on other sites

I have to approach this different @RLX

I think I have to make adjustments and hardcode the filename inside the LSP and use FINDFILE to get the path

Link to comment
Share on other sites

LOL

Going to block all other LSP files in use here if they do not have the "Check" build in

A lot of designers are not going to like this ( have no other choice atm until I find a good solution )

 

 

No I am the IT guy who screws with the coders

Link to comment
Share on other sites

LOL

Going to block all other LSP files in use here if they do not have the "Check" build in

A lot of designers are not going to like this ( have no other choice atm until I find a good solution )

 

 

No I am the IT guy who screws with the coders

 

 

glad you're not my boss hahahaha

Link to comment
Share on other sites

Oh btw , IT apologized for the script thingy... I may use them for AutoCAD , but the extension scr is forbidden when it comes to email (as attachments) ... well , I can either paste the commands in mail body or rename scr file to txt should I have the need to mail them so that's one problem less , at least until the next time...

 

 

gr. Rlx

Link to comment
Share on other sites

parrantly is was never their intention to block it for use in ACAD

well I can also live with the block in email

that's what we call safety m8

I can easily break in using SCR in email using auto activation LOL

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...