Jump to content

Recommended Posts

Posted

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

Posted

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 ?

Posted
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

Posted

(chr (last (vl-string->list (vl-filename-base (getvar 'dwgname)))))

((lambda (fn) (substr fn (strlen fn))) (vl-filename-base (getvar 'dwgname)))

Posted

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

Posted

Another, similar to Stefan's suggestions:

(apply '(lambda ( a b c ) (substr b (strlen b))) (fnsplitl (getvar 'dwgname)))

Posted

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


Posted (edited)

what am I doing wrong?

 

You're not using AUTOMATICPUB == 1. :thumbsup:

Edited by BlackBox
Added link to online documentation.
Posted

AUTOMATICPUB ?

What does this variable?

 

pmxcad

Posted
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

Posted

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

Posted

Found something. I have to clear the setq`s.

 

(setq Revision nil) (setq DwgN nil) (setq Fname nil) (setq name nil)

 

PmxCAD

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...