Author Topic: odbx help  (Read 3122 times)

0 Members and 1 Guest are viewing this topic.

OcCad

  • Guest
odbx help
« on: October 09, 2008, 12:40:08 PM »
Hey guys! Im modifying some odbx code previously helped with on this site for a new need- modifying files exported from revit to suit the architect. There are more pieces to the puzzle, however, I'll post what I think would be an easier fix first. Currently I am wanting to step through a folder and for each drawing simply turn off a layer and delete a layout. For some reason though it wants to delete "Layout2" in my current drawing and then locks up saying "Layout2" doesnt exist. Also if I try to "temporarily" fix the problem by adding Layout2 in my current drawing (which it shouldnt be accessing in the first place) I get and "error writing/closing file."  Any help with this first part is appreciated.

(main purpose of function will end up being... open folder with dwgs/convert from ctb to stb/modify pagesetup to "company.stb"/change all layers to plot by style "black"/turn off layer "a-anno-nplt"/delete "layout2"/close dwg)

Code: [Select]
;;;
;;;  *** -- Main Function -- ***
;;;

(defun c:smf (/)

;  (setq saveErrorOdbx *error*
; *error* BATodbxEngineError
; dbx_doc nil
;  )

(vl-load-com)

  (setq dir_path (BrowseForFolder "Select folder to process: " "My Computer"))
  (setq dwgs (vl-directory-files dir_path "*.dwg" 1)) ;;;FILTER FILE NAME HERE****
  (setq dbx_doc (vla-GetInterfaceObject
                  (vlax-get-acad-object)
                  (strcat "ObjectDBX.AxDbDocument." (substr (getvar "acadver") 1 2))
                )
  )

  (foreach dwg dwgs
    (setq dwg_path (strcat dir_path dwg))
    (vlax-invoke dbx_doc "Open" dwg_path)
      (if dwg
        (progn
          (prompt (strcat "\n  - Report for - " dwg))
            (progn
;              (vlax-map-collection
;                (vla-get-layers dbx_doc)
;                '(lambda (x)
;                   (if x
;                     (vl-catch-all-error-p
;                       (vl-catch-all-apply 'vla-put-plotstylename (list x "black"))
;                     );vl-catch
;                     (progn
;                       (setq err_msg (strcat "*** Plotstyles not updated ***"))
;                       (princ "\n")(princ err_msg)
;                     );progn
;                   );if
;                 );lambda
;              );vlax-map
               (if (setq lyr (get_item (vla-get-layers dbx_doc) "a-anno-nplt"))
                (progn
                  (vla-put-layeron lyr :vlax-false)
                  (princ "\n    Layer updated!")
                );progn
                (progn
                  (setq err_msg (strcat "*** Layer does not exist in drawing ***"))
                  (princ "\n")(princ err_msg)
                );progn
               );if
               (if (setq xlayout (get_item (vla-get-layouts dbx_doc) "Layout2"))
                (progn
                  (vla-delete xlayout)
                  (princ "\n    Layout deleted!")
                );progn
                (progn
                  (setq err_msg (strcat "*** Layout does not exist in drawing ***"))
                  (princ "\n")(princ err_msg)
                );progn
               );if
            (vla-SaveAs dbx_doc dwg_path)
            );progn
        );progn
        (prompt (strcat "\n *** Couldn't open drawing \"" dwg "\""))
      );if
  );foreach
 
  (vlax-release-object dbx_doc)
; (setq *error* saveErrorOdbx)
  (setq dbx_doc nil)
  (princ)

);end defun

previous help & references can be credited here:

http://www.theswamp.org/index.php?topic=14334.0

http://www.theswamp.org/index.php?topic=13732.0

http://www.theswamp.org/index.php?topic=21649.0

http://www.theswamp.org/index.php?topic=12147.0

T.Willey

  • Needs a day job
  • Posts: 5251
Re: odbx help
« Reply #1 on: October 09, 2008, 12:53:54 PM »
The layout one seems to be a bug.  I tested in both '06 and '08 and get the same thing.  It will delete the layout from the current drawing, not the one open with ObjectDBX.

The layer one isn't hard.  You would just step through the layer collection ( vlax-for ... ) and when you find the one you want, change the 'Freeze' property to what you want.
Tim

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

Please think about donating if this post helped you.

OcCad

  • Guest
Re: odbx help
« Reply #2 on: October 09, 2008, 01:01:03 PM »
yeah the layer one works fine for me but as soon as i added the code for the layout, all hell broke loose. Any way around it?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: odbx help
« Reply #3 on: October 09, 2008, 01:08:35 PM »
Doesn't look like it ( at least I couldn't find one ).
Tim

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

Please think about donating if this post helped you.

OcCad

  • Guest
Re: odbx help
« Reply #4 on: October 09, 2008, 01:54:45 PM »
so then if im forced to only be able to do this through a batch file, how can I modify "layout1" page setup to use "company.stb"?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: odbx help
« Reply #5 on: October 09, 2008, 01:58:00 PM »
so then if im forced to only be able to do this through a batch file, how can I modify "layout1" page setup to use "company.stb"?
That one I'm not sure of, as I don't use .stb.  Look at the command 'convertpstyles' though, as that should get you where you want to be.
Tim

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

Please think about donating if this post helped you.

OcCad

  • Guest
Re: odbx help
« Reply #6 on: October 09, 2008, 02:07:17 PM »
i have. these would be commands to be included in my batch file. i'm exporting from revit so color mapping is related to revit.stb but when plotting in page setup want to switch to company.stb

Code: [Select]
       (setq FullPath (strcat DirPath Dwg))
        (write-line (strcat "_.open " (chr 34) FullPath (chr 34)) Ofil)
        (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") Ofil)
        (write-line (strcat "_layout" " " "set" " " "layout1") Ofil)
        (write-line (strcat "_zoom" " " "extents" " ") Ofil)
        (write-line (strcat "_layout" " " "delete" " " "layout2") Ofil)
        (write-line (strcat "_convertpstyles" " " "revit.stb" " ") Ofil)
        (write-line (strcat "_-purge" " " "all" " " "*" " " "n") Ofil)
        (write-line (strcat "_-layer" " " "pstyles" " " "black " " "*" " ") Ofil)
        (write-line (strcat "_-layer" " " "off" " ""a-anno-nplt" " ") Ofil)
        (write-line (*** PAGESETUP TO SWITCH TO COMPANY.STB***) Ofil)
        (write-line "_.qsave" Ofil)
        (write-line "_.close" Ofil)

have looked into sheet set manager however it doesnt attach the setup to each sheet, only to the sheet setup. (ex: when i go to plot dialog box for individual sheet it doesnt show wanted page setup but does in sheet set manager page setup)

OcCad

  • Guest
Re: odbx help
« Reply #7 on: October 09, 2008, 03:10:07 PM »
Weird... when running the above script I'm having another problem now with converting over to .stb



but i know my paths are okay because i can immediately type it in afterwards and have it work okay

« Last Edit: October 09, 2008, 03:13:52 PM by Lexicon »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: odbx help
« Reply #8 on: October 09, 2008, 03:12:27 PM »
Maybe someone with more experience in dealing with stb will chime in.  Sorry I can't be of more help on this one.
Tim

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

Please think about donating if this post helped you.

OcCad

  • Guest
Re: odbx help
« Reply #9 on: October 09, 2008, 06:46:51 PM »
Hey Tim,

Well I figured out a solution. What I couldnt get done in batch I added by loading in a lisp. Its unfortunate that it all couldnt be done through ObjectDBX. May be someday someone else will be able to find a fix. Thank you for your help sir!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: odbx help
« Reply #10 on: October 09, 2008, 06:50:58 PM »
I'm glad you got something to work for you Lexicon, even if it isn't the quickest way, it is still a way that you don't have to interact with so many drawings.

You're welcome for what little I helped you with.
Tim

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

Please think about donating if this post helped you.