TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Kerry on November 14, 2006, 12:20:28 AM

Title: Complaining about Loading the Dishwasher ??
Post by: Kerry 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
)
;;;-------------------------------------------------------------------
;;;







Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry 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))
    ;;
    ;;
)


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

Title: Re: Complaining about Loading the Dishwasher ??
Post by: Bryco 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)
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 14, 2006, 01:47:39 AM
Different problem Bryco ... but thanks for the post ..
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry 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, :-)
Title: Re: Complaining about Loading the Dishwasher ??
Post by: T.Willey 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.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry 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))
    ;;
    ;;
)

;;;-------------------------------------------------------------------
;;;
;;;
Title: Re: Complaining about Loading the Dishwasher ??
Post by: T.Willey on November 14, 2006, 07:43:54 PM
Glad to hear it Kerry.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R on November 15, 2006, 12:21:18 AM
Kerry, are you looking for a particular block name? <evil grin>
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R 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.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R on November 15, 2006, 01:01:18 AM
Kerry, there's actually an even better way to do this......................................................C#   :evil:  :-D
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry 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 ...
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry 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 ..
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry 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:
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R 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.


Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R on November 15, 2006, 05:56:51 AM
I might have confused the issue by just using a standard old lisp defun - was meant to demonstrate concept only.
Equally applicable to DBX. ESPECIALLY, if there is ever only 1 insert....why iterate over EVERY entity when you can go straight to the one you want? <rhetorical question> :)

Cheers,
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 06:20:31 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.
...................
Cheers,
Glenn.


Ahhh OK, hadn't considered that.
The block MAY be any one of 5 used for each job, in various named combinations, and may include the project Number in it's name.   May require reading config files to determine the full border name.
I s'pose I could get a list of the Blocks in the Collection, Pattern match the name, and go from there. 

Interesting idea, thanks.

.. though at this point it would be difficult getting a return on any further investment, just the satisfaction of improving it, and as a by product, possibly saving a couple of minutes each month.

We are a peculiar breed, hey ?


 
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R on November 15, 2006, 06:36:38 AM
I prefer to think of us as perfectionists/millisecondists (just invented a word I think) rather than peculiar per se :)

Cheers,
Glenn.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: CADaver on November 15, 2006, 07:38:49 AM
I prefer to think of us as perfectionists/millisecondists (just invented a word I think) rather than peculiar per se :)

Though peculiar none the less....
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Chuck Gabriel on November 15, 2006, 08:08:06 AM
Excellent trick Glenn.  Where did you learn that one?
Title: Re: Complaining about Loading the Dishwasher ??
Post by: T.Willey on November 15, 2006, 01:02:12 PM
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 ...

If you want I can share mine, C#.  I'm sure it's not that pretty as it was my first one.  It opens the drawings database for edit, finds the title blocks, and updates the revisions on the title block.  Let me know.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 04:36:21 PM
Post <share> away Tim ...

broadening the knowledgebase would be great. !
Title: Re: Complaining about Loading the Dishwasher ??
Post by: T.Willey on November 15, 2006, 04:58:19 PM
Post <share> away Tim ...

broadening the knowledgebase would be great. !

You asked for it  :wink:
Okay the code is too long to post in a reply, so I will attach it.  Hope that is okay.

Couldn't attach a 'cs' file, so I changed the extension to 'lsp' just change it back once dl'ed.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 05:06:12 PM
Great Tim, Thanks
Title: Re: Complaining about Loading the Dishwasher ??
Post by: T.Willey on November 15, 2006, 05:16:24 PM
Great Tim, Thanks
You're welcome.  If my logic seems flawed, please point it out as I'm just learning.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 05:20:06 PM
I'm working from home today, so I'll try to have a look during what would have been "travelling time" tonight ..
Title: Re: Complaining about Loading the Dishwasher ??
Post by: T.Willey on November 15, 2006, 05:23:36 PM
I'm working from home today, so I'll try to have a look during what would have been "travelling time" tonight ..
If you working from home, enjoy it (I'm jealous).  Don't worry about my stuff, have fun.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 07:07:37 PM
Heh, Glenn .. Good stuff .. very insightful !

Grabs the data OK .. Just need to test the speed, including writing .. later ..
Quote
Command:
Command: TEST1116B
((   ("DWG_NO_C" . "A016-C36")
     ("FOR_CON" . "FOR CONSTRUCTION")
     ("REV_BOX" . "1")
     ("TITLE-1" . "ROM DUMP POCKET - DUMP HOPPER")
     ("TITLE-2" . "STRUCTURAL STEELWORK DETAILS")
     ("TITLE-3" . "WALL FRAME W3 & W6 - COMMON PLATE - ITEM DETAILS")
     ("DRAWN" . "RMK")
     ("DRAWN_DATE" . "APR 06")
 .............. etc

Code: [Select]
;;; DBXTest1116-01.LSP
;;; kwb 20061116
;;; Testing Glenn's theory ... get the inserted block instance from the BlockTable
;;; will only work as expected when there is ONE instance of the Block.
;;;-------------------------------------------------------------------
;;;
(DEFUN c:Test1116b ( / BorderName DocName IAxDbDocument DataList )
    (SETQ BorderName    "BORDER*"
          DocName       (DOS_GETFILED "Select file"
                                      "J:\\DWGS"
                                      "Drawing files (*.dwg)|*.dwg|All files (*.*)|*.*||"
                        )
          IAxDbDocument (kdub:DBX:GetInterface)
    )
    ;; -----------------
    ;;   
    (IF (VL-CATCH-ALL-ERROR-P
            (VL-CATCH-ALL-APPLY 'VLA-OPEN (LIST IAxDbDocument DocName))
        )
        (SETQ IAxDbDocument nil)
    )
    (IF IAxDbDocument
        (SETQ DataList
                 (kdub:BDX:ReadAttributes-03 BorderName IAxDbDocument)
        )
    )
    (VLAX-RELEASE-OBJECT IAxDbDocument)
    DataList
)
;;;-------------------------------------------------------------------
;;;
(DEFUN kdub:BDX:ReadAttributes-03 ( BorderBlockName   IAxDbDocument
                                   /                 dbx-borderObject
                                   edata             BorderReference
                                   AttLst
                                  )
    ;;
    ;; Find the Block in the Block Table   
    ;;
    (VLAX-FOR blockDefinition (VLA-GET-BLOCKS IAxDbDocument)
        (IF (WCMATCH (STRCASE (VLA-GET-NAME blockDefinition)) BorderBlockName)
            (SETQ dbx-borderObject blockDefinition)
        )
    )
    ;;
    ;; If the AcDbBlockTableRecord is there, Grab the Ename and run with it ....
    ;;
    (IF dbx-borderObject
        (PROGN (FOREACH edata (ENTGET (VLAX-VLA-OBJECT->ENAME dbx-borderObject))
                   (IF (= (CAR edata) 331)
                       (SETQ BorderReference (CDR edata))
                   )
               )
               ;;
               ;; Extract the Attributes ..
               ;;
               (IF BorderReference
                   (SETQ AttLst
                            (CONS (MAPCAR
                                      '(LAMBDA (Att)
                                           (CONS (VLA-GET-TAGSTRING Att)
                                                 (VLA-GET-TEXTSTRING Att)
                                           )
                                       )
                                      (VLAX-INVOKE
                                          (VLAX-ENAME->VLA-OBJECT BorderReference)
                                          'GetAttributes
                                      )
                                  )
                                  AttLst
                            )
                   )
               )
        )
    )
    AttLst
)
;;;-------------------------------------------------------------------
;;;
 
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 07:48:17 PM
Prior to Clean-up and optimisation ...
My Machine at home has essentially identical spec's  to my box at work, but I've run both tests here ...

... the joys of using a removable drive for development source .. :-)

The Test1115D is the last one posted Yesterday
The Test1116C is the included here.
Quote
Command:
Command: test1115d
 132 Files completed in 6.1910 seconds.
Command:
Command: TEST1116C
 132 Files completed in 7.2500 seconds.
Command:

The previous is marginally faster.
I'm guessing ... perhaps using the database itteration and scarpering when the block is found works because the Border is usually inserted early in the drawing process, so IT MAY be close to the start of the database ... that could be tested I s'pose ..
Code: [Select]
;;;-------------------------------------------------------------------
;;;
(DEFUN c:Test1116c
       (/ BorderName FileList Path start finish IAxDbDocument dbxDoc)
    (SETQ BorderName "BORDER*"
          FileList   (DOS_GETFILEM
                         "Select files"
                         "J:\\DWGS"
                         "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:DBX:GetInterface))
    ;; -----------------
    ;;
    (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:BDX:ReadandSaveAttributes-04 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:BDX:ReadandSaveAttributes-04 (dwgFileName BorderBlockName   IAxDbDocument
                                   /                 dbx-borderObject
                                   edata             BorderReference
                                   AttLst
                                  )
    ;;
    ;; Find the Block in the Block Table   
    ;;
    (VLAX-FOR blockDefinition (VLA-GET-BLOCKS IAxDbDocument)
        (IF (WCMATCH (STRCASE (VLA-GET-NAME blockDefinition)) BorderBlockName)
            (SETQ dbx-borderObject blockDefinition)
        )
    )
    ;;
    ;; If the AcDbBlockTableRecord is there, Grab the Ename and run with it ....
    ;;
    (IF dbx-borderObject
        (PROGN (FOREACH edata (ENTGET (VLAX-VLA-OBJECT->ENAME dbx-borderObject))
                   (IF (= (CAR edata) 331)
                       (SETQ BorderReference (CDR edata))
                   )
               )
               ;;
               ;; Extract the Attributes ..
               ;;
               (IF BorderReference
                   (SETQ AttLst
                            (CONS (MAPCAR
                                      '(LAMBDA (Att)
                                           (CONS (VLA-GET-TAGSTRING Att)
                                                 (VLA-GET-TEXTSTRING Att)
                                           )
                                       )
                                      (VLAX-INVOKE
                                          (VLAX-ENAME->VLA-OBJECT BorderReference)
                                          '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))
    ;;
    ;;
)
;;;-------------------------------------------------------------------
;;;
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R on November 15, 2006, 08:54:53 PM
Interesting - just something to keep in mind for future endeavours.
I suspect my approach would get significantly faster the larger the drawing got and the more inserts of the same block...however that's just a suspicion.

Good stuff Kerry.

Cheers,
Glenn.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Glenn R on November 15, 2006, 09:02:01 PM
Chuck, to be honest I can't remember whether I saw it somewhere or I stumbled on it years ago...might be the adesk ng...dunno.
Makes you wonder what else you can get to in the drawing dbase by converting an activex pointer to a lisp ename.

It works because tblobjname return a 0 . "BLOCK" which is BLOCK_BEGIN, whereas a com pointer to a block is actually positioned on the "BLOCK_RECORD" object/dxf code, which is of course where the blockreferenceids live.

All a bit of a moot point for me as i hardly ever write lisp anymore, but I thought it was a pertinent tidbit to share in the current thread context.

Cheers,
Glenn.
Title: Re: Complaining about Loading the Dishwasher ??
Post by: Kerry on November 15, 2006, 09:05:12 PM
Interesting - just something to keep in mind for future endeavours.
I suspect my approach would get significantly faster the larger the drawing got and the more inserts of the same block...however that's just a suspicion.

Good stuff Kerry.

Cheers,
Glenn.

I'm sure your supposition is correct Glenn. I have a couple of projects planned with similar functionality, which may benefit from that approach..

Thanks heaps, again :-)