Importing a PDF using .SendCommand and a path?

Importing a PDF using .SendCommand and a path?

Anonymous
Not applicable
3,017 Views
10 Replies
Message 1 of 11

Importing a PDF using .SendCommand and a path?

Anonymous
Not applicable

I have the following code that essentially presses the "PDF import" button: 

 

Sub ImportMultiPDF()
    'This opens the MSO file dialog picker to search for a PDF to import.
    ThisDrawing.SendCommand "-PDFIMPORT" & vbCr & vbCr
'Command to open a PDF at a specific path goes next... End Sub

My goals:

1. Import a pdf given a path to the pdf

2. Repeat above .SendCommand and additional string inputs to insert an entire multi-page PDF document, page by page, at insertion points specified by a constant page scale. 

 

In sum, I want to automate the task of importing a PDF page by page, choose where to insert each page, and how to scale them. Each page takes a minute to complete, and some documents are quite long. 

I'm currently stuck on the file path, you have to click on a PDF document after pressing PDF import. 

0 Likes
3,018 Views
10 Replies
Replies (10)
Message 2 of 11

Ed__Jobe
Mentor
Mentor

That's one of the problems of using SendCommand, you can't change the command. You could type F for File, however, the command opens the file dialog rather than allowing a true command line input. BTW, that's not an MSO file picker, its an AutoCAD dialog.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 11

Anonymous
Not applicable

So, as I feared, you're confirming that there's no reasonable way to use VBA to import a PDF from a path? There really should be a pdfImport function in VBA with attributes such as path. I'd love that feature. 

0 Likes
Message 4 of 11

Ed__Jobe
Mentor
Mentor

@Anonymous wrote:

I'd love that feature. 


I wouldn't hold my breath. More practical would be for them to correctly implement the command line version. It shouldn't present dialogs. You can submit this to the AutoCAD wish list at augi.com.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 11

maratovich
Advisor
Advisor

PDFIMPORT no support for COM. Not possible to use from VBA
Maybe this one comes in handy:

 

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 6 of 11

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

how about sending a LISP command so you can send the filename to the command line?

(command "_-PDFIMPORT" "_FILE" "C:/TEMP/myPDF.pdf" "1" "0,0" "1.0" "0.0")

Is that what you are looking for?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 11

bknightALS4H
Participant
Participant

Bringing this back from the dead - it appears that the command line version of "PDFIMPORT" doesn't really support passing the filename - it requires use of the file selection dialog. 

 

So close yet so far! 

 

 

Any other options to script this? I have hundreds of PDFs I need to attach. 

0 Likes
Message 8 of 11

Ed__Jobe
Mentor
Mentor

ThisDrawing.SetVariable "filedia", 0

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 9 of 11

bknightALS4H
Participant
Participant

Even with the filedia system variable set to 0 I still have issues.

 

When I type the command and give it a path rather than typing "File" to open the dialog, it gives me *Invalid Selection*


Also trying this and getting issues with the path getting passed properly - seems to lose its formatting:

Command: (command "_-PDFIMPORT" "_FILE" "C:\Users\BillKnight\Documents\Acade 2020\AeData\Proj\DrawingTests\test2.pdf" "1" "0,0" "1.0" "0.0" )
_-PDFIMPORT
Select PDF underlay or [File] <File>: _FILE
Enter filename for PDF import: C:UUsersBillKnightDocumentsAcade 2020AeDataProjDrawingTests       est2.pdf

 

0 Likes
Message 10 of 11

bknightALS4H
Participant
Participant

Nevermind, I got it working! I just had to escape the "\" in my path with another \

 

This works! 

(command "_-PDFIMPORT" "_FILE" "C:\\Users\\BillKnight\\Documents\\Acade 2020\\AeData\\Proj\\DrawingTests\\test2.pdf" "1" "0,0" "1.0" "0.0" )
0 Likes
Message 11 of 11

Ed__Jobe
Mentor
Mentor

That's lisp. This works for me.

Sub pdftest()
    ThisDrawing.SetVariable "filedia", 0
    ThisDrawing.SendCommand "-pdfimport" & vbCr & _
                            "file" & vbCr & _
                            """N:\filepath\1012401C01.pdf""" & vbCr & _
                            "1" & vbCr & _
                            "0,0" & vbCr & _
                            "1.0" & vbCr & _
                            "0" & vbCr
    ThisDrawing.SetVariable "filedia", 1
End Sub

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes