Author Topic: (getvar "PSTYLEMODE") and ObjectDBX ??  (Read 5483 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
(getvar "PSTYLEMODE") and ObjectDBX ??
« on: January 06, 2007, 04:29:30 PM »
I am using objectdbx to process some drawings, actually setting plot styles on layers.
Problem is I want to test the drawing to see if it uses named plot styles.
In plain lisp I used (getvar "PSTYLEMODE"), so i tried (vla-getvariable obdx "PSTYLEMODE")
That didn't work, I guess sysvars are not available in objectdbx?
I was thinking a work around would be to get the layer collection  & then get layer "0" and
test for that property. [PlotStyleName] But it returns something like this "Color_0"

Got to be an easy way? What am I missing?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #1 on: January 06, 2007, 07:21:41 PM »
W.A.G.

Hi Alan
What does something like this return in the variously configured documents ..
Code: [Select]
(setq dbxDoc (kdub:OpenDbxDocument "c:Testdbx2004.dwg"))

(setq dbxoLay (vla-item (vla-get-layers dbxDoc) "0"))

[color=red];;(vla-put-PlotStyleName oLay "Bylayer")[/color] ;; rev to dbxoLay
(vla-put-PlotStyleName dbxoLay "Bylayer")


Does it only produce an exception in color dependent plot style mode ??
is so, could you trap for the exception ?

« Last Edit: January 06, 2007, 07:56:40 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #2 on: January 06, 2007, 07:24:16 PM »
.. and for the anal retentive code police ..
a warning not to  forget
Code: [Select]
(kdub:CloseDbxDocument dbxdoc)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #3 on: January 06, 2007, 07:33:36 PM »
How about something like
Code: [Select]
(and
      (VLAX-WRITE-ENABLED-P objLay)
       (VLAX-PROPERTY-AVAILABLE-P objLay "PlotStyleName")
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #4 on: January 06, 2007, 07:45:54 PM »
Thanks Kerry,
This is working because in a CTB style DWG the plot style is resturned as "Color_nnn" where nnn is the color number.
I am only testing in ACAD 2000 right now.
Code: [Select]
(defun PlotStyleUpdate (doc /  lays LayersLocked)
  (if  (= (substr (vla-get-PlotStyleName (vla-item (vla-get-layers doc)"0")) 1 5) "Color")
    (prompt (strcat "\nThis is a CTB DWG, can not proceed" (vl-filename-base (vla-get-name doc))))
    (progn
      (princ (strcat "\nUpdating " (vl-filename-base (vla-get-name doc))))
     
PS The following returns True in a CTB DWG
Code: [Select]
(and
      (VLAX-WRITE-ENABLED-P objLay)
       (VLAX-PROPERTY-AVAILABLE-P objLay "PlotStyleName"))
   
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #5 on: January 06, 2007, 07:49:44 PM »
W.A.G.

Hi Alan
What does something like this return in the variously configured documents ..
Code: [Select]
(setq dbxDoc (kdub:OpenDbxDocument "c:Testdbx2004.dwg"))

(setq dbxoLay (vla-item (vla-get-layers dbxDoc) "0"))

(vla-put-PlotStyleName oLay "Bylayer")

Does it only produce an exception in color dependent plot style mode ??
is so, could you trap for the exception ?
Yes, this may be the ticket.
 
Code: [Select]
(setq olay (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))"0")))
#<VLA-OBJECT IAcadLayer 02e10e34>
_1$ (vla-put-PlotStyleName oLay "Bylayer")
; error: Automation Error. The drawing is in color dependent plot style mode
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #6 on: January 06, 2007, 07:52:41 PM »
That looks promising !

Would you need to also look at the equivalent to
DEFLPLSTYLE
DEFPLSTYLE
PSTYLEPOLICY
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #7 on: January 06, 2007, 08:01:36 PM »
Hum, I don't think so in my application.
I am just stepping through a layer list & changing the plot styles to those in the list.
If the layer doesn't exist in the dwg I skip it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #8 on: January 06, 2007, 08:07:05 PM »
OK, this is what I get in s STB style DWG
Code: [Select]
_1$ (setq olay (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))"0"))
#<VLA-OBJECT IAcadLayer 02d1b0e4>
_1$ (vla-put-PlotStyleName oLay "Bylayer")
; error: Automation Error. Key not found

Still an error as "ByLayer" is not valid, but the msg is differant.
Problem is, testing the actual error message as it may vary from ACAD version to version.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #9 on: January 06, 2007, 08:27:09 PM »
Plotting programmatically is a bit like dealing with a wraith for me ... just get my hands around its neck and it dissolves back into the mist.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #10 on: January 06, 2007, 08:52:48 PM »
How true. :-D

I have a bunch of file from a GC which he wants modified. They are all CTB & I want to use STB.
I am not plotting them yet just trying to update the plot style names for the layer in the list.
This is what I am playing with. I took a routine by Tim & modified it for this usage.

The PlotStyleUpdate is what I threw together and works fine on a single drawing.
So I though with 12 drawing to go why not try to do it with DBX as this is not the first & surly not
the last time I have to do this.
Well, I can't seem to "SaveAs' without an error and then there is this problem testing for CTB files.
I have the CTB licked for the moment.
Any reason why I can't 'SaveAs' ? I am suspecting that it's ACAD2000. I'll try it on 2004 tomorrow.
Too tired to fight it anymore tonight.

Code: [Select]
;;;by Tim Willey 8/29/06
;;;  modified by CAB 01/03/2007
(defun C:Test (/ DirPath odbx FullPath fname usrdmd)
(setq *acad (vlax-get-acad-object))
(if
 (and
  (setq DirPath (getfolder))
  (setq odbx
   (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.16")
   )
  )
 )
 (progn
 (setq usrdmd (getvar "demandload"))
 (setvar "demandload" 0)
 (foreach Dwg (vl-directory-files DirPath "*.dwg" 1)
  (setq FullPath (strcat DirPath "\\" Dwg))
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list odbx FullPath)))
   (prompt (strcat "\n ++ Couldn't open drawing \"" FullPath "\""))
   (progn
    (prompt (strcat "\n  - Processing - " FullPath))
    (if (PlotStyleUpdate odbx)
      (progn
        ;;  CAB having trouble saving in ACAD2000
        (setq fname (vl-string-subst "\\" "\\\\" (vla-get-Name odbx))) ; CAB
        ;;(setq fname (vl-string-subst (strcat (vl-filename-base fname)"-1") (vl-filename-base fname) fname))
        ;;(vla-SaveAs odbx fname)
        (vl-catch-all-apply 'vla-saveas (list odbx fname)) ; CAB
      )
    )
   )
  )
 )
 (setvar "demandload" usrdmd)
 )
)
(and odbx (vlax-release-object odbx))
(setq odbx nil)
(princ)
)


(defun GetFolder ( / DirPat)
 (and (setq DirPat (getfiled "Browse for folder"
                   "Open a folder and click on SAVE" " " 1))
      (setq DirPat (substr DirPat 1 (- (strlen DirPat) 31)))
 )
 DirPat
)

;;  CAB 01/06/2007
;;  Update the plot style name in layers of XXXXXX Drawing
;;  command line entry
(defun c:LFPU() (PlotStyleUpdate (vla-get-activedocument (vlax-get-acad-object))))

;;  ObjectDBX entry
;;  returns true if successful
(defun PlotStyleUpdate (doc /  lays LayersLocked)
 
  (if (= (substr (vla-get-PlotStyleName (vla-item (vla-get-layers doc)"0")) 1 5) "Color")
    (prompt (strcat "\nThis is a CTB DWG, can not proceed \n    " (vl-filename-base (vla-get-name doc))))
   
    (progn
      (princ (strcat "\nUpdating  " (vl-filename-base (vla-get-name doc))))
      (setq lays (vla-get-layers doc))
      ;;  unlock and make list of layers changed
      (vlax-for lay lays
        (if (eq (vla-get-lock lay) :vlax-true)
          (progn
            (setq LayersLocked (cons lay LayersLocked))
            (vla-put-lock lay :vlax-false)
          )
        )
      )
      ;;  update each layer in the dwg found in the list
      (foreach lay (GetLayersToChange)
        (vl-catch-all-apply '(lambda(lay)
          (vla-put-plotstylename (vla-item lays (car lay)) (cadr lay)))
          (list lay)
        )
      )
      (mapcar '(lambda (x) (vla-put-lock x :vlax-true)) LayersLocked)
      t
    )
  )
)


(defun GetLayersToChange()
  '( ; (LayerName  PlotStyle)
 ("0"                "Light")
 ("1-TITLEBLK"       "Medium")
 ("A-COPYRIGHT"      "Light")
 ("A-TEXT2"          "Light")
 ("anno-appl"        "Light")
 ("anno-clg"         "Light")
 ("anno-clg-dims"    "Light")
 ("anno-dims"        "Light")
 ("anno-legn"        "Light")
 ("anno-legn-bord"   "Light")
 ("anno-legn-text"   "Light")
 ("anno-notes"       "Light")
 ("anno-plumb"       "Light")
 ("anno-rev"         "Light")
 ("anno-rmname"      "Light")
 ("anno-rmsize"      "Light")
 ("anno-tags"        "Light")
 ("anno-ttl"         "Light")
 ("anno-ttlblk"      "Light")
 ("appliance"        "Light")
 ("area"             "Light")
 ("area3"            "Light")
 ("beam-abv"         "Light")
 ("case-abv"         "Light")
 ("casework"         "Light")
 ("clg-abv"          "Light")
 ("column"           "Light")
 ("column-blw"       "Light")
 ("column-int"       "Light")
 ("door"             "Light")
 ("door-frame"       "Light")
 ("door-panel"       "Light")
 ("door-stop"        "Light")
 ("door-swing"       "Light")
 ("door-thresh"      "Light")
 ("door-trshld"      "Light")
 ("electric"         "Light")
 ("elevator"         "Light")
 ("equip-abv"        "Light")
 ("equipment"        "Light")
 ("f1"               "Light")
 ("hatching"         "Light")
 ("hose-bib"         "Light")
 ("insulat"          "Light")
 ("plumbing"         "Light")
 ("railing"          "Light")
 ("site-fence2"      "Light")
 ("slab"             "Light")
 ("slab-deck"        "Light")
 ("stairs"           "Light")
 ("TBLK BOLD"        "Heavy")
 ("TBLK GREY"        "Light")
 ("TBLK HEAVY"       "Heavy")
 ("TBLK LIGHT"       "Light")
 ("TBLK MEDIUM"      "Medium")
 ("TBLK NAME"        "Light")
 ("wall"             "Heavy")
 ("wall-glass"       "Light")
 ("wall-int-abv"     "Light")
 ("wall-int-blw"     "Light")
 ("wall-int-fin"     "Heavy")
 ("wall-int-hat"     "Light")
 ("wall-msn-abv"     "Light")
 ("wall-msn-blw"     "Light")
 ("wall-msn-fin"     "Heavy")
 ("wall-msn-hat"     "Light")
 ("wall-open"        "Light")
 ("wall-open-above"  "Light")
 ("wall-plumb"       "Light")
 ("wall-pres-fil"    "Light")
 ("wind-frame"       "xLight")
 ("wind-glass"       "xLight")
 ("wind-sash"        "xLight")
 ("window"           "Light")
 ("Z-TITLE-TEXT"     "Light")))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (getvar "PSTYLEMODE") and ObjectDBX ??
« Reply #11 on: January 06, 2007, 09:04:53 PM »
Oh, this is the error. It does save the drawing but the routine stops!

Code: [Select]
Updating ACAD-A-02 Notes Plan-2; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on unknown exception
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.