Author Topic: Using ObjectDBX to Obtain Attribute Values  (Read 1765 times)

0 Members and 1 Guest are viewing this topic.

HD

  • Guest
Using ObjectDBX to Obtain Attribute Values
« 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!
« Last Edit: December 01, 2005, 08:43:20 AM by HD »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.


mkweaver

  • Bull Frog
  • Posts: 352
Re: Using ObjectDBX to Obtain Attribute Values
« Reply #3 on: August 18, 2008, 08:54:40 AM »
Nick,
For item #1:
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  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:

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  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:
Code: [Select]
(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:
Code: [Select]
(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