Add pause to the lisp

Add pause to the lisp

Prashanthr
Enthusiast Enthusiast
1,704 Views
17 Replies
Message 1 of 18

Add pause to the lisp

Prashanthr
Enthusiast
Enthusiast

Hello Everyone,

 

I am still learning lisp and thought of creating a lisp to attach pdf to the drawing as using the command "PDFATTACH" takes time to load a pdf with more than 100 pages and scrolling down the list to select the pages is time consuming.

 

(defun c:PFF()
(command "-PDFATTACH" "C:\XXX\XXX" "\\" "\\" "954" "0")
(princ)
)

 

When I run this lisp it says "C:XXX‚XXX not found. Can anyone help me out? 

I want the lisp to pause for user input for "page number" and "scale". I even tried adding PAUSE instead of "\\", but still it didn't work. 

Thanks in advance.

 

0 Likes
Accepted solutions (2)
1,705 Views
17 Replies
Replies (17)
Message 2 of 18

ВeekeeCZ
Consultant
Consultant

Post real file name.

Message 3 of 18

Kent1Cooper
Consultant
Consultant

Try it with either double back-slashes or single forward-slashes as separators in the file path.

Kent Cooper, AIA
0 Likes
Message 4 of 18

pbejse
Mentor
Mentor

Here you go.

paused.png

Message 5 of 18

Prashanthr
Enthusiast
Enthusiast

Hi @ВeekeeCZ 

 

Here is the file name: 11_STATE___GD11___PERMIT_FOR_ISSUE_DRAWING.pdf

0 Likes
Message 6 of 18

Prashanthr
Enthusiast
Enthusiast

Hi @Kent1Cooper 

 

I tried to double backslash and forward slash as well, but doing so is making autocad go crazy. I am able see loading icon constantly rotating and pressing ESC does not  me Exit out of this command. I had to force close AutoCAD.

0 Likes
Message 7 of 18

Prashanthr
Enthusiast
Enthusiast

 

@pbejse  oh man!! This is working so awesome 😂😂🤣 

0 Likes
Message 8 of 18

Sea-Haven
Mentor
Mentor

maybe this 

(command "-PDFATTACH" "d:/acadtemp/vba-tutorial.pdf" (getint "\nEnter page number ") (getstring "\nenter insertion point x,y  ") 954 0)

 

 

0 Likes
Message 9 of 18

Prashanthr
Enthusiast
Enthusiast

Hi @Sea-Haven 

 

I tried this, but its not working, I get the prompt to enter the "page number" but the command history shows the pdf is not found. 

0 Likes
Message 10 of 18

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, I did it in a more complex way because... if I did it the simplest way I know it was crushing my acad.

 

(defun c:PFF ( / g p s)
  (if (and (setq g (cond ((getint "\nPage <1>: ")) (1)))
	   (setq p (getpoint "\nPoint: "))
	   (setq s (cond ((getreal "\nScale <1>: ")) (1)))
	   )
    (command "-PDFATTACH" "c:\\Users\\USer\\Dropbox\\nome_xco_me_startlist.pdf" g "_non" p s 0))
  (princ)
)

 

 
Message 11 of 18

Prashanthr
Enthusiast
Enthusiast

Hi @ВeekeeCZ 

Thank you. This lisp also is not working. Not sure why its working. I assumed creating a lisp for this task to be very easy to deal with but its not 😅

Here is the screenshot of the command history.

Prashanthr_0-1624532794309.png

 

0 Likes
Message 12 of 18

ВeekeeCZ
Consultant
Consultant

The screenshot shows that it does not find the file. So the part marked with red lines by you is the one, where the issue is.

0 Likes
Message 13 of 18

hmsilva
Mentor
Mentor
Accepted solution

@Prashanthr try this slightly modified code from @ВeekeeCZ 

(defun c:PFF ( / f g p s)
  (if (and (setq g (cond ((getint "\nPage <1>: ")) (1)))
	   (setq p (getpoint "\nPoint: "))
	   (setq s (cond ((getreal "\nScale <1>: ")) (1)))
	   (setq f (getfiled "Select a PDF File" "" "pdf" 0))
	   )
    (progn
      (command "-PDFATTACH" f g "_non" p s 0)
      (print f)
    )
    )
  (princ)
)

will ask you to select the pdf file.

ex:

Command: PFF
Page <1>:
Point:
Scale <1>: -PDFATTACH Path to PDF file to attach: C:\Users\Test\Documents\water-controls.pdf Enter page number or [?] <1>: 1
Specify insertion point: _non
Base image size: Width: 8.2677, Height: 11.6929, Undefined
Specify scale factor or [Unit] <1.0000>: 1
Specify rotation <90.0000>: 0
Command:
"C:\\Users\\Test\\Documents\\water-controls.pdf"  <- copy and paste this line into the original code, it's the correct path...

Command: 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 14 of 18

Prashanthr
Enthusiast
Enthusiast

Hi @ВeekeeCZ 

I tried a different pdf file in different location and the lisp works perfect 😊 Thank you 🤗

0 Likes
Message 15 of 18

Prashanthr
Enthusiast
Enthusiast

Hi @hmsilva 

This lisp works great! But one problem is that every time I need to browse the location of the folder and it doesn't remember the earlier used locations 😅 This can be overcome by adding the location in the lisp, but it would be more awesome if it would remember the location last used 😄

0 Likes
Message 16 of 18

pendean
Community Legend
Community Legend
0 Likes
Message 17 of 18

hmsilva
Mentor
Mentor

@Prashanthr wrote:

Hi @hmsilva 

This lisp works great! But one problem is that every time I need to browse the location of the folder and it doesn't remember the earlier used locations 😅 This can be overcome by adding the location in the lisp, but it would be more awesome if it would remember the location last used 😄


@Prashanthr 

getfiled function don't remember last file location, but we can hardcode a path...

the code line

(setq f (getfiled "Select a PDF File" "" "pdf" 0))

 don't have a location to start the file selection, but changing the "" to a valid path, it will start there the 

ex:

(setq f (getfiled "Select a PDF File" "H:\\Test\\" "pdf" 0))

will start the selection in "H:\\Test\\" folder...

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 18 of 18

ВeekeeCZ
Consultant
Consultant

Just out of today's misery here's a bit enhanced update.

 

(defun c:PFF ( / f p)
(vl-load-com)
  (or *pff-h* (setq *pff-h* "c:\\Users\\user\\Dropbox")) ; defaults
  (or *pff-g* (setq *pff-g* 1))
  (or *pff-s* (setq *pff-s* 1))
    
  (if (and (setq f (getfiled "Select a PDF File" (strcat *pff-path* "\\") "pdf" 0))
	   (setq *pff-g* (cond ((getint (strcat "\nPage <" (itoa *pff-g*) ">: "))) (*pff-g*)))
	   (setq *pff-s* (cond ((getint (strcat "\nScale <" (itoa *pff-s*) ">: "))) (*pff-s*)))
	   (setq p (getpoint "\nPoint: "))
	   (setq *pff-h* (vl-filename-directory f))
	   )
    (progn
      (command "-PDFATTACH" f *pff-g* "_non" p *pff-s* 0)
      (print f)
    )
    )
  (princ)
)