MULTIPLE PDF IMPORT AS OBJECT

MULTIPLE PDF IMPORT AS OBJECT

sdhara.hit
Advocate Advocate
901 Views
8 Replies
Message 1 of 9

MULTIPLE PDF IMPORT AS OBJECT

sdhara.hit
Advocate
Advocate

I have xref many pdf in a cad model. now i want to use import as object under pdf underlay to all pdf in one command. can any one provide lsp ? 

 

Required lisp for this command by selecting all attached pdf.  

Command: _pdfimport
Specify first corner of area to import or [Polygonal/All/Settings] <All>: a
Keep, Detach or Unload PDF underlay? [Keep/Detach/Unload] <Unload>: d

 

 

 

0 Likes
Accepted solutions (1)
902 Views
8 Replies
Replies (8)
Message 2 of 9

imadHabash
Mentor
Mentor

Hi,

You can drag underlays directly into the current drawing.

Imad Habash

EESignature

0 Likes
Message 3 of 9

baksconstructor
Advocate
Advocate

It is not possible to convert PDF backgrounds into objects directly.
You need to re-import the PDF
Maybe this will help you to speed it up - AutoImportCAD 

0 Likes
Message 4 of 9

sdhara.hit
Advocate
Advocate

Command: _pdfimport
Specify first corner of area to import or [Polygonal/All/Settings] <All>: a
Keep, Detach or Unload PDF underlay? [Keep/Detach/Unload] <Unload>: d

 

 

I have to make lisp for this command by selecting all attached pdf.  

0 Likes
Message 5 of 9

paullimapa
Mentor
Mentor

try this:

(if (setq ss (ssget "_x" '((0 . "PDFUNDERLAY"))))
 (progn
  (setq count 0)
  (repeat (sslength ss)
   (command "_.pdfimport" (ssname ss count) "_A" "_D")
   (setq count (1+ count))
  ) ; repeat
 ) ; progn
) ; if

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 9

sdhara.hit
Advocate
Advocate

its working but only one page. can you update it? @paullimapa 

(defun c:PDF2DWG (/ ss count ent)
(if (setq ss (ssget "_X" '((0 . "PDFUNDERLAY")))) ; সমস্ত PDF Underlay নির্বাচন করুন
(progn
(setq count 0)
(while (< count (sslength ss))
(setq ent (ssname ss count)) ; বর্তমান PDF Underlay
(if (and ent (entget ent)) ; যদি বৈধ হয়
(progn
(vl-cmdf "_.pdfimport" ent "_A" "_D") ; Import as AutoCAD geometry & Detach
(princ (strcat "\nImported & detached: " (cdr (assoc 2 (entget ent))))) ; সফল হলে বার্তা দেখান
)
)
(setq count (1+ count)) ; পরবর্তী উপাদানে যান
) ; while
) ; progn
(princ "\nNo PDF Underlay found.") ; যদি কিছু না পাওয়া যায়
) ; if
(princ)
)

 

 

 

Command: PDF2DWG
_.pdfimport
Select PDF underlay or [File] <File>: Specify first corner of area to import or [Polygonal/All/Settings] <All>: _A
Keep, Detach or Unload PDF underlay? [Keep/Detach/Unload] <Unload>: _D
Binding PDF file C:\Users\sdhara\SystraGroup\Sambalpur Pre-Bid - Sambalpur Pre-Bid\Production\DOCs\IN\Client\Tender Docs\20250219\P&P.pdf, page 106 ...
Command:
Erreur : bad argument type: stringp nil

0 Likes
Message 7 of 9

cadffm
Consultant
Consultant
Accepted solution

a Version WITH the settings dialog

 

(defun c:PDFIMPORTUNDERLAY+ (/ ss n)
(and
(princ "\nSelect PDF-Underlays: ")
(setq n 0 ss (ssget '((0 . "PDFUNDERLAY"))))
(null(command "_.PDFIMPORT" (ssname ss n) "_settings" "_all" "_detach"))
(repeat (1-(sslength ss)) (command "_.PDFIMPORT" (ssname ss (setq n (1+ n))) "_all" "_detach"))
)
(princ)
)

Sebastian

Message 8 of 9

sdhara.hit
Advocate
Advocate

@cadffm Thanks, its working 🙂

0 Likes
Message 9 of 9

paullimapa
Mentor
Mentor

Nice work putting the code together.

But you can see where the error occurs in your code which is right after the detach: "_D"

So this line of code which you added after detaching the pdf is where it fails:

(princ (strcat "\nImported & detached: " (cdr (assoc 2 (entget ent))))) 

There are actually 2 reasons that's causing the error:

1. After the pdf is detached, the entity is removed from the dwg so there's no longer an entity to apply entget.

2. If you look at the entity data for pdf underlays there is no assoc 2 pair. So to get this you can use this code instead:

(getpropertyvalue ent "DefinitionId/Name")

So I would put your princ statement before you import and detach the pdf entity like this:

(progn
(princ (strcat "\nImported & detached: " (getpropertyvalue ent "DefinitionId/Name"))) ; সফল হলে বার্তা দেখান
(vl-cmdf "_.pdfimport" ent "_A" "_D") ; Import as AutoCAD geometry & Detach
)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes