Jump to content
DGRL

smal code to find itself LOL

Recommended Posts

DGRL

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

Share this post


Link to post
Share on other sites
rlx

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

Share this post


Link to post
Share on other sites
DGRL

@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

Share this post


Link to post
Share on other sites
DGRL

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

Share this post


Link to post
Share on other sites
rlx

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))



Share this post


Link to post
Share on other sites
DGRL

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

Share this post


Link to post
Share on other sites
rlx

sounds like a plan :thumbsup:

Share this post


Link to post
Share on other sites
DGRL

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

Share this post


Link to post
Share on other sites
rlx
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

Share this post


Link to post
Share on other sites
DGRL

I would give you a greencard LOL

Share this post


Link to post
Share on other sites
rlx
I would give you a greencard LOL

 

 

have created my own green card (not fully functional , but almost)

 

 

ps. in the options dialog 'S activates support dialog :-)

RlxProfile.lsp

Share this post


Link to post
Share on other sites
DGRL

send me pm with explanation about this lsp

Is this making an "profile" is AutoCAD with all needed settings?

Share this post


Link to post
Share on other sites
rlx

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

Share this post


Link to post
Share on other sites
DGRL

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

Share this post


Link to post
Share on other sites
DGRL

:rofl: MICRO SOFTIES :rofl:

:rofl: :rofl::rofl::rofl::rofl::rofl:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×