pmxcad Posted September 9, 2014 Share Posted September 9, 2014 Hello, iàm looking for the lisp version of this diesel expression: %% It gets the last character of the filename. XXXXX-A (revision A) the filename lenght could be different so i want it to count from end to the beginning. Thanks, PmxCAD Quote Link to comment Share on other sites More sharing options...
Tharwat Posted September 9, 2014 Share Posted September 9, 2014 the filename lenght could be different so i want it to count from end to the beginning. What do you mean from end to beginning ? does it mean the base file name ? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 9, 2014 Share Posted September 9, 2014 Hello, iàm looking for the lisp version of this diesel expression: %% It gets the last character of the filename. XXXXX-A (revision A) the filename lenght could be different so i want it to count from end to the beginning. The LISP translation would be: (substr (getvar 'dwgname) (- (strlen (getvar 'dwgname)) 4) 1) However, one advantage of using LISP is the ability to more effectively test for conditions, and utilize both variables/parameters, and sub-functions: (vl-load-com) (defun _GetRevision (dwgName / i) ;; Example: (_GetRevision "XXXXX-A.dwg") ;; Returns: "A" (if (setq i (vl-string-search "-" dwgName)) (substr dwgName (+ 2 i) 1) ) ) Cheers Quote Link to comment Share on other sites More sharing options...
Stefan BMR Posted September 9, 2014 Share Posted September 9, 2014 (chr (last (vl-string->list (vl-filename-base (getvar 'dwgname))))) ((lambda (fn) (substr fn (strlen fn))) (vl-filename-base (getvar 'dwgname))) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 9, 2014 Share Posted September 9, 2014 ... Another that leaves the file extension, given OP's request for last character: (defun _GetRevision (dwgName / i) ;; Example: (_GetRevision "XXXXX-A.dwg") ;; Returns: "A" (if (setq i (vl-string-search "." dwgName)) (substr dwgName i 1) ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 9, 2014 Share Posted September 9, 2014 Another, similar to Stefan's suggestions: (apply '(lambda ( a b c ) (substr b (strlen b))) (fnsplitl (getvar 'dwgname))) Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 9, 2014 Author Share Posted September 9, 2014 Yes it works, but it works only for 1 tab. I use it in a script for plotting to pdf. Takes the active layou tab name with the revision from the filename to create a pdf. (tabname-A.PDF) it goes wrong with the next tab. The script stops before it is completed. It seems that data remains in memory. what am I doing wrong? PmxCAD (setq Revision (substr (getvar 'dwgname) (- (strlen (getvar 'dwgname)) 5) 2)) (setq DwgN (getvar "CTAB")) (setq Fname (substr DwgN 1 (- (strlen DwgN)0))) (setq name (strcat (getvar "DWGPREFIX") Fname Revision".pdf")) -plot !name Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 9, 2014 Share Posted September 9, 2014 (edited) what am I doing wrong? You're not using AUTOMATICPUB == 1. Edited September 9, 2014 by BlackBox Added link to online documentation. Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 9, 2014 Author Share Posted September 9, 2014 AUTOMATICPUB ? What does this variable? pmxcad Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 9, 2014 Share Posted September 9, 2014 AUTOMATICPUB ? What does this variable? It enables/disabled the AUTOPUBLISH mechanism first implemented back in 2009 version... I use it daily for plans production to produce a PDF each time I SAVE a drawing, and have even customized the behavior with this. HTH Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 10, 2014 Share Posted September 10, 2014 This will plot all your pdf's from layouts to the same location as the dwg and uses the layout name for each sheet http://www.cadtutor.net/forum/showthread.php?84430-Move-layout-Rename-layouts-Goto-layout version 2 is plot range http://www.cadtutor.net/forum/showthread.php?84430-Move-layout-Rename-layouts-Goto-layout Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 10, 2014 Author Share Posted September 10, 2014 BlackBox, Bigal I'll try but I think it does not work in my case. I like the layout plotting to PDF with layout name and behind the revision letter of the DWG file. Not all layouts has to be plotted to PDF, some plotted to DWF. Plotting with a script also sets the PDF to the DWG folder. I just want to know why the script stops when I want to plot. Another layout Maybe I should look over it again. Anyone have an idea? PmxCAD Quote Link to comment Share on other sites More sharing options...
pmxcad Posted September 10, 2014 Author Share Posted September 10, 2014 Found something. I have to clear the setq`s. (setq Revision nil) (setq DwgN nil) (setq Fname nil) (setq name nil) PmxCAD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.