Author Topic: Complaining about Loading the Dishwasher ??  (Read 14836 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Complaining about Loading the Dishwasher ??
« on: November 14, 2006, 12:20:28 AM »

I may be 'Complaining about Loading the Dishwasher'

I'm extracting attributes from drawing borders with DBX , ie accessing the drawing dataBase directly without opening the drawing.

Each drawing has a border with 65 attributes which are extracted and <for testing> written to a text file with the same base name as the drawing.

The test I've used is 132 drawings totalling about 19MB and writing about 950 text characters to each text file < total of 129 KB>

This is the current result ; about 0.130 seconds each  :

Quote
Command: test
 132 Files completed in 17.0940 seconds.
Command:

I was looking at the  (VLAX-FOR Obj (VLA-GET-MODELSPACE dbx-iacaddocument) ...
which steps through each modelspace object, even after the target block is found.
The quandry is "is there an easier, faster way to do this" ?
Seems to me I could count the database items,
step through the database using 'item' to query the object, increment the counter,
repeat, repeat, then skip-out when the block is found ..

I'll probably test that tomorrow, but in the mean-time, does anyone have any other ideas, or see any bottlenecks I've missed ..
...
Code: [Select]
;; DBX_Testing.LSP
;; kwb 20061114
;;;-------------------------------------------------------------------
;;;

(DEFUN c:test (/ BorderName FileList Path start finish)
    (SETQ BorderName "BORDER*"
          FileList   (DOS_GETFILEM
                         "Select files"
                         (GETVAR "dwgprefix")
                         "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||"
                     )
    )
    (SETQ Path     (CAR FileList)
          FileList (CDR FileList)
    )
    (SETQ start (GETVAR "millisecs"))
    (FOREACH docname FileList
        (kdub:getBDXAttributes (STRCAT Path docname) BorderName)
    )
    (SETQ finish (GETVAR "millisecs"))
    (PROMPT (STRCAT "\n "
                    (ITOA (LENGTH FileList))
                    " Files completed in "
                    (RTOS (/ (- finish start) 1000.0) 2 4)
                    " seconds."
            )
    )
    (PRINC)
)
;;;-------------------------------------------------------------------
;;;

(DEFUN kdub:getBDXAttributes
       (dwgFileName BlockName / att attlst dbx-iacaddocument fdesc_id)
    (SETQ AttLst nil)
    ;; Assume the file is not in the current Document Collection
    (SETQ dbx-iacaddocument (KDUB:OPENDBXDOCUMENT dwgFileName))
    ;;
    (VLAX-FOR Obj (VLA-GET-MODELSPACE dbx-iacaddocument)
        (IF (AND (= (VLA-GET-OBJECTNAME Obj) "AcDbBlockReference")
                 ;;  (VLA-GET-HASATTRIBUTES Obj) ;; qualifies by definition
                 (WCMATCH (STRCASE (VLA-GET-NAME Obj)) BlockName)
            )
            (SETQ AttLst (CONS (MAPCAR '(LAMBDA (Att)
                                            (CONS (VLA-GET-TAGSTRING Att)
                                                  (VLA-GET-TEXTSTRING Att)
                                            )
                                        )
                                       (VLAX-INVOKE Obj 'GetAttributes)
                               )
                               AttLst
                         )
            )
        )
    )
    (OR AttLst (SETQ AttLst '(" ")))
    ;;
    ;; Release the DBX database
    (VLAX-RELEASE-OBJECT dbx-iacaddocument)
    ;;
    ;; Write data to file.
    (SETQ fdesc_id (OPEN (STRCAT dwgFileName ".txt") "W"))
    (WRITE-LINE (VL-PRINC-TO-STRING (CAR AttLst)) fdesc_id)
    (SETQ fdesc_id (CLOSE fdesc_id))
    ;;
    ;;
)

;;;-------------------------------------------------------------------
;;;
;;; Open a dbx Document
;;;

(DEFUN kdub:OpenDbxDocument (DbxdwgName      /
                             acadver         DBXserver
                             dbxopenCatchit  dbxDoc
                             IAcadApplication
                             IAcadDocument
                            )
    (SETQ DbxdwgName       (STRCASE DbxdwgName)
          acadver          (ATOI (GETVAR "acadver"))
          IAcadApplication (VLAX-GET-ACAD-OBJECT)
          IAcadDocument    (VLA-GET-ACTIVEDOCUMENT IAcadApplication)
    )
    (COND ((= DbxdwgName (STRCASE (VLA-GET-FULLNAME IAcadDocument)))
           (PROMPT (STRCAT "\nUnable to interface to ActiveDocument "
                           DbxdwgName
                           " as DBX Drawing."
                   )
           )
          )
          ((SETQ
               dbxDoc (IF (< acadver 16)
                          (VLA-GETINTERFACEOBJECT IAcadApplication
                                                  "ObjectDBX.AxDbDocument"
                          )
                          (VLA-GETINTERFACEOBJECT
                              IAcadApplication
                              (STRCAT "ObjectDBX.AxDbDocument." (ITOA acadver))
                          )
                      )
           )
           (IF (VL-CATCH-ALL-ERROR-P
                   (VL-CATCH-ALL-APPLY 'VLA-OPEN (LIST dbxDoc DbxdwgName))
               )
               (SETQ dbxDoc nil)
           )
          )
    )
    (IF (NOT dbxDoc)
        (PROMPT (STRCAT "\nUnable to determine interface to DBX Drawing "
                        DbxdwgName
                )
        )
    )
    dbxDoc
)
;;;-------------------------------------------------------------------
;;;







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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #1 on: November 14, 2006, 01:06:09 AM »
Thought so ... knocked 40% off the time ....
Down to 0.076 seconds each drawing ..  which is pretty fast .. :-)


Quote
Command: test2
 132 Files completed in 10.0780 seconds.
Command:

Code: [Select]
;; DBX_Testing.LSP
;; kwb 20061114
;;;-------------------------------------------------------------------
;;;

(DEFUN c:test2 (/ BorderName FileList Path start finish)
    (SETQ BorderName "BORDER*"
          FileList   (DOS_GETFILEM
                         "Select files"
                         (GETVAR "dwgprefix")
                         "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||"
                     )
    )
    (SETQ Path     (CAR FileList)
          FileList (CDR FileList)
    )
    (SETQ start (GETVAR "millisecs"))
    (FOREACH docname FileList
        (kdub:getBDXAttributes2 (STRCAT Path docname) BorderName)
    )
    (SETQ finish (GETVAR "millisecs"))
    (PROMPT (STRCAT "\n "
                    (ITOA (LENGTH FileList))
                    " Files completed in "
                    (RTOS (/ (- finish start) 1000.0) 2 4)
                    " seconds."
            )
    )
    (PRINC)
)
;;;-------------------------------------------------------------------
;;;

;;;-------------------------------------------------------------------
;;;
(DEFUN kdub:getBDXAttributes2
       (dwgFileName BlockName / att attlst dbx-iacaddocument dbx-modelspace Count index Obj fdesc_id)
    (SETQ AttLst nil)
    ;; Assume the file is not in the current Document Collection
    (SETQ dbx-iacaddocument (KDUB:OPENDBXDOCUMENT dwgFileName)
          dbx-modelspace    (VLA-GET-MODELSPACE dbx-iacaddocument)
          Count             (VLA-GET-COUNT dbx-modelspace)
          index             0
    )
    ;;
    (WHILE (< index count)
        (SETQ Obj   (VLA-ITEM dbx-modelspace index)
              index (1+ index)
        )
        (IF (AND (= (VLA-GET-OBJECTNAME Obj) "AcDbBlockReference")
                 (WCMATCH (STRCASE (VLA-GET-NAME Obj)) BlockName)
            )
            (SETQ index  count
                  AttLst (CONS (MAPCAR '(LAMBDA (Att)
                                            (CONS (VLA-GET-TAGSTRING Att)
                                                  (VLA-GET-TEXTSTRING Att)
                                            )
                                        )
                                       (VLAX-INVOKE Obj 'GetAttributes)
                               )
                               AttLst
                         )
            )
        )
    )
    (OR AttLst (SETQ AttLst '(" ")))
    ;;
    ;; Release the DBX database
    (VLAX-RELEASE-OBJECT dbx-iacaddocument)
    ;;
    ;; Write data to file.
    (SETQ fdesc_id (OPEN (STRCAT dwgFileName ".txt") "W"))
    (WRITE-LINE (VL-PRINC-TO-STRING (CAR AttLst)) fdesc_id)
    (SETQ fdesc_id (CLOSE fdesc_id))
    ;;
    ;;
)


;;;-------------------------------------------------------------------
;;;
;;;

« Last Edit: November 14, 2006, 01:08:02 AM by Kerry Brown »
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.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Complaining about Loading the Dishwasher ??
« Reply #2 on: November 14, 2006, 01:42:29 AM »
Seems like Tony found a way as well  http://tinyurl.com/2w59s (Ps, I  can't read the stuff I was just looking for a better way to load the dishwasher)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #3 on: November 14, 2006, 01:47:39 AM »
Different problem Bryco ... but thanks for the post ..
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #4 on: November 14, 2006, 01:49:08 AM »
not that this is really a problem, just a fine tuning thing I think ...

... though if someone can seriously reduce the time I'd be really interested, :-)
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Complaining about Loading the Dishwasher ??
« Reply #5 on: November 14, 2006, 02:04:31 AM »
One way that I have do it, is to use 'vl-catch-all-apply' with the 'vlax-for' and then once you find the title block, and extracte the attributes throw an error with 'exit'.

You could also only use one dbx app (drawing) to open all the drawings, and then just 'release' it and 'nil' it when done with all the drawings.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #6 on: November 14, 2006, 07:06:46 PM »
Hi Tim,
The 'exit' trap would work, but I try not to use that sort of design factory.

You're correct about initialising the dbx interface only once ... that does make a difference 

I incorporated that and did some further clean-up ... it's smoking now
; down to 0.0463 secs for each drawing

Quote
Command: test
 132 Files completed in 6.1090 seconds.
Command:
Code: [Select]
;; DBX_Testing.LSP
;; kwb 20061114
;;;-------------------------------------------------------------------
;;;

(DEFUN c:test (/ BorderName FileList Path start finish IAxDbDocument dbxDoc)
    (SETQ BorderName "BORDER*"
          FileList   (DOS_GETFILEM
                         "Select files"
                         (GETVAR "dwgprefix")
                         "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||"
                     )
    )
    (SETQ Path     (CAR FileList)
          FileList (MAPCAR '(LAMBDA (x) (STRCAT Path x)) (CDR FileList))
    )
    (SETQ start (GETVAR "millisecs"))
    ;;
    (SETQ IAxDbDocument (kdub:GetDBXInterface))
    ;; -----------------
    ;;
    (FOREACH docname FileList
        (SETQ dbxDoc IAxDbDocument)
        (IF (VL-CATCH-ALL-ERROR-P
                (VL-CATCH-ALL-APPLY 'VLA-OPEN (LIST dbxDoc docname))
            )
            (SETQ dbxDoc nil)
        )
        (IF dbxDoc
            (kdub:getBDXAttributes docname BorderName dbxDoc)
        )
    )
    (VLAX-RELEASE-OBJECT IAxDbDocument)
    ;; -----------------
    ;;
    (SETQ finish (GETVAR "millisecs"))
    (PROMPT (STRCAT "\n "
                    (ITOA (LENGTH FileList))
                    " Files completed in "
                    (RTOS (/ (- finish start) 1000.0) 2 4)
                    " seconds."
            )
    )
    (PRINC)
)

;;;-------------------------------------------------------------------
;;;
(DEFUN kdub:GetDBXInterface (/ AcadVer IAcadApplication IAxDbDocument)
    (SETQ AcadVer          (ATOI (GETVAR "acadver"))
          IAcadApplication (VLAX-GET-ACAD-OBJECT)
          IAxDbDocument (IF (< AcadVer 16)
                               (VLA-GETINTERFACEOBJECT IAcadApplication
                                                       "ObjectDBX.AxDbDocument"
                               )
                               (VLA-GETINTERFACEOBJECT
                                   IAcadApplication
                                   (STRCAT "ObjectDBX.AxDbDocument." (ITOA AcadVer))
                               )
                           )
    )
)

;;;-------------------------------------------------------------------
;;;
(DEFUN kdub:getBDXAttributes (dwgFileName    BlockName
                              dbx-iacaddocument
                              /              att
                              attlst         dbx-iacaddocument
                              dbx-modelspace Count
                              index          Obj
                              fdesc_id
                             )
    ;;
    (SETQ dbx-modelspace (VLA-GET-MODELSPACE dbx-iacaddocument)
          Count          (VLA-GET-COUNT dbx-modelspace)
          index          0
    )
    ;;
    (WHILE (< index count)
        (SETQ Obj   (VLA-ITEM dbx-modelspace index)
              index (1+ index)
        )
        (IF (AND (= (VLA-GET-OBJECTNAME Obj) "AcDbBlockReference")
                 (WCMATCH (STRCASE (VLA-GET-NAME Obj)) BlockName)
            )
            (SETQ index  count
                  AttLst (CONS (MAPCAR '(LAMBDA (Att)
                                            (CONS (VLA-GET-TAGSTRING Att)
                                                  (VLA-GET-TEXTSTRING Att)
                                            )
                                        )
                                       (VLAX-INVOKE Obj 'GetAttributes)
                               )
                               AttLst
                         )
            )
        )
    )
    (OR AttLst (SETQ AttLst '(" ")))
    ;;
    ;;
    ;; Write data to file.
    (SETQ fdesc_id (OPEN (STRCAT dwgFileName ".txt") "W"))
    (WRITE-LINE (VL-PRINC-TO-STRING (CAR AttLst)) fdesc_id)
    (SETQ fdesc_id (CLOSE fdesc_id))
    ;;
    ;;
)

;;;-------------------------------------------------------------------
;;;
;;;
« Last Edit: November 14, 2006, 07:09:11 PM by Kerry Brown »
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Complaining about Loading the Dishwasher ??
« Reply #7 on: November 14, 2006, 07:43:54 PM »
Glad to hear it Kerry.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Complaining about Loading the Dishwasher ??
« Reply #8 on: November 15, 2006, 12:21:18 AM »
Kerry, are you looking for a particular block name? <evil grin>

Glenn R

  • Guest
Re: Complaining about Loading the Dishwasher ??
« Reply #9 on: November 15, 2006, 12:47:02 AM »
Please excuse my crappy lisp as I haven't done anything serious in it for a few years - C++ and C# keeps my attention nowadays.

You can use the BlockReferenceIds stored on each block table record - the trick is getting to them in normal lisp - which you can't.
Unless, you use ActiveX to get the BTR, THEN convert it to an ename and do your mojo with that.

Anyway, run this around the yard a few times - it will give you the idea:

Code: [Select]
defun C:Test (/ pAcad pDoc pBlkTbl pBtr)
  ; Get apointer to the application itself...
  (setq pAcad (vlax-get-acad-object))
  ; Now get a pointer to the active document...
  (setq pDoc (vla-get-ActiveDocument pAcad))
  ; Now open up the block table...
  (setq pBlkTbl (vla-get-Blocks pDoc))
  ; Get our 'block table record'...
  (setq pBtr (vla-Item pBlkTbl "Test"))

  (setq pBtrEname (vlax-vla-object->ename pBtr))

  (setq pBtrElist (entget pBtrEname))
  (print pBtrElist)

  ; Get the 331 codes BLKREFS - this will give us the inserts of this block table record...
  (setq pBlkRef nil)

  (foreach x pBtrElist
    (if (= (car x) 331)
      (progn
(setq pBlkRef (cdr x))
(print (entget pBlkRef))
      );progn
    )
  );foreach


  ; Clean up
  (setq pBlkTBl nil
pDoc nil
pAcad nil
  )
);defun

Cheers,
Glenn.

Glenn R

  • Guest
Re: Complaining about Loading the Dishwasher ??
« Reply #10 on: November 15, 2006, 01:01:18 AM »
Kerry, there's actually an even better way to do this......................................................C#   :evil:  :-D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #11 on: November 15, 2006, 02:37:30 AM »
Kerry, are you looking for a particular block name? <evil grin>

Yes, and I know there is only, and always, one instance ..
Code: [Select]
(SETQ BorderName "BORDER*"  
In this case it's always prefixed with BORDER ...
But identifying the Block is not too hard < in a controlled environment, at least >





Kerry, there's actually an even better way to do this......................................................C#   :evil:  :-D

I know, Already started ... :-)

 ... also easier to use SQL/ADO from C# than from VLisp.  ;-) 


I'm pleasantly surprised by how fast the VLisp is with DBX ...  better than 1000 drawings per minute is pretty slick including writing the data to file ...
« Last Edit: November 15, 2006, 02:44:35 AM by Kerry Brown »
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #12 on: November 15, 2006, 02:40:34 AM »
............
Anyway, run this around the yard a few times - it will give you the idea:

Code: [Select]
defun C:Test (/ pAcad pDoc pBlkTbl pBtr)
 ;;..........
);defun

Cheers,
Glenn.

I'm using DBX Glenn, so this wont help .. unless I misunderstand your intent ..
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Complaining about Loading the Dishwasher ??
« Reply #13 on: November 15, 2006, 02:47:27 AM »
......  as I haven't done anything serious in it <lisp >  for a few years - C++ and C# keeps my attention nowadays.
Cheers,
Glenn.

I'm looking forward to saying that too ... though I DO enjoy VLisp ... [personal problem, I know]    :lol:
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.

Glenn R

  • Guest
Re: Complaining about Loading the Dishwasher ??
« Reply #14 on: November 15, 2006, 05:54:10 AM »
I think you might misunderstand me Kerry. The basic premise behind what I posted is this:

1. Go STRAIGHT to the Block Table Record in question by using item on the block table - no need to loop over every entity in every layout.
2. Convert said ActiveX pointer to lisp ename.
3. Get the inserts of this block table table record from 2. above.
4. Go STRAIGHT to each insert of said block and do your mojo.
5. Will work just as well in DBX.

Cheers,
Glenn.