How to open file by AutoCAD commandline

How to open file by AutoCAD commandline

Anonymous
Not applicable
1,520 Views
1 Reply
Message 1 of 2

How to open file by AutoCAD commandline

Anonymous
Not applicable

Hi, I am trying to import a PDF using just the AutoCAD command line. I want to automate this process for purpose of a much bigger project. My code is below:

public static void SendACommandToAutoCAD(string userfile)

 

{

string command;

Document acDoc = Application.DocumentManager.MdiActiveDocument;

 

 

command = "._-PDFIMPORT f " + "'" + userfile + "'" + " 1 0,0 1.0 0";

acDoc.SendStringToExecute(command, true, false, false);

}

 

In order, ._-PDFIMPORT is the command, f is file or underlay, userfile is user's input of filepath, 1 is page number, 0,0 is position, 1.0 is scale factor, 0 is rotation. The only thing that changes for the purpose of this is userfile.

 

Please help me figure out why the command is not working. When I put it, it gets stuck at the dialog box to select the file and does not open the file. How do I get passed this dialog box?

 

If my code is bad please let me know any adjustments you would recommend.

 

Thank you so much!

0 Likes
1,521 Views
1 Reply
Reply (1)
Message 2 of 2

waseefur.rahman
Advocate
Advocate

 Hi,

Try this

 

ThisDrawing.SendCommand("FILEDIA" + vbCr + "0" + vbCr);

ThisDrawing.SendCommand("-IMPORT" + vbCr + "PDF" + vbCr + "ALL" + vbCr + "C:\File.pdf" + vbCr);

ThisDrawing.SendCommand("FILEDIA" + vbCr + "1" + vbCr);

if you use "FILEDIA" command then only you will be able to pass File path, or else the Dialog will be open.


 

 

0 Likes