Can't figure out what is wrong with this LISP

Can't figure out what is wrong with this LISP

Anonymous
Not applicable
1,461 Views
11 Replies
Message 1 of 12

Can't figure out what is wrong with this LISP

Anonymous
Not applicable

Hello,

 

I've actually posted this question/topic on the regular AutoCAD LISP Forum, but ended up boiling it down to an issue with either my computer or using AutoCAD Architectural 2019 (I've recently started using ACA, but have been using ACAD for 8 years).

 

Both of the LISPs pasted below do the same thing and work for the other people on the forum I created, but they are not using AutoCAD Architectural 2019.  I'm posting this here on this forum trying to figure out if it's an ACA issue or is an issue with my computer.

 

 

(defun c:CU ( / ppath newpath fname)
(vl-load-com)
	(setvar "filedia" 0)
	(setq ppath (getvar "dwgprefix"))
	(setq newpath (vl-string-subst "\\PDF\\" "\\CAD\\" ppath))
	(setq fname (strcat newpath (vl-filename-base (getvar "dwgname")) ".pdf"))
		(command "-export"
		"pdf"
		"current"
		"no"
		fname
	)
	(setvar "filedia" 1)
(princ)
)
(defun c:CU ( / pdffile)
  (setvar "filedia" 0)
   (setq pdffile 
      (strcat 
         (vl-string-subst "\\PDF\\" "\\CAD\\" (getvar "dwgprefix"))
         (vl-filename-base (getvar "dwgname")) 
         ".pdf"
      )
   )
   (command "-export" "_P" "_C" "_N" pdffile)
  (setvar "filedia" 1)
   (princ)
)

 

Here is the previous forum I created.

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/can-t-figure-out-what-s-wrong-with-t...

 

Any help is greatly appreciated.  Thank you!

0 Likes
Accepted solutions (1)
1,462 Views
11 Replies
Replies (11)
Message 2 of 12

dlanorh
Advisor
Advisor

Removed

I am not one of the robots you're looking for

0 Likes
Message 3 of 12

Anonymous
Not applicable

@dlanorh

adding the *'s did help with automatically PDFing the file, but it still did not change the PDF output file location.  It placed the PDF in the same folder as the DWG.

0 Likes
Message 4 of 12

BeKirra
Advisor
Advisor

Please check your drawing path.

I suspect the your local path does not have a folder named as "CAD".

If this is the case,

  • you may have to replace "CAD" with your drawing folder name in the line below in your code.
  • you also create a destination folder named as "PDF".
(setq newpath (vl-string-subst "\\PDF\\" "\\CAD\\" ppath))

 

Here is an example taken from "HELP".

_$ (vl-string-subst "Obi-wan" "Ben" "Ben Kenobi")

Result: "Obi-wan Kenobi"

 

And Please note that the search is case-sensitive, and that vl-string-subst substitutes only the first occurrence it finds of the string.

 

HTH

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 5 of 12

dlanorh
Advisor
Advisor
I was assuming it was like wcmatch but it isn't.

I am not one of the robots you're looking for

0 Likes
Message 6 of 12

roland.r71
Collaborator
Collaborator

That actually doen't matter.

As I wrote the second version of the c:CU as posted here, I know for sure.

I did not (at first) create the "\CAD\" path for testing. So it could not be replaced by "\PDF\"

As a result, the PDF ended up next to the DWG. (basically just using "DWGPREFIX")

 

As the code is quite short & simple, the only 2 things I can come up with:

1. Does ACA support the visualLisp commands (the vl-string-subst & vl-filename-base functions) ?

2. Does ACA support the "-EXPORT" command ?

If both are "yes", there's something wrong with the system/installation.

If one of 'm is "No", well, then you found the problem. ( & I would be very surprised)

0 Likes
Message 7 of 12

cadffm
Consultant
Consultant
Accepted solution

@Anonymous

Your code works in Architecture (ACA2019.0.2 / ACAD 2019.1) for me.

-when you are in paperspace

-when your drawing is located in a path with a folder "CAD" and

-when ther is a existing path with the wanted "PDF" folder.


However, you should check in the code beforehand


1. whether the current file is in a path containing a folder "CAD"
    (If not, either cancel or ..)


2. Only then does the path adaptation CAD-> PDF make sense
    (If there is no 'CAD' folder and you do not want to cancel the program,
    the alternative would be to use the same folder as the DWG and alert the user with an ALERT notice)

 

3. You will not notice the BIG and the small spelling! Use STRCASE for compare/subst strings

 

(if (vl-string-search "\\CAD\\" (strcase(getvar "dwgprefix")))
(setq newpath (vl-string-subst "\\PDF\\" "\\CAD\\" (strcase(getvar "dwgprefix"))))
(progn (setq newpath (getvar "dwgprefix"))(alert(strcat "Targetfolder: " (getvar 'dwgprefix))))
)


4. Even if there is a 'CAD' folder, your code will not check if there is a 'PDF' folder.
    That you would have to check and create the folder with Lisp if it is not the case.

    http://help.autodesk.com/view/ACD/2019/ENU/?query=vl%20directory&knowledgeSource=Product%20Documentation

5. The FILEDIA is a superfluous source of problems, remove it.

 

Sebastian

0 Likes
Message 8 of 12

Anonymous
Not applicable

The folder structure is definitely there.

 

When manual type part of the LISP in the AutoCAD command line, the path appears correctly, but when I run the LISP, it just does not remember the new PDF path.  (see attachment)

 

@cadffm BUUUTTTT.........it just worked.  I removed the FILEDIA variable from the LISP and it suddenly started working........

Just out of curiosity, why would FILEDIA cause this problem?

0 Likes
Message 9 of 12

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

@dlanorh

adding the *'s did help with automatically PDFing the file, but it still did not change the PDF output file location.  It placed the PDF in the same folder as the DWG.


... right.

I didn't notice this post before, but together with @cadffm confirmation it works...

 

With the other thread you mentioned you wanted these path, explicitly.

...so I assumed you spoke of existing file structure.

 

However, this proves (to me) that's not the case.

As I've explained before, if the file to PDF is NOT inside a path containing CAD, it will NOT be replaced by PDF & the pdf ends up with the DWG (as happens to you)

If there is a CAD, but no PDF path, I'm not sure what will happen, but it won't be good.

 

So, the only thing "wrong" with the lisp is that it doesn't check if these 2 directories truely exist. It assumes they do. So to solve it, either build in a check, or make sure both the ...CAD... & ...PDF... directories exist.

0 Likes
Message 10 of 12

roland.r71
Collaborator
Collaborator

Smiley LOL

I told you it worked for me, WITHOUT the filedia. Smiley Tongue

 

It's a bit weird it has such influence, but it does make some sense as it is connected to supplying the path for any output file, by using a dialog or not.

 

As using (command ...) is without dialog by default you don't need it, but setting it anyway proves to be destructive in this case.

0 Likes
Message 11 of 12

Anonymous
Not applicable

.....it just stopped working again....I think I have to reinstall ACA

0 Likes
Message 12 of 12

roland.r71
Collaborator
Collaborator

If the paths are correct and you use the code as I posted it with the other topic (so, without the filedia) & make sure you do have the (vl-load-com) somewhere (as I put it outside the function (you only need to use it ones during a ACAD session))

 

It should work. (its realy a simple piece of code where there isn't much that can go wrong, beyond the paths)

 

If not, you might indeed need to reinstall.

But first... try removing any other lisps loaded with ACADDOC or APPLOAD to make sure there isn't one causing trouble surfacing when using this function. It wouldn't be the first time another lisp is causing trouble.