getenv\setenv truncation

getenv\setenv truncation

nbawden
Advocate Advocate
585 Views
5 Replies
Message 1 of 6

getenv\setenv truncation

nbawden
Advocate
Advocate

I am using a getenv \ setenv function in my acad.lsp file to append an additional support file search path. as follows:

 

(setenv "ACAD" (strcat "C:\\Civil3D\\Support Files;" (getenv "ACAD")))

The problem is that the response is being truncated and only about 1/4 of the existing entries are being lost. It is either the length of the strig that is an issue or I also read somewhere that full stops can be a problem?

 

Our Support File Search Path list is long because of 3rd party programs - most of which use .bundle structures which always seem to result in additions to the list.

 

Is there better lisp code to achieve this? Can I just append instead of re-writing the string?

0 Likes
586 Views
5 Replies
Replies (5)
Message 2 of 6

dbroad
Mentor
Mentor

According to Microsoft, there is a 32767 character limit to an environmental variable, which you are most likely not hitting.

 

I also believe that the correct way of doing what you want is to set up a profile using the options command and setting up the support files from that point.  Once you set up the support files, you should not need to modify them using acad.lsp.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 6

dgorsman
Consultant
Consultant

There is a hard limit to the number of characters, but I'm not quite certain what that number is.  I routinely run into this problem with large numbers of search paths (and yes, we do need to change it.  The paths change for different clients).  If you export an ARG with the search path string past that limit the value changes from a string to hex-format:

 

"ACAD"=hex(2):50,00,3a,00,5c,00,41,00,75,00,74,00,6f,00,43,00,41,00,44,00,20,\
  00,41,00,70,00,70,00,73,00,5c,00,47,00,65,00,6e,00,65,00,72,00,69,00,63,00,\
  20,00,41,00,75,00,74,00,6f,00,43,00,41,00,44,00,5c,00,53,00,75,00,70,00,70,\
  00,6f,00,72,00,74,00,5c,00,4c,00,69,00,73,00,70,00,3b,00,47,00,3a,00,5c,00,\
  44,00,50,00,48,00,20,00,41,00,75,00,74,00,6f,00,43,00,41,00,44,00,20,00,53,\
  00,75,00,70,00,70,00,6f,00,72,00,74,00,5c,00,41,00,70,00,70,00,6c,00,69,00,\
  63,00,61,00,74,00,69,00,6f,00,6e,00,73,00,5c,00,41,00,75,00,74,00,6f,00,43,\
  00,41,00,44,00,5c,00,50,00,47,00,50,00,20,00,32,00,30,00,31,00,31,00,3b,00,\
  50,00,3a,00,5c,00,41,00,75,00,74,00,6f,00,43,00,41,00,44,00,20,00,41,00,70,\

 

I think it gets treated as a QWORD or some such by AutoCAD.  Its transparent from the REGEDIT side of things though - REGEDIT still reports it as a DWORD and lists everything.

 

I don't have a way around this directly.  I already have some client/application/generic search path system set up for my LISP routines which helps keep things short enough that its an infrequent problem.  One of the high priority tasks on my To Do list is to completely implement my own search path system so I can pull all of my search paths out, leaving only those absolutely necessary.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 4 of 6

nbawden
Advocate
Advocate

Thanks guys,

 

In the end I found a Lee Mac function that appears to work nicely:

 

;; Add Support File Search Paths at 'n'  -  Lee Mac
;; Adds a list of Support File Search Paths, excluding duplicates and invalid paths.
;; lst - [lst] list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; idx - [int] [optional] zero-based index at which to add new paths
;; Returns: [str] "ACAD" Environment String following modification


(defun LM:sfsp+n ( lst idx / add str )

    (defun add ( str new idx / pos )
        (if (< 0 idx)
            (if (setq pos (vl-string-position 59 str))
                (strcat (substr str 1 (1+ pos)) (add (substr str (+ pos 2)) new (1- idx)))
                (strcat ";" new)
            )
            (strcat new str ";")
        )
    )

    (setenv "ACAD"
        (add (setq str (vl-string-right-trim ";" (getenv "ACAD")))
            (apply 'strcat
                (mapcar '(lambda ( x ) (strcat x ";"))
                    (vl-remove-if
                       '(lambda ( x )
                            (or (vl-string-search (strcase x) (strcase str))
                                (not (findfile x))
                            )
                        )
                        (mapcar
                           '(lambda ( x )
                                (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x))
                            )
                            lst
                        )
                    )
                )
            )
            idx
        )
    )
)


(LM:sfsp+n '("C:\\Folder1" "C:\\Folder2" "C:\\Folder3") 0)

 When I load AutoCAD on a new computer for the first time with the above code in an acad.lsp file it succeeds in adding the additional support path I want. However the problem is that it occurs after the default template drawing has started to load so I still get missing .SHX error messages for files that reside in this additional support folder. From second time I start AutoCAD on that computer I have no further issues.

0 Likes
Message 5 of 6

dbroad
Mentor
Mentor

The appropriate way to add support paths is to use the options command.  This needs to be done only once.  No programming is necessary.  If you want to clone the profile from computer to computer, use the export and import functionality of the options command.  It creates an arg file that can be used to populate the profile settings to the registry safely.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 6 of 6

nbawden
Advocate
Advocate

Thanks for your thoughts again - we have to do it this way for reasons of deployment and how our office functions. Arg files no longer work for us becuase they screw up srusted paths. I have a working solution now that works for us so all is good.

0 Likes