Need a LISP check to see if the drawing has a pdf underlay in it

Need a LISP check to see if the drawing has a pdf underlay in it

fk
Advocate Advocate
460 Views
5 Replies
Message 1 of 6

Need a LISP check to see if the drawing has a pdf underlay in it

fk
Advocate
Advocate

Hi,

can anyone help me with some LISP code that can check if the active drawing contains DWF, PDF, DGN, OLE underlays?

 

\Freddy

0 Likes
461 Views
5 Replies
Replies (5)
Message 2 of 6

ronjonp
Mentor
Mentor

Variable 'r' will hold a list of those items if found:

(defun c:foo (/ r)
  (vlax-for b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for o	b
      (and (wcmatch (strcase (vla-get-objectname o)) "*PDF*,*DWF*,*DGN*,*OLE*FRAME*")
	   (setq r (cons o r))
      )
    )
  )
  r
)
Message 3 of 6

fk
Advocate
Advocate

Many thanks. Easy when you know how.

That code works fine, as long as AutoCAD finds the "underlay" and as long as it is inserted into the drawing. It doesn't work as well if the "underlay" is "Not found" or "Unreferenced". How easy is it to also take into account such cases?

0 Likes
Message 4 of 6

fk
Advocate
Advocate

Anyone?

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

Check the entity type of objects in all those categories with:

(cdr (assoc 0 (entget (car (entsel "\nSelect an underlay object: ")))))

and if in all cases the types end with "UNDERLAY" with different prefixes, then this will find them:

(ssget "_X" '((0 . "*UNDERLAY")))

which I suspect [without testing] would ignore any that are unreferenced.

If you just want to know whether or not there are any, you could do something like this:

(prompt

  (strcat

    "\nThere are "

    (if (ssget "_X" '((0 . "*UNDERLAY"))) "" "no ")

    "Underlay object(s) in this drawing."

  ); strcat

); prompt

If you want to see them selected/gripped/highlighted, this will do that with all that are in the current space:

(sssetfirst nil (ssget "_X" '((0 . "*UNDERLAY"))))

Or they could be saved into a selection set to process however you like.

Kent Cooper, AIA
0 Likes
Message 6 of 6

Moshe-A
Mentor
Mentor

@fk hi,

 

From R200 to R2017 there was file dependencies object but it turn obsolete from R2018 so underlay objects move to dictionaries 

check dumpUnderlayDef command to retrieve underlay objects. i test it only on pdf, dwf files think OLE objects does not consider underlay

i do not have dgn to insert so i gamble on dictionary table name is similar to "ACAD_PDFDEFINITIONS", "ACAD_DWFDEFINITIONS" as "ACAD_DGNDEFINITIONS".

 

works even objects detached or erased 😀

 

enjoy

Moshe

 

 

; dump underlay definitions

(defun c:dumpUnderlayDef (/ adoc dict table AcDbDictionary AcDbObj i ename elist)
 (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
 (setq dict (vla-get-dictionaries adoc))
  
 (foreach table '("ACAD_PDFDEFINITIONS" "ACAD_DWFDEFINITIONS" "ACAD_DGNDEFINITIONS")
  (if (and
	 (not
	     (vl-catch-all-error-p
	       (setq AcDbDictionary (vl-catch-all-apply 'vla-item (list dict table)))
	     )
         )
         (> (vla-get-count AcDbDictionary) 0)
      )
   (progn
    (terpri)
    (princ table)
    (setq i 0)
    (while (< i (vla-get-count AcDbDictionary))
     (setq AcDbObj (vla-item AcDbDictionary i))
     (setq ename (vlax-vla-object->ename AcDbObj))
     (setq elist (entget ename))
     (terpri)
     (princ (cdr (assoc '1 elist)))
     (setq i (1+ i))
     (vlax-release-object AcDbObj)
    ); while
    
    (vlax-release-object AcDbDictionary)
   ); progn
  ); if

 ); foreach

 (vlax-release-object dict)
 (vlax-release-object adoc)

 (princ)
); c:dumpUnderlayDef