Lisp Xref Attached using CSV change the file/dwg name to SMALL letter it should

Lisp Xref Attached using CSV change the file/dwg name to SMALL letter it should

nichkherbsman
Advocate Advocate
1,500 Views
9 Replies
Message 1 of 10

Lisp Xref Attached using CSV change the file/dwg name to SMALL letter it should

nichkherbsman
Advocate
Advocate

NEW_WrongName-Xref.PNGOLD_RightName-Xref.PNGHi,

I need help, after I use the lisp below the file name in xref tab has change to small letter (like NEW_WrongName-Xref). It should be just like the original file name (like OLD_RightName-Xref).

Is it the lisp or the Autocad itself?

See the image below:

 

Thank you.

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Accepted solutions (3)
1,501 Views
9 Replies
Replies (9)
Message 2 of 10

nichkherbsman
Advocate
Advocate

I forgot to include the lisp.

Here it is:

 

(defun c:xcsv (/ *error* fileo files fname line oldlay xref)

(defun *error* (msg)
(if fileo
(close fileo)
)
(if oldlay
(setvar 'CLAYER oldlay)
)
(cond ((not msg))
((member msg '("Function cancelled" "quit / exit abort")))
((princ (strcat "\n** Error: " msg " ** ")))
)
(princ)
)

(if (setq fname (getfiled "Select a .csv file to read" "C:/" "csv" 8))
(progn
(setq oldlay (getvar 'CLAYER))
(if (tblsearch "layer" "Z_XREF")
(setvar "clayer" "Z_XREF")
(command "_.-layer" "_M" "Z_XREF" "")
)
(setq fileo (open fname "r"))
(while (setq line (read-line fileo))
(setq line (vl-string-translate "\\" "/" line))
(setq files (cons line files))
)
(if files
(foreach file files
(if (setq xref (findfile file))
(command "_.-xref" "_o" xref "_S" "1.0" "_R" "0.0" (list 0 0 0) "_.-xref" "_T" "*" "_R")
)
)
)
)
)
(*error* nil)
(princ)
)

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Message 3 of 10

JamesMaeding
Advisor
Advisor
Accepted solution

@nichkherbsman 

the (findfile ...) returns the case you fed it, I just tested that.

(findfile "MyLisp.lsp") returns C:\Temp\MyLisp.lsp

(findfile "mylisp.lsp") returns C:\Temp\mylisp.lsp

so whatever is in the csv is what you get for the path.

The question is how to get the case of the file as explorer shows it, not your csv.

I recalled using Scripting.FileSystemObject for some of my routines for speed, and put this together:

(defun Get-Real-Case ( Path / fsObj abPth)
  (vl-load-com)
  (and (setq fsObj(vlax-create-object "Scripting.FileSystemObject"))
       (FINDFILE Path)
       (not (vl-catch-all-error-p (setq abPth (vl-catch-all-apply 'vlax-invoke-method (list fsObj 'GetAbsolutePathName Path)))))
  )
  (vlax-release-object fsObj)
   abPth
)

so change line:

(if (setq xref (findfile file))

to:

(if (setq xref (Get-Real-Case file))

and that should do it. thx

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 4 of 10

nichkherbsman
Advocate
Advocate

Thank you very much.

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Message 5 of 10

nichkherbsman
Advocate
Advocate

I try the lisp but the result is same, Lower case.

This is the lisp:

 

(defun c:xcsvv2 (/ *error* fileo files fname line oldlay xref)

(defun *error* (msg)
(if fileo
(close fileo)
)
(if oldlay
(setvar 'CLAYER oldlay)
)
(cond ((not msg))
((member msg '("Function cancelled" "quit / exit abort")))
((princ (strcat "\n** Error: " msg " ** ")))
)
(princ)
)

(defun Get-Real-Case ( Path / fsObj abPth)
(vl-load-com)
(and (setq fsObj(vlax-create-object "Scripting.FileSystemObject"))
(FINDFILE Path)
(not (vl-catch-all-error-p (setq abPth (vl-catch-all-apply 'vlax-invoke-method (list fsObj 'GetAbsolutePathName Path)))))
)
(vlax-release-object fsObj)
abPth
)

(if (setq fname (getfiled "Select a .csv file to read" "C:/" "csv" 8))
(progn
(setq oldlay (getvar 'CLAYER))
(if (tblsearch "layer" "Z_XREF")
(setvar "clayer" "Z_XREF")
(command "_.-layer" "_M" "Z_XREF" "")
)
(setq fileo (open fname "r"))
(while (setq line (read-line fileo))
(setq line (vl-string-translate "\\" "/" line))
(setq files (cons line files))
)
(if files
(foreach file files
(if (setq xref (Get-Real-Case file))
(command "_.-xref" "_o" xref "_S" "1.0" "_R" "0.0" (list 0 0 0) "_.-xref" "_T" "*" "_R")
)
)
)
)
)
(*error* nil)
(princ)
)NEW_WrongName-Xref2.PNG

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Message 6 of 10

JamesMaeding
Advisor
Advisor
Accepted solution

@nichkherbsman 

ah, perfect learning situation. Couple thing to mention that will help you in the future...

1) post indented code using the </> button. Just paste in the window that pops up.

Note that I use tabs in lisp to indent which is 2 spaces wide in the VLIDE. I replace those tabs with 2 spaces before posting here as the code window expands them pretty wide.

2) To test the issue at hand, we really only need to test the (Get-Real-Case file) statement. You posted your entire code, but just said it did not work. What you need to do is post a test statement and its return, like:

(Get-Real-Case "C:\\temp\\MyTest.lsp") returns:

c:\temp\mytest.lsp

or whatever the test does.

Stay focused on the problem statement, then attach your lisp if you want but throwing the whole codeset up without that is not very effective as people don't like to figure out what changed and so on, only to discover its all the same but one statement.

Please do the test statement mentioned and post the return. thx

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 7 of 10

JamesMaeding
Advisor
Advisor

@nichkherbsman 

Did it work? I thought you were saying it did not. Cool if it did 🙂


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 8 of 10

nichkherbsman
Advocate
Advocate

@JamesMaeding 

Hi Sir,

 

Still didn't work. I don't know where to find the  error?

Sorry I'm not that good in scripting. Can you help me how to combine this code/lisp?

Thank you.

 

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Message 9 of 10

nichkherbsman
Advocate
Advocate

@JamesMaeding  Hi I tried it to lower version like Acad 2016 and the lisp works but in 2019 it did'nt work, why is that?

 

thank you.

NiCHKCiD
BIM Modeler
Technical Officer
Technical Designer
Sr. Draftsman
0 Likes
Message 10 of 10

JamesMaeding
Advisor
Advisor
Accepted solution

@nichkherbsman 

There is no reason, I have used this code forever.

You need to open the code in the VLIDE, set a breakpoint (F9), pick Tools->Load text in editor.

Then run the function at command line and use F8 and shiftF8 to walk through the code.

It will stop where it glitches.

My guess is it will get to the command statement, so you may have to see if your 2016 is offering the exact same questions as 2019 or whatever.

This is the perfect chance for you to learn this and will give you the ability to troubleshoot other lisps.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes