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

0 Members and 1 Guest are viewing this topic.

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #90 on: March 30, 2006, 02:11:54 PM »
Hi guys, first post here. Never even seen this place before. I got linked to this thread from discussion forums on autodesk.
From what I see and understand (little) this seems like a very well written and powerful routine. Right now I have a number of processes that happen to do the same thing. It's quiet messy, but automated. I use -attext to get the attributes, and i use a batch software to run through the drawings, then combine the .txt files and get one that gets imported to excel and vba takes care of the rest.
I was looking to do this process with obd, but i know very little about vla stuff and activex stuff.

The original code here, makes some what sense to me, but I would apprecieate it greatly if someone would list some more descriptions of what does what. Aspecially the area where you are going through the drawings and checking for blocks etc.
I thank u all greatly, and very jealous of all of u being so knowledgable in this programming language...

Thanks in advance.
Viktor.

GDF

  • Water Moccasin
  • Posts: 1990
Re: Make Sheet Index using obectDBX
« Reply #91 on: March 30, 2006, 02:44:47 PM »
Hi Viktor

Welcome to the swamp. This is by far the best way ahead of the rest forum.
Quote
I thank u all greatly, and very jealous of all of u being so knowledgable in this programming language...
I am learning to, I got alot of help on this one...maybe someone can chime in on the details.


This particular original routine use AutoCAD's objectdbx to create a text file listing the sheet files within the selected directory.
It gets the value of an attributed block located in each sheet file that has the following data:
sheet number
sheet title
sheet date
...and it searches for any revision/addedum attributed blocks for the date to update

For example, here is a current job <SheetIdex.txt file>
Code: [Select]
22 July 2005  [2]  A0.00     Cover                         
22 July 2005  [ ]  A0.01     Site Plan                     
22 July 2005  [2]  A1.01     Project Data                 
22 July 2005  [ ]  A1.02     Fire Proofing Data           
22 July 2005  [ ]  A1.03     Fair Housing Data             
22 July 2005  [ ]  A1.04     ADA Handicap Data             
22 July 2005  [ ]  A1.05     TAS Handicap Data             
22 July 2005  [ ]  A2.01a    Foundation Plan               
22 July 2005  [ ]  A2.01b    Floor Plan                   
22 July 2005  [ ]  A2.01c    Floor Plan                   
22 July 2005  [ ]  A2.01d    Floor Plan                   
22 July 2005  [ ]  A2.01e    Roof Plan                     
22 July 2005  [ ]  A2.02a    Foundation Plan               
22 July 2005  [ ]  A2.02b    Floor Plan                   
22 July 2005  [ ]  A2.02c    Floor Plan                   
22 July 2005  [ ]  A2.02d    Floor Plan                   
22 July 2005  [ ]  A2.02e    Roof Plan                     
22 July 2005  [ ]  A2.03a    Foundation Plan               
22 July 2005  [ ]  A2.03b    Floor Plan                   
22 July 2005  [ ]  A2.03c    Floor Plan                   
22 July 2005  [ ]  A2.03d    Floor Plan                   
22 July 2005  [ ]  A2.03e    Roof Plan                     
22 July 2005  [ ]  A3.00     Schedules                     
22 July 2005  [ ]  A3.01     Unit Plan                     
22 July 2005  [ ]  A3.02a    Unit Plan                     
22 July 2005  [ ]  A3.02b    Unit Plan                     
22 July 2005  [ ]  A3.02c    Unit Plan                     
22 July 2005  [ ]  A3.03a    Unit Plan                     
22 July 2005  [ ]  A3.03b    Unit Plan                     
22 July 2005  [ ]  A3.03c    Unit Plan                     
22 July 2005  [ ]  A3.03d    Unit Plan                     
22 July 2005  [ ]  A3.03e    Unit Plan                     
22 July 2005  [ ]  A3.04     Unit Plan                     
22 July 2005  [ ]  A3.05a    Unit Plan                     
22 July 2005  [ ]  A3.05b    Unit Plan                     
22 July 2005  [ ]  A3.05c    Unit Plan                     
22 July 2005  [2]  A4.01     Building Elevations           
22 July 2005  [2]  A4.02     Building Elevations           
22 July 2005  [2]  A4.03     Building Elevations           
22 July 2005  [2]  A5.01     Wall Sections                 
22 July 2005  [2]  A5.02     Wall Sections                 
22 July 2005  [2]  A5.03     Wall Sections                 
22 July 2005  [2]  A5.04     Wall Sections                 
22 July 2005  [2]  A5.05     Wall Sections                 
22 July 2005  [2]  A6.01     Stairs                       
22 July 2005  [ ]  A6.02     Stairs                       
02 Feb 2006   [3]  A6.03     Stairs                       
02 Feb 2006   [3]  A6.04     Stairs                       
22 July 2005  [2]  A7.01     Details                       
22 July 2005  [2]  A7.02     Details                       
22 July 2005  [2]  A7.03     Details                       
22 July 2005  [2]  A7.04     Details                       
22 July 2005  [2]  A7.05     Details                       
22 July 2005  [ ]  A7.06     Details                       
22 July 2005  [ ]  A7.07     Details                       
22 July 2005  [ ]  A8.00     Schedules                     
22 July 2005  [ ]  A8.01     Foundation Plan               
22 July 2005  [ ]  A8.02     Leasing Office Plan           
22 July 2005  [ ]  A8.03     Ceiling Plan                 
22 July 2005  [ ]  A8.04     Roof Plan                     
22 July 2005  [ ]  A8.05     Elevations                   
22 July 2005  [ ]  A8.06     Elevations                   
22 July 2005  [ ]  A8.07     Elevations                   
22 July 2005  [ ]  A8.08     Wall Sections                 
22 July 2005  [ ]  A9.01     Mail Kiosk                   
22 July 2005  [ ]  A9.02     Garage / Maint. Bldg.         
22 July 2005  [ ]  A9.03     Garage                       
22 July 2005  [ ]  A9.04     Garage                       
22 July 2005  [ ]  A9.05     Sign and Cabana               

Gary
« Last Edit: March 30, 2006, 02:50:27 PM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #92 on: March 30, 2006, 03:03:26 PM »
Thanks Gary, i have no doubt that it's he best forum :) I've been looking around for a few days and my brain hurts lol.

Well, your description makes sense, and that's what I ment by ObjectDBX, i just haven't dealt with it enough to memorize that it's not obd (obdII sensors from the cars that I gets me confused), but ObjectDBX.

The list you posted is also similar to what I get, i do the same operation, but like I said, in a very messy way. I rely on a batch program to shuffle through the drawings, then I use a windows cmd to combine all txt files into one file and open it in excel and go from there.

I guess my question is more for that code in particular. If you have a minute to answer these basic questions, this will be allot more clear for me.


Code: [Select]
(defun C:CSI (/ indexlist file)
  (getfolder)
  (ARCH:CreateIndex2436TBA)
  (if (= indexlist nil)(ARCH:CreateIndex2436TAG))
  (setq file (open "C:\\Temp\\SheetIndex.txt" "w"))
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (write-line (strcat (car a) "\t" (cdr a)) file)
  )
  (close file)
  (command ".shell" "notepad C:\\Temp\\SheetIndex.txt")
)
(princ)

Code above you first call the "getfolder", which is pretty straight forward (although for some reason when I run it the "folderlist" comes back as nill, that is when i break right at the end of that function.

Then you call "getindex" through the ARCH:*** which is basically sorting of the document that you get.
Am I somewhere ok so far?

Now, this GETINDEX just does not make much sense to me on how it works.
Could you give me a brief description before I make a fool out of myself? Step by step would be asking for too much, but if it won't take long, THANK YOU!
But thanks in either way!

Viktor.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Make Sheet Index using obectDBX
« Reply #93 on: March 30, 2006, 03:25:31 PM »
Viktor,

 Welcome to the swamp.

If you know VBA more than LISP, then you might want to code it in VBA.  VBA also has the ability to use ObjectDBX, but I don't know any VBA, but I can't help on the LISP side.

Let us know which way you want to go.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 1990
Re: Make Sheet Index using obectDBX
« Reply #94 on: March 30, 2006, 03:31:35 PM »
Code above you first call the "getfolder", which is pretty straight forward (although for some reason when I run it the "folderlist" comes back as nill, that is when i break right at the end of that function.

The folder selected has to contain your "sheet file" drawing and not in a sub folder, otherwise it will return nil.

As far as the voodoo vla- stuff, it's over my head.
The getindex part is from Jeff Mishler, Tim Willey and Allen Butler. Without help from Allen I would be sinking to the bottom of the swamp.
I better let them explain it. I'm the kind of lisper that just wants to put the key in and go....and try to learn something along the way.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #95 on: March 30, 2006, 03:38:27 PM »
Yea Gary, u and me are on the same page, its just you are more further along the page...
This is the way i learn too, but back to the folder list. I do have drawing files in there. Does it only build a list if the drawings contain a certain block? I figured it only lists all the files in that folder. That's what I had. but still returned nill.

About VBA, i'm very new to cad side of the vba, i can get around but no way efficient at it. excel side is a bit easier, since there recording is allowed which taught me pretty quickly. Anyone know if AutoCad will soon have a record feature for macro's?

Thanks,
Viktor.

GDF

  • Water Moccasin
  • Posts: 1990
Re: Make Sheet Index using obectDBX
« Reply #96 on: March 30, 2006, 03:44:20 PM »
Yea Gary, u and me are on the same page, its just you are more further along the page...
This is the way i learn too, but back to the folder list. I do have drawing files in there. Does it only build a list if the drawings contain a certain block? I figured it only lists all the files in that folder. That's what I had. but still returned nill.

About VBA, i'm very new to cad side of the vba, i can get around but no way efficient at it. excel side is a bit easier, since there recording is allowed which taught me pretty quickly. Anyone know if AutoCad will soon have a record feature for macro's?

Thanks,
Viktor.


Yes it has to contain the attributed blocks....like the block inclosed.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2019x64 Windows 10x64

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
Re: Make Sheet Index using obectDBX
« Reply #97 on: March 30, 2006, 04:02:20 PM »
Hi Viktor, I'm glad you found your way over here. People have been asking about macro recording for some time and I have yet to hear anyone from Adesk comment about it.

As for the (getindex), I don't know which one you tried (there are a number of incremental versions here and I didn't check to see what, if anything, changed in that portion of the code) but if you look at the first one I posted in Reply#5 I'll try to walk you through it....
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 Modified for training purposes, 3/30/06 JMM|;
(defun getindex (blkname  attname1 attname2 /      *acad    atts
dwgs   f    folder   layouts  masterlist
name   odbx    val1     val2
)
  ;;;the next function is derived from a post by Tony Tanzillo to the Adesk NG's
  (defun BrowseForFolder (/ sh folder parentfolder folderobject result)
    ;;as posted the autodesk discussion customization group by Tony Tanzillo
    (vl-load-com)
    (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
     "Shell.Application"
   )
    )

    (setq folder
   (vlax-invoke-method
     sh 'BrowseForFolder 0 "" 0)
    )
    (vlax-release-object sh)

    (if folder
      (progn
(setq parentfolder
       (vlax-get-property folder 'ParentFolder)
)
(setq FolderObject
       (vlax-invoke-method
ParentFolder
'ParseName
(vlax-get-property Folder 'Title)
       )
)
(setq result
       (vlax-get-property FolderObject 'Path)
)
(mapcar 'vlax-release-object
(list folder parentfolder folderobject)
)
result
      )
    )
  );;end BrowseForFolder
  ;;  another function, this one gets all of the drawings in the folder
  ;;  and prepends the path to the dwg name, accepts a list of folders
  (defun getdwglist (folderlist)
    (apply 'append
   (mapcar '(lambda (f)
      (mapcar '(lambda (name)
(strcat f "\\" name)
       )
      (vl-directory-files f "*.dwg" 1)
      )
    )
   folderlist
   )
    )
  )
  ;;;;main body of getindex
  ;;I placed all of these into an (and) so it will exit if anyone fails before moving on
  (if (and (setq *acad (vlax-get-acad-object)) ;;get the acad application
   (setq folder (browseforfolder)) ;;select a folder
   (setq dwgs (getdwglist (list folder)));;find all dwg's in that folder
      )
    (progn
      ;;if we made it this far we have dwg's to work with
      ;;modified 3/30/06 to allow for future versions
      (setq versn (atoi (substr (getvar "acadver") 1 2))
odbx (if (< versn 16)
       (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
       (vla-GetInterfaceObject
*acad
(strcat "ObjectDBX.AxDbDocument." (itoa versn))
       )
     )
      )
      (foreach dwg dwgs ;;loop through each drawing in the list
(if
  (and
    ;;try to open it, it will exit if there is an error
    (not (vl-catch-all-error-p
   (vl-catch-all-apply
     '(lambda ()
(vla-open odbx dwg)
      )
   )
)
    )
;;see if the block is even in the drawing, again it will exit on error
    (not
      (vl-catch-all-error-p
(vl-catch-all-apply
  '(lambda ()
     (setq blk (vla-item (vla-get-blocks odbx) blkname))
   )
)
      )
    )
  )
   (progn
     ;;no errors...carry on
     (setq layouts (vla-get-layouts odbx))
     (vlax-for layout layouts ;;cycle through each layout Tab
       (if (not (eq "MODEL" (strcase (vla-get-name layout)))) ;;exclude Model space
(progn
   (vlax-for ent (vla-get-block layout) ;;look for Inserts....BlockReference in ActiveX terms
     (if (and (eq (vla-get-objectname ent)
  "AcDbBlockReference"
      )
      (eq (strcase (vla-get-name ent)) ;;check the name
  (strcase blkname)
      )
)
       (progn
;;the name matches, get the attributes
(setq atts (vlax-invoke ent 'getattributes))
;;now cycle through the attributes and collect the values of the desired atts
(foreach att atts
   (if (eq (vla-get-tagstring att)
   (strcase attname1)
       )
     (setq val1 (vla-get-textstring att))
   )
   (if (eq (vla-get-tagstring att)
   (strcase attname2)
       )
     (setq val2 (vla-get-textstring att))
   )
)
;;add them to the master list
(setq masterlist
(cons (cons val1 val2) masterlist)
;(cons (list (vla-get-name odbx) (cons val1 val2)) masterlist);for testing
)
       )
     )
   )
)
       )
     )
   )
)
      )
      ;;we're done with ODBX, release it
      (mapcar 'vlax-release-object (list odbx *acad))
    )
  )
  ;;put the list into the order of the drawings
  (reverse masterlist)
)
;;;Test with my title block having a name of TDG and get the 2 attributes NO & SHEET_NAME
(defun c:createindex ()
  (setq indexlist (getindex "TDG" "NO" "SHEET_NAME"))
)

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #98 on: March 30, 2006, 05:00:32 PM »
I AM LIKING THIS!!! Good job Jeff!
It is starting to make more sense to me. 
Here's a question, in this part:

Code: [Select]
    (not
      (vl-catch-all-error-p
(vl-catch-all-apply
  '(lambda ()
     (setq blk (vla-item (vla-get-blocks odbx) blkname))
   )
)
      )
    )
  )
   (progn
     ;;no errors...carry on
     (setq layouts (vla-get-layouts odbx))
     (vlax-for layout layouts ;;cycle through each layout Tab
       (if (not (eq "MODEL" (strcase (vla-get-name layout)))) ;;exclude Model space
(progn
   (vlax-for ent (vla-get-block layout) ;;look for Inserts....BlockReference in ActiveX terms
     (if (and (eq (vla-get-objectname ent)
  "AcDbBlockReference"
      )
      (eq (strcase (vla-get-name ent)) ;;check the name
  (strcase blkname)
      )
)

How and where did you set the blkname to be block name???? i'm a bit lost in this section all together.
Thanks for your reply.

Viktor.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Make Sheet Index using obectDBX
« Reply #99 on: March 30, 2006, 05:13:47 PM »
Do you know how to write your own lisp routines?

How and where did you set the blkname to be block name???? i'm a bit lost in this section all together.
Thanks for your reply.

Viktor.

This is where Jeff knows what the block name is going to be, along with the attribute tag names.
Code: [Select]
(defun getindex (blkname  attname1 attname2 /      *acad    atts
dwgs   f    folder   layouts  masterlist
name   odbx    val1     val2
)

He is saying when you call this (sub) routine, you need three arguements.  The first is the block name (blkname) the second two are the tag names (attname1 attname2).  The when he calls the routine in the main routine, he supplies the arguements.

Code: [Select]
(defun c:createindex ()
  (setq indexlist (getindex "TDG" "NO" "SHEET_NAME"))
)
Tim

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

Please think about donating if this post helped you.

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #100 on: March 30, 2006, 08:16:46 PM »
Well, like i said, i'm new to this part of lisping. my history is very short with lisp, all my personal lisp routines are very messy, for example, i didn't even know how to call different functions within lisp, all my routines would start with (defun c:test (/ a b c) and end with a ) that's basic, but because i don't get much opportunity to train myself with this, i waist allot of my personal time making some simple routine in the only way i know how to.

this is excellent because it pushes me to learn all these new things, but at least they are making sense to me :)
Thanks to all for your input.

Viktor.

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #101 on: March 30, 2006, 09:16:27 PM »
i'm one of those people that can walk into a room filled with the most intelligent people on a planet, and still be able to ask the most simple question without being offended  :-)

Viktor

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #102 on: March 30, 2006, 10:07:01 PM »
ok here's one more easy question to u all.

Code: [Select]
(setq masterlist
(cons (cons val1 val2) masterlist)

In this code, val1 and val2 are combined into a masterlist by using cons????

well, my question is this, is there a way to just write the val1 and val2 to a text file instead?
can someone explain to me the importance of combining the values into one list?

what if you have just one attribute?

Thanks ahead.
Viktor.

Jeff_M

  • King Gator
  • Posts: 3942
  • C3D user & customizer
Re: Make Sheet Index using obectDBX
« Reply #103 on: March 31, 2006, 12:37:21 PM »
Hi Viktor,
Yes, (cons (cons ...)) is creating a master list of lists.
You could write these to a text file, but, IMHO, it is much more efficient to do that once, and not by this routine. By doing it this way, this routine can be used for more than one specific thing. I don't recall the 'official' term for this, but I like to refer to it as 'compartmental' coding so that code snippets cn be re-used for other programs.

If I had just one attribute then I'd just do this:
(setq masterlist (cons att1 masterlist))

See Gary's progressions for how how he handled exporting the results to a text file.


bp

  • Mosquito
  • Posts: 1
Re: Make Sheet Index using obectDBX
« Reply #104 on: April 12, 2006, 09:25:03 AM »
This is great. How would I modify this to search for a list of specific text instead of blocks with attributes. We are sometimes given a list of items( instruments which are just text comprised of hundreds of items spread across multiple drawings in a folder ) we need to locate in drawings.

Allen

Thank you, that works perfectly. I modified the code slightly. Now how would I make the list of each unit drawing "list line"
to be iin numerical order based upon the room number?

Code: [Select]
  (foreach dwg  indexlist
    (foreach itm dwg
    ;;write to list_box and notepad
      (cond
        ((= "DWG" (car itm))         
         (setq x (padout (cdr itm) 10))         
         ;(write-line (strcat x) file)
         )   
        ((= (nth 1 (car blkdata)) (car itm))
         (setq a (padout (cdr  itm) 16)))
        ((= (nth 2 (car blkdata)) (car itm))
         (setq b (padout (cdr  itm) 5))) 
        ((= (nth 3 (car blkdata)) (car itm))
         (setq c (padout (cdr itm) 10)))
        )
        (if (and a b c)
          (progn           
            (if (not x)(setq x "          "))
            (write-line (strcat x a b c) file)           
            (setq got-list (append (list (strcat x a b c)) got-list))
            (setq a nil b nil c nil x nil)))
  ))
  (close file)
  ;;added dialog box interface
  (defun do_act (key_pr) (setq op key_pr)(done_dialog)(princ))
  (setq ARCH#LOGO " Arch Program©")
  (setq ARCH#YEAR (substr (rtos (getvar "CDATE") 2 16) 1 4))
  ;;(setq dcl_id (load_dialog (strcat "" "ARCH_CreateRoomIndex-CRI.dcl")))
  (setq dcl_id (load_dialog (strcat ARCH#CUSF "BLOC/" "ARCH_CreateRoomIndex-CRI.dcl")))
  (if (not (new_dialog "ARCH_RoomIndex" DCL_ID "" '(-1 -1))) (dcl_error))   
  (set_tile "set-title" (strcat ARCH#LOGO " : CRI                           Create Room Index List"))
  (set_tile "set-copyright" (strcat ARCH#LOGO " " ARCH#YEAR " for AutoCAD®"))
  (start_list "file-list")
  (mapcar 'add_list (reverse got-list))
  (end_list)

Thank you, again.

Gary