Author Topic: Make Sheet Index using obectDBX  (Read 68835 times)

0 Members and 1 Guest are viewing this topic.

airportman

  • Newt
  • Posts: 37
  • i customize when required
Re: Make Sheet Index using obectDBX
« Reply #150 on: November 14, 2011, 11:19:58 AM »
I like ODBX ...TACOS !!
Perception is a state of mind  -/ Twitter = @hochanz -/ Intel i7 - 3.07GHz -/ 12GB Ram -/ Nvidia Quadro FX 1800

jaydee

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #151 on: November 14, 2011, 08:52:35 PM »
Quote
  function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006
  And kindly edited by Tim Willey to extract any number of attributes

  Modified by Lee Mac to process open drawings
  Modified by CAB forced Tags to match to Tags strings in all upper case
 
  Rewritten by Lee Mac 14.11.2011 to process a directory supplied as an argument.

Thankyou verymuch Lee
It works wonder, But i stumble across one minor issue that i would like to overcome.
which is the coversheet which have different block name to the normal border sheet title but still have attributes info.
Code: [Select]
(defun c:test (/ title ss)

 (setq Title  "*[AB][01234]*")
 (if (setq ss (ssget "_X" (list (cons 0 "insert") (cons 2 Title) (cons 66 1))))
  (progn
   (setq titlename (cdr (assoc 2 (entget (ssname ss 0)))))
   (getindex (getvar "dwgprefix") titlename)
   (write2csv)
  )
 )

My question is, instead of providing blockname as an argument to GetIndex function.
Is it possible for ODBX to determine the block name based on a existing "TAGname"
say if a unigue tag name is found ie. attr tag is "DRAWING_NUMBER", then get the the block name if it contain this tag?

Because the block name is a big variable, name varies from project to project and based on sheet size.

I throught it would more user friendly if the program could self determine the block name if a particular attribute tag name is found.. This also allow to produce the sheet index if a project contain multiple sheet names but with similar attribute definitions.

This link http://www.theswamp.org/index.php?topic=32633.msg381796#msg381796is also from yourself Lee is the closest to what i think might be able to assist to providing blockname.
Thankyou


« Last Edit: November 15, 2011, 06:51:23 AM by jaydee »

stevesfr

  • Newt
  • Posts: 54
Re: Make Sheet Index using obectDBX
« Reply #152 on: November 15, 2011, 08:27:04 AM »
Here is a completely rewritten version:

Supply it with the directory to process, block name and attribute tag list.

Code: [Select]
;|
  function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006
  And kindly edited by Tim Willey to extract any number of attributes

  Modified by Lee Mac to process open drawings
  Modified by CAB forced Tags to match to Tags strings in all upper case
 
  Rewritten by Lee Mac 14.11.2011 to process a directory supplied as an argument.
|;

(defun getindex ( directory blknme attlst / acapp acdocs dbx doc lst pair result tmp x )

    (setq attlst (mapcar '(lambda ( x ) (cons (strcase x) "")) attlst)
          blknme (strcase blknme)
    )
    (if
        (and
            (vl-file-directory-p
                (setq directory
                    (vl-string-right-trim "\\" (vl-string-translate "/" "\\" directory))
                )
            )
            (setq lst
                (mapcar
                    (function
                        (lambda ( x ) (strcat directory "\\" x))
                    )
                    (vl-directory-files directory "*.dwg" 1)
                )
            )
        )
        (progn
            (setq acapp (vlax-get-acad-object))
            (vlax-for doc (vla-get-documents acapp)
                (setq acdocs (cons (cons (strcase (vla-get-fullname doc)) doc) acdocs))
            )
            (setq dbx (LM:ObjectDBXDocument acapp))
            (foreach dwg lst
                (if
                    (and
                        (setq doc
                            (cond
                                (   (cdr (assoc (strcase dwg) acdocs)))
                                (   (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list dbx dwg)))) dbx)
                            )
                        )
                        (not
                            (vl-catch-all-error-p
                                (vl-catch-all-apply 'vla-item (list (vla-get-blocks doc) blknme))
                            )
                        )
                    )
                    (vlax-for layout (vla-get-layouts doc)
                        (if (not (eq "MODEL" (strcase (vla-get-name layout))))
                            (vlax-for obj (vla-get-block layout)
                                (if
                                    (and
                                        (eq "AcDbBlockReference" (vla-get-objectname obj))
                                        (eq blknme
                                            (if (vlax-property-available-p obj 'effectivename)
                                                (strcase (vla-get-effectivename obj))
                                                (strcase (vla-get-name obj))
                                            )
                                        )
                                        (eq :vlax-true (vla-get-hasattributes obj))
                                    )
                                    (progn
                                        (setq tmp attlst)
                                        (foreach att (vlax-invoke obj 'getattributes)
                                            (if (setq pair (assoc (strcase (vla-get-tagstring att)) tmp))
                                                (setq tmp  (subst (cons (car pair) (vla-get-textstring att)) pair tmp))
                                            )
                                        )
                                        (setq result (cons (cons (vl-filename-base dwg) tmp) result))
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (foreach obj (list doc dbx acapp)
                (if (and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj)))
                    (vlax-release-object obj)
                )
            )
        )
    )
    (reverse result)
)

(defun LM:ObjectDBXDocument ( acapp / acver )
    (vla-GetInterfaceObject acapp
        (if (< (setq acver (atoi (getvar "ACADVER"))) 16)
            "ObjectDBX.AxDbDocument"
            (strcat "ObjectDBX.AxDbDocument." (itoa acver))
        )
    )
)

Untested, so I hope I haven't missed anything...

LEE,
I enter the following at the command line:
(getindex ("c:\\b2\\" '("KEY-ITEM" "ITEM" "QUANTITY"))
where b2 is the dir of dwgs to be processed
KEY-ITEM is the block and ITEM and QUANTITY are the attributes
result.... nothing
what am I doing wrong at the command line?
tia, Steve
Can't remember what I'm supposed to forget.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #153 on: November 15, 2011, 08:31:37 AM »
LEE,
I enter the following at the command line:
(getindex ("c:\\b2\\" '("KEY-ITEM" "ITEM" "QUANTITY"))
where b2 is the dir of dwgs to be processed
KEY-ITEM is the block and ITEM and QUANTITY are the attributes
result.... nothing
what am I doing wrong at the command line?

Steve,

The result you receive should be an error since you are passing an unquoted list which will interpret "c:\\b2\\" as a function, and you have only passed the getindex function one argument, with a missing ")" from the end.

Try this instead:

Code: [Select]
(getindex "c:\\b2" "KEY-ITEM" '("ITEM" "QUANTITY"))
Lee

stevesfr

  • Newt
  • Posts: 54
Re: Make Sheet Index using obectDBX
« Reply #154 on: November 15, 2011, 01:26:50 PM »
There are so many variations of the program in this topic, its difficult which one yields the "sheet index".
can someone provide a "score card" of which entry is latest and greatest.  Too bad the phoney ones can't be deleted, as they are certainly confusing to me !
tia
Steve
Can't remember what I'm supposed to forget.

jaydee

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #155 on: November 16, 2011, 04:51:43 PM »
Hi.

Refer to my post Reply #151 above
How to odbx to get the Block Name with a given attribute tag name?
sort of step thru all insert/block in paper space layout, find the tagname "DRAWING_NUMBER" if found then extract the block name.

This code is from Lee http://www.theswamp.org/index.php?topic=38014.0
whick i would like doing via ObjectDbx
Code: [Select]
(defun GetBlocksWithTag ( / ss i e )
  (if (setq ss (ssget "_X" '((0 . "INSERT") (66 . 1))))
    (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i))))     
      (if
        (not
          (vl-some '(lambda ( a ) (eq "DRAWING_NUMBER" (vla-get-tagstring a)))
            (vlax-invoke (vlax-ename->vla-object e) 'getattributes)
          )
        )
        (ssdel e ss)
      )
    )
  )
  (setq blknme (cdr (assoc 2 (entget (ssname ss 0)))))
)

Thankyou
« Last Edit: November 16, 2011, 07:49:16 PM by jaydee »