Nick,
For item #1:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function: GetRemoteDoc ;;;
;;; Purpose: Retrieves the document object for the specified drawing file, pulling it from ;;;
;;; the documents collection if it occurs there. ;;;
;;; Arguments: ;;;
;;; fname String - the fully qualified pathname of the source file, with ;;;
;;; extension. ;;;
;;; Returns: an objectDbx document object ;;;
;;; Note: Don't forget to release the object ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetRemoteDoc (fname / dbxstr dbxdoc objDocs ActiveDwg)
(setq
objDocs (vla-get-documents (vlax-get-acad-object))
fname (if (dos_uncpath fname)
(dos_uncpath fname)
fname
)
ActiveDwg (strcase (findfile (strcat (getvar "dwgprefix") (getvar "dwgname"))))
ActiveDwg (if (dos_uncpath ActiveDwg)
(dos_uncpath ActiveDwg)
ActiveDwg
)
)
(cond
;;it is the active drawing
((= (strcase (findfile fname)) ActiveDwg)
(vla-get-activedocument (vlax-get-acad-object))
)
;;It's already open
((and
;;The filename is in the documents collection
(null
(vl-catch-all-error-p
(setq dbxdoc (vl-catch-all-apply
'vla-item
(list
objdocs
(strcat (vl-filename-base fname) ".DWG")
)
)
)
)
)
;;The drawing in the documents collection has the correct path
(= (strcase (findfile fname)) (strcase (findfile (vla-get-fullname dbxdoc))))
) ;end and
dbxdoc
)
;;we can open it with objectdbx
((setq fname (findfile fname))
(setq
DBXstr (cond
((< (atof (getvar "ACADVER")) 16.0)
"ObjectDBX.AxDbDocument"
)
(T (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2)))
)
DBXDoc (vla-getinterfaceobject (vlax-get-acad-object) DBXstr)
)
(vla-open DBXDoc fname)
dbxdoc
) ;end cond findfile fname
) ;end cond
)
For item #2:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function: GetInserts ;;;
;;; Purpose: Retrieves all insert objects with attributes from a remote document ;;;
;;; Arguments: ;;;
;;; doc A document object ;;;
;;; Returns: A list of lists as follows ;;;
;;; ( ;;;
;;; (Insertion1 (tagstring1 . value1)(tagstring2 . value2)...) ;;;
;;; (Insertion2 (tagstring1 . value1)(tagstring2 . value2)...) ;;;
;;; ... ;;;
;;; ) ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun GetInserts (
doc
/
rtlist
)
;;for each object in paperspace
(vlax-for objIns (vla-get-paperspace doc)
;;if it is a blockref and it has attributes
(if (and (= "AcDbBlockReference" (vla-get-objectname objins))
(vlax-property-available-p objins "HASATTRIBUTES")
(= :vlax-true (vla-get-hasattributes objins))
) ;end and
;;add the blockref object to our list to return
(setq
rtlist (cons
(cons
(vla-get-effectivename objins)
(vl-catch-all-apply 'getatts (list objins))
)
rtlist
)
)
) ;end if
) ;end vlax-for paperspace
;;for each object in modelspace
(vlax-for objIns (vla-get-modelspace doc)
;;if it is a blockref and it has attributes
(if (and (= "AcDbBlockReference" (vla-get-objectname objins))
(vlax-property-available-p objins "HASATTRIBUTES")
(= :vlax-true (vla-get-hasattributes objins))
) ;end and
;;add the blockref object to our list to return
(setq
rtlist (cons
(cons
(vla-get-effectivename objins)
(vl-catch-all-apply 'getatts (list objins))
)
rtlist
)
) ;end progn
) ;end if
)
(vl-remove-if (function (lambda (ins) (vl-catch-all-error-p (cdr ins)))) rtlist)
) ;end getinserts
GetInserts, along with something to the tune of:(assoc "ANSI-E" (setq AllInserts (GetInserts(GetRemoteDoc MyFile))))
will tell you if your ANSI-E block exists in the drawing. Once you have that, you can gather all the REVISION blocks, thus:
(vl-remove-if-not
(function
(lambda(ins)
(= "REVISION" (car ins))
)
)
AllInserts
)
Play with it, see if it makes sense. If you need help beyond this just ask.
Mike