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

Find mnl file folder with lisp

9 REPLIES 9
Reply
Message 1 of 10
rapidcad
1072 Views, 9 Replies

Find mnl file folder with lisp

Hi all, I think this is an easy question, but I am struggling to figure out how to get this.

I have a menu system I've developed and I've been setting the path for most blocks as a variable in the mnl file - the variable is the filepath stored as a string. This has been a great way to keep a single place to point for the library of blocks. However, I am about to share this menu with others who will not have my folder structure, so I want to somehow, just update the path variable in the mnl file automatically, by reading the mnl file's folder location - sort of like (getvar "DRAWINGPREFIX") but for the .mnl 

 

I can always prompt the user to go find the folder then write the string as the variable to the acaddoc.lsp, but it would be nicer to leave that alone, since the user might change his acaddoc every once in a while.

 

Is this something that can be puled out with vlax- functions?

 

Any help greatly appreciated.

 

Ron

 

ADN CAD Developer/Operator
9 REPLIES 9
Message 2 of 10
Kent1Cooper
in reply to: rapidcad

Assuming it's in some folder location listed in the Support File Search Paths:

 

(findfile "YourFileName.mnl")

 

will find where it is.  The result will include the complete path and file name.  You can trim off the latter part using (vl-string-position) with the from-the-end option to find where the last path delimiter [the ASCII code 92] is:

 

(setq

  pathandfile (findfile "YourFileName.mnl")

  pathonly (substr pathandfile 1 (1+ (vl-string-position 92 pathandfile 1 T)))

)

Kent Cooper, AIA
Message 3 of 10
rapidcad
in reply to: Kent1Cooper

Thanks Kent - I had just started goofing with that, but was hoping for a more sure fire way. I will have to pick this up again in the morning - Thanks for the help - you've shown me a nice application of the function.

 

I'll test and repost tomorrow morning.

Ron

ADN CAD Developer/Operator
Message 4 of 10
smaher12
in reply to: rapidcad

I have the following in my acaddoc.lsp.

 

(defun c:asd ()
  (startapp "explorer" (strcat "/n,/e," (getvar "roamablerootprefix") "support"))
  (princ)
)

Message 5 of 10
pbejse
in reply to: rapidcad


@rapidcad wrote:

Thanks Kent - I had just started goofing with that, but was hoping for a more sure fire way. I will have to pick this up again in the morning - Thanks for the help - you've shown me a nice application of the function.

 

I'll test and repost tomorrow morning.

Ron


What do you mean by "sure fire way" rapidcad?  which file are you wanting to modify anyway? the MNL file?

 

 

Message 6 of 10
rapidcad
in reply to: pbejse

Yeah, I was actually thinking of trying to write to the .mnl. If that's not possible, I'll try putting the variable in a file in the menu folder which I will have the user add to his support path. I was going to add the folder path myself using Don Butler's ADDPATH, but maybe I could prompt them for a path, run ADDPATH and put it in the search paths, then write the folder path as a variable into a settings file and have the .mnl file call the settings file locally from this same folder. I think that will work if I place a simple (load "SETTINGS.lsp")

 

Sometimes I have to talk these things out to make saense of them! Thanks for the help -

But, just out of curiosity - is it possible to write to the .mnl?

 

Ron 

ADN CAD Developer/Operator
Message 7 of 10
rapidcad
in reply to: smaher12

Thanks Smaher, I have been using something similar to append ACADDOC.lsp :

(setq lisppath "(load \"C:\\\\CAx\\\\Resource\\\\xCAD\\\\autocad\\\\tools\\\\acadtools.lsp\")")
(setq f(open (strcat (getvar "roamablerootprefix")"support\\Acaddoc.lsp") "a"))
(write-line lisppath f)
(close f)

 

ADN CAD Developer/Operator
Message 8 of 10
pbejse
in reply to: rapidcad


@rapidcad wrote:

Yeah, I was actually thinking of trying to write to the .mnl. If that's not possible, I'll try putting the variable in a file in the menu folder which I will have the user add to his support path. I was going to add the folder path myself using Don Butler's ADDPATH, but maybe I could prompt them for a path, run ADDPATH and put it in the search paths, then write the folder path as a variable into a settings file and have the .mnl file call the settings file locally from this same folder. I think that will work if I place a simple (load "SETTINGS.lsp")

 

Sometimes I have to talk these things out to make saense of them! Thanks for the help -

But, just out of curiosity - is it possible to write to the .mnl?

 

Ron 


Yes it is possible, its just a text file after all, but i would advise againts it.

 

But if  this would be a one time thingy and once you were able to "fix" the path for a specific user then its all done and over with? then I think ADDPATH would work for you.

 

Your issue here is the folder path for the blocks, I'm guessing the blocks are not on a shared drive/folder otherwise you wouldnt have any problem sharing the menu.

 

Can you confirm that this is the case? I can think of a couple of solutions to deal with this problem

Message 9 of 10
rapidcad
in reply to: pbejse

Thanks for the help. While I work with AutoCAD every day, I still consider myself a kludge when it comes to programming. I really couldn't do any of this if I wasn't studying the solutions of advanced programmers such as yourself.

 

I am putting together an installation package for users outside the corporation who will be using our library. They might need to place their copy of our folder (which has subfolders) in various places per their differing IT considerations. Because I am under a time crunch to put out a limited trial package, I think I will have to keep it simple for now.

 

I would ultimately like to build an installer that would prompt the user for the folder location to install to, copy the folder structure there from source files on media or web portal, open AutoCAD, copy existing workspace and profile, set the copes as active workspace and profile, add the paths and menu, place the variable string in the.mnl, and restart AutoCAD. Sounds like this ultimate vision is more than lisp based, since I have to unzip or get the source files from the web or something, as well as closing and starting AutoCAD. I personally can only work with lisp at this time. I poked around with VBA a little, but that was years ago, and I didn't write anything, I just modified other's code. So for now, I figure I'll Just write instructions for the user to get the files unzipped to their destination folder.

 

I have automated several of these things here at our company already, but we have control over folder locations and many other variables. I already have the following functions working:

 

I can prompt the user for the folder he has put our file structure in and capture that as the string for my variable.

I have seen how I can process the path so that it can be expressed as a lisp string and be recalled without formatting issues.

I can backup the workspace and profile and make the new ones (based on their existing) active.

I can add the paths to the profile using ADDPATH

I can add the menu as a partial through menuload

I can write the path variable defun string to ACADDOC.lsp or a Settings.lsp - whichever I choose

 

That's what I intend to combine in beta form this week - put these together for next week, along with a zip file and instructions.

 

If you know of a way to write the defun for the path variable to the .mnl (which would be in our folder structure, but placed anywhere on their network) this WOULD be a one time thing - at installation only, I will see if I can eliminate prompting the user for the folder path and just programmatically place it in the .mnl

 

What I could use is a way to get the path for our folder. I have looked at many ideas, but found nothing that works fast enough. Michael Puckett's ancient FILEFIND can be used to find my folder, but it is really slooow and could return multiple folders if the user saved the zip file to the same drive.

So for now I will plan on just prompting the user to pick the folder for me.

 

Any help would be welcome.

 

Ron

 

ADN CAD Developer/Operator
Message 10 of 10
rapidcad
in reply to: rapidcad

What I opted to do for the moment, was to instruct the users to unzip our folder structure to a read/writable folder, open a setup drawing in that folder, then start a setup lisp which runs on loading. The setup lisp does the following:

 

1. Checks to see if dwgname is the setup drawing

2. Uses findfile to find the mnl file (since it will be in this same folder) and set a pointer variable to the path string

3. Uses dwgprefix to set a pointer variable to the path string which will be used later

4. Backs up the current workspace

5. Makes a new workspace (copy of previous workspace renamed)

6. Backs up the profile

7. Makes a new profile from the previous profile

8. Exports the profile to the folder structure

9. Sets the new profile current

10. Checks to see if our menugroup is already there

11. if not, it uses menuload to load it as a partial

12. Runs addpath to add the path to the Options>Support Files search paths that dwgprefix captured (with some formatting regarding strings saved as variables)

13. Put the toolpalette path in the Options>Tool Palettes File Locations search paths as a second folder by using romablerootprefix to capture the typical AutoCAD structure and append it using vla-put-ToolPalettePath

14. Use write-line to place a carefully formatted verson of the path string variable captured in step 3 as a (setq path-variable string) into the mnl file

15. Exports the finished profile to the new folder structure as a backup for the new proper profile.

16. Prompts the user to restart AutoCAD.

 

The hardest thing was formatting the sting (setq path-variable string) so that it could be written using write-file to the mnl file. It had to survive being passed as a variable and yet emerge in the mnl file as a properly formatted string variable.

 

Here's what I used for appending the mnl file:

capture the paths

( If (= "TGDRAW SETUP.dwg" (getvar "dwgname"))
  (progn

(setq targetfile (findfile "TGDRAW.mnl"))
    (setq FilesPath (getvar "dwgprefix"))
    (setq RootPath (substr FilesPath 1 (- (strlen FilesPath) 7))

)

<all the other steps here>

(setq putLIBdir (strcat "(setq LIBdir \"" (vl-string-translate "\\" "/" FilesPath) "\")")  )
(setq f(open targetfile "a"))
(write-line putLIBdir f)
(close f)

 

I struggled to get the path to translate properly with the correct foreslashes and I needed it to contain a final foreslash for my string concatenations in all my menu programming.

 

This works great.  Hope it can be of use to someone if they are trying to write a setvar into a file sometime.

 

Ron

 

 

ADN CAD Developer/Operator

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

Post to forums  

Autodesk Design & Make Report

”Boost