TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HD on December 01, 2005, 08:35:23 AM
-
Hello,
I would like to use ObjectDBX and Visual LISP to do the following. The problem that I am having is that I don't know enough about ObjectDBX.
1) Open a drawing from a particular directory
2) Search opened drawing for a block named ANSI-E
3) If the ANSI-E block exists, collect all blocks named REVISION
4) For each REVISION block, procure the attribute value from the attribute name REVLEVEL.
5) Generate a report with the drawing name and the highest attribute value read from the REVLEVEL attribute name.
6) Close the drawing
7) Process the next drawing
After reviewing the above tasks, I could use help with items 2 through 4. I realize that these items are the "meat" of the program, but any help would be greatly appreciated.
Thanks!
-
One of these may get you started
Re: Change the same details of a number of drawing titleblocks (http://www.theswamp.org/forum/index.php?topic=7335.msg91135#msg91135)
DBX Testing (http://www.theswamp.org/forum/index.php?topic=6307.0)
run a lisp in dwgs WITHOUT opening the dwgs? (http://www.theswamp.org/forum/index.php?topic=7498.0)
Jeff_M or anyone familiar with ObjectDBX (http://www.theswamp.org/forum/index.php?topic=3650.0)
Find Text in a Closed Drawing (http://www.theswamp.org/forum/index.php?topic=2671.0)
Block Adding (http://www.theswamp.org/forum/index.php?topic=1821.0)
-
One of these may get you started
Re: Change the same details of a number of drawing titleblocks (http://www.theswamp.org/forum/index.php?topic=7335.msg91135#msg91135)
DBX Testing (http://www.theswamp.org/forum/index.php?topic=6307.0)
run a lisp in dwgs WITHOUT opening the dwgs? (http://www.theswamp.org/forum/index.php?topic=7498.0)
Jeff_M or anyone familiar with ObjectDBX (http://www.theswamp.org/forum/index.php?topic=3650.0)
Find Text in a Closed Drawing (http://www.theswamp.org/forum/index.php?topic=2671.0)
Block Adding (http://www.theswamp.org/forum/index.php?topic=1821.0)
mark,and thanks kerry show the links.
-
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