Author Topic: extract information from .dwg  (Read 6321 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
extract information from .dwg
« on: November 19, 2004, 12:21:38 PM »
first,happy friday to those this applies to.
but its not the end of the day for me. so here is what is coming next. i need to check the base point of about 1000 dwg's. what i want to do is see if the base point is 0,0,0. actually i would just like to know what it is. im pretty sure 95% of them have that as the base point but i need all of them to. so what i thought was some sort of script that ran through a directory and checked each drawing. the information i would need to be able to put on paper is the name of the drawing and its base point. the only problem is i dont know what i have to do to do this. can someone lead me in the right direction. what it is going to allow me to do is go into the drawings where the base point isnt 0,0,0 and change it to that. but i dont want to open a 1000 or so drawings to check. all help is appreciated. thanks

M-dub

  • Guest
extract information from .dwg
« Reply #1 on: November 19, 2004, 12:35:11 PM »
A few years ago, I did this exact same task.
I'll look to see if I have my old scripts around and get back to you shortly.

Oak3s

  • Guest
extract information from .dwg
« Reply #2 on: November 19, 2004, 12:40:23 PM »
thank you, where they details? i dislike details :)

M-dub

  • Guest
extract information from .dwg
« Reply #3 on: November 19, 2004, 12:41:23 PM »
Have a look HERE...

Oak3s

  • Guest
extract information from .dwg
« Reply #4 on: November 19, 2004, 12:51:02 PM »
well, that would have been nice two days ago. i already went into drawings and changed them. some things i couldnt acomplish with a script. but now all i want to do is pull the basepoint value out along with the file name and print it out on paper. i could go through and check each one myself but who would want to do that. i want (i sound like a little kid) the script to run and in the end i want :cry: (being a baby now) to open a notepad or something and see the results. if i cant do that....its going to be a longggggg friday :)

Oak3s

  • Guest
extract information from .dwg
« Reply #5 on: November 19, 2004, 12:59:17 PM »
the reason i dont just run a script to change the base to 0,0,0 is because i have to go into the drawing and move something to that point. unfortuanantly it isnt a block with an ins i can move to that point.

M-dub

  • Guest
extract information from .dwg
« Reply #6 on: November 19, 2004, 01:12:16 PM »
Did you see the macro I had posted at the bottom of the other thread?
Code: [Select]
^C^Cmove;all;;\0,0;base;0,0;z;e;change;all;;p;c;bylayer;la;0;lt;bylayer;;-layer;s;0;;-purge;a;;n;

Oak3s

  • Guest
extract information from .dwg
« Reply #7 on: November 19, 2004, 01:27:23 PM »
from what i read from that macro is it moves everything to 0,0 from a point you pick. it changes the base to 0,0. it zoom extends. then puts everthing on layer 0 with everthing set to by layer. then it sets 0 to current layer. then it purges. but i already went through something like this. now what i want to do is check to see if the base point is actually set to 0,0. then in excel or notepad or something i want to see on paper the name of the file and the base point:

file                                           base point
100-001                                   0,0,0
100-002                                   0,0,0
100-003                                   3/4, 2, 0          (now this i would go change)

i would have to go into the drawing and change that myself because i want a quadrant of a cirlce to be there. i already went through and moved everything as far as i know. but instead of just changing the basepoint to 0,0 in a script, i want to know which ones arnt that way so i can open them and edit them because they need some other things done that a script can do.
but thats for the macro M-dub. maybe im reading it wrong and your giving me all i need already. im sorry if thats the case.[/b]

ELOQUINTET

  • Guest
extract information from .dwg
« Reply #8 on: November 19, 2004, 01:41:47 PM »
hmmm my thought is how can you find an object in a drawing externally if it is not a block and doesn't have a defined base point. the external files has no reference, that is if i've read this correctly?

M-dub

  • Guest
extract information from .dwg
« Reply #9 on: November 19, 2004, 01:50:32 PM »
Ok, I get you now...
I don't currently have anything to help you get there, but I'm sure someone could help you.  It seems like it would be a pretty simple routine to write.  Mark wrote me one for extracting the layers of a drawing into a CSV file and I think this is exactly what you're looking for, only with the basepoints instead of the layers.
Code: [Select]
(defun c:layers2csv (/ get->layobj open->file lay lylst fo)
  (vl-load-com)

  (defun get->layrobj ()
    (vla-get-Layers
      (vla-get-ActiveDocument
        (vlax-get-acad-object)
        )
      )
    )
 
    (vlax-for lay (get->layrobj)
      (setq lylst
             (cons
               (list
                 (vlax-get-property lay 'Name)
                 (itoa (vlax-get-property lay 'Color))
                 (vlax-get-property lay 'Linetype)
                 )
               lylst
               )
            )
      )

  (if lylst
    (progn
       ; remove layer '0' and reverse the list
      (setq lylst (reverse (vl-remove (last lylst) lylst))
            ; sort the list
            lylst (vl-sort lylst '(lambda (x y) (< (car x)(car y))))
            fo (open (strcat "c:/"(getvar 'dwgname)".csv") "w"); suitable for Excel
            )
      (foreach l lylst
        (write-line (strcat (car l) "," (cadr l) "," (last l)) fo)
        )
      (close fo)
      )
    )

  (princ)
  )

Oak3s

  • Guest
extract information from .dwg
« Reply #10 on: November 19, 2004, 01:57:03 PM »
seems like thats something headed in the right direction. sorry for the confusion. im still not where i would like to be. there is to much in that code that i dont understand enough of to modify it. thanks for the help though. i will try to play with it for a while.

ronjonp

  • Needs a day job
  • Posts: 7531
extract information from .dwg
« Reply #11 on: November 19, 2004, 02:33:35 PM »
Here is lisp I use to make the insertion point of a detail in the middle of the block. Don't know if this helps but thought I'd throw it out there.

Code: [Select]
(defun c:dins (/ cen_screen)

(command ".zoom" "extents")
(setq cen_screen (getvar 'viewctr)
)
  (command ".base" cen_screen )
  (princ)
)


Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Oak3s

  • Guest
extract information from .dwg
« Reply #12 on: November 19, 2004, 02:41:38 PM »
thanks ronjonp. lol, doesnt help but maybe it will for something else.
ive looked at the autodesk forums and cant find this there. sounds like it should be simple. but i dont know how to go about getting the information and putting that in a excel file or a txt file. basicly i dont know how to write the important parts of the script ;) lol....it might be a long day. bummer.

ronjonp

  • Needs a day job
  • Posts: 7531
extract information from .dwg
« Reply #13 on: November 19, 2004, 02:59:20 PM »
Do you just want to see if the base is set to 0,0,0 or an object from a certain point is at 0,0,0?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

M-dub

  • Guest
extract information from .dwg
« Reply #14 on: November 19, 2004, 03:10:41 PM »
Here's the pseudo code I think he's looking for.

1. Get current BASE point
.........save it in a variable
2. Get current dwgname
.........save it in a variable
3. Export the information into a txt or csv file like so
Drawing Number____|____Basepoint
__ABC123.dwg______|______0,0,0__

I think that he'd then want to create a script so he could perform this lisp routine on a multitude of drawing files automatically, having the information appended to the txt or csv file.

Am I right, Oak3s?

Oak3s

  • Guest
extract information from .dwg
« Reply #15 on: November 19, 2004, 03:15:54 PM »
i just want to know if the basepoint is 0,0,0. and find that out without manually opening every drawing.

Oak3s

  • Guest
extract information from .dwg
« Reply #16 on: November 19, 2004, 03:18:21 PM »
that is exactly right!!!! Praise the AutoCAD Lord whomever he or she may be. we have pseudo code people should understand.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #17 on: November 19, 2004, 03:29:21 PM »
Oak3s -
What version of acad are you using?
TheSwamp.org  (serving the CAD community since 2003)

Oak3s

  • Guest
extract information from .dwg
« Reply #18 on: November 19, 2004, 03:31:50 PM »
Mark - 2002 no third party software.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #19 on: November 19, 2004, 03:34:42 PM »
Oak3s -
what do you get when you paste this into acad?
Code: [Select]

(vl-load-com)
(vlax-product-key)
TheSwamp.org  (serving the CAD community since 2003)

Oak3s

  • Guest
extract information from .dwg
« Reply #20 on: November 19, 2004, 03:40:40 PM »
i dont know what the last part means.....i hope its not top secret stuff that will get me in trouble. but it says release 15 and then ACAD-1:409.  nevermind, here is the whole thing. maybe you need something else.
Software\\Autodesk\\AutoCAD\\R15.0\\ACAD-1:409

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #21 on: November 19, 2004, 03:45:40 PM »
thanks......... BRB, I hope!
TheSwamp.org  (serving the CAD community since 2003)

M-dub

  • Guest
extract information from .dwg
« Reply #22 on: November 19, 2004, 03:58:55 PM »
You've got the master on it now, Jeremy...No worries!  :)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #23 on: November 19, 2004, 04:00:49 PM »
copy a few files to a temp dir, create a dwg list file and run this from a new acad dwg and session. BTW, cross your fingers. :D
Code: [Select]

(defun c:getbase ( / ; internal functions
                   release read-parse-file var2lst
                   ; local variables
                   fn dwg_names_lst out_file_name out_file_open
                   acad_app acad_app_docs open_doc in_base dwg_name)

  ;;; this will create a .csv file containing the BASE coordinates and name
  ;;; of every dwg in a list of dwgs read from a text file. path *must* be
  ;;; included. i.e. c:\temp\dwgname.dwg
  ;;; the output file (__file-bases.csv) will be in the same location of
  ;;; your dwg list file.
  ;;;
  ;;; sample dwg list
  ;;; C:\Temp\Dwgs\detail1.dwg
  ;;; C:\Temp\Dwgs\detail2.dwg
  ;;; C:\Temp\Dwgs\detail3.dwg
  ;;;
  ;;; sample output
  ;;; (0.0 0.0 0.0),C:\Temp\Dwgs\detail1.dwg
  ;;; (0.0 0.0 0.0),C:\Temp\Dwgs\detail2.dwg
  ;;; (0.0 0.0 0.0),C:\Temp\Dwgs\detail3.dwg
  ;;;
  ;;; *no* error trapping, use at your own risk

  (vl-load-com)

  (defun release (obj /)
    (if
      (= (type obj) 'VLA-OBJECT)
      (if (not (vlax-object-released-p obj))
        (vlax-release-object obj)
        )
      )
    )


  (defun read-parse-file (fn / ln name_lst)
    (setq fo (open fn "r"))
    (while (setq ln (read-line fo))
           (setq name_lst (cons ln name_lst))
           )
    (close fo)
    (reverse name_lst)
    )

  (defun var2lst (var)
    (if (= (type var) 'VARIANT)
      (vlax-safearray->list
        (vlax-variant-value var)
        )
      )
    )

  ;; ====== body of main starts here ======

  ;; user dialog box for selecting the path\image file
  (if (setq fn (getfiled "Select File to Read" "" "txt" 8))
    (progn
      (setq dwg_names_lst (read-parse-file fn)
            out_file_name (strcat (vl-filename-directory fn) "\\__file-bases.csv")
            out_file_open (open out_file_name "w")
            )
      )
    (exit)
    )


  ;; open another acad session in the background
  (setq acad_app (vlax-create-object "AutoCAD.Application.15"))
 ; (setq acad_app (vlax-create-object "AutoCAD.Application.16"))

  (setq acad_app_docs (vla-get-documents acad_app))

  (foreach dwg dwg_names_lst

           (setq open_doc (vlax-invoke-method acad_app_docs 'Open dwg))

           (setq in_base
                 (var2lst
                   (vlax-invoke-method open_doc 'GetVariable "insbase")
                   )
                 dwg_name (vlax-get-property open_doc 'FullName)
                 )
           (write-line
             (strcat
               (vl-princ-to-string in_base)","dwg_name
               )
             out_file_open
             )

           (vlax-invoke-method open_doc "Close" :vlax-false)
           (release open_doc)

           )

  (close out_file_open)

  (vlax-invoke-method
    (vla-item acad_app_docs 0) "Close" :vlax-false); closes the intial dwg (Drawing1.dwg)
  (vlax-invoke-method acad_app 'Quit)

  ;(release acad_app)

  (princ)

  )
TheSwamp.org  (serving the CAD community since 2003)

Oak3s

  • Guest
extract information from .dwg
« Reply #24 on: November 19, 2004, 04:14:47 PM »
how do i create a dwg list file?  :oops:  man, that question makes me feel dumb. i think its something to do with DOS. i could be way wrong but im one of those who never worked in DOS. i feel like im getting somewhere though. thanks Mark for the code...even though i havent ran all the way through it yet.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #25 on: November 19, 2004, 04:56:37 PM »
open a shell (dos window) 'cd' to the dir with the files you want to list. 'dir *.dwg >dwg_list.txt' or what ever you want to list, then open that file with your favorite text editor and add the path to each line so you end up with someting like the sample in the code. You can also find free apps that do the same thing. Search for "directory list maker" or some such.
TheSwamp.org  (serving the CAD community since 2003)

Oak3s

  • Guest
extract information from .dwg
« Reply #26 on: November 19, 2004, 05:01:31 PM »
hey Mark, i got it. thanks for the help. it rocks. does exactly what i want. man, you made my day. one thing that is weird though (probably because i have never seen it) its running in the background so i looks like autocad locks up. but way cool anyway. thanks for the help. its appreciated very much. and to everyone else who had comments. thanks

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #27 on: November 19, 2004, 05:14:26 PM »
Yes it is running in the background, the app opens another session of acad in the background, it's much like running a script only it's not processing in the current acad session. Just be very careful with that because you are openning and closing each dwg in the list. I usually let it run at night when nothing else is going on.

Glad you like.
TheSwamp.org  (serving the CAD community since 2003)

Oak3s

  • Guest
extract information from .dwg
« Reply #28 on: November 19, 2004, 05:50:33 PM »
something interesting about the output of this. it has the two 'colums'. one for base point and one for the file name. this is what it looks like.
(0.0 0.0 0.0)_____________file name
(0.0 0.0 0.0)_____________file name2
but some of them have (0.0 4.59227E-o16 0.0) and when i check the basepoint manualy it says 0,0,0. so what i thought was maybe it had to do with unit percision. well the percision is max on all of them. so then i thought maybe it was coordinates. but the coords varuable is 1 in all of them. so then i thought maybe it had something to do with the units blocks are inserted at. well so far i have been wrong. anyone have any other ideas what it could be. the drawings have the same basepoint, same units, same percision. so im clueless.
enjoy the weekend.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
extract information from .dwg
« Reply #29 on: November 19, 2004, 06:50:21 PM »
send me the dwg if you like, i'll see what I can find out.
TheSwamp.org  (serving the CAD community since 2003)