Author Topic: Free from Displays, Visretain, and View Layer States  (Read 5250 times)

0 Members and 1 Guest are viewing this topic.

jbuzbee

  • Swamp Rat
  • Posts: 851
Free from Displays, Visretain, and View Layer States
« on: May 03, 2006, 01:12:24 PM »
I have recently turned away from Displays and gone to the dark side: Layers.  You can now call me "Darth Buzz".

A few reasons?  Visretain, nested Xrefs and the xref override command.

So I've gone back to the simplicity of layers.  If anyone would like more information on how to use ADT on a Layer Based platform just let me know: it's kinda lonely over here on the dark side:  But I have TOTAL control over the display of my projects now!

jb
James Buzbee
Windows 8

whdjr

  • Guest
Re: Free from Displays, Visretain, and View Layer States
« Reply #1 on: May 03, 2006, 01:39:41 PM »
Please shadow us with your dark conjures Oh Dark One...

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Free from Displays, Visretain, and View Layer States
« Reply #2 on: May 09, 2006, 12:04:38 PM »
Code: [Select]
;;; ObjectDBX functions
;;;
;;;

(if (< (atoi (getvar "AcadVer")) 16)
  (cond ((vl-registry-read "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"))
        ((not (setq dbxserver (findfile "AxDb15.dll")))
         (alert "Error: Can't locate ObjectDBX Library (AxDb15.dll)"))
        (t
         (startapp "regsvr32.exe" (strcat "/s \"" dbxserver "\""))
         (or (vl-registry-read "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID")
             (alert "Error: Failed to register ObjectDBX ActiveX services.")))))

;;; Open a dbxDoc ;
;;; use (setq dbxDocument(jb:OpenDbxDocument "MyFile.dwg")) ;
(defun jb:OpenDbxDocument  (DwgName / app doc dbxopen dbxDoc)
  (setq app(vlax-get-acad-object)
        doc(vla-get-ActiveDocument app))     
  (if (/= dwgname
          (vla-get-fullname doc))
    (progn (cond
             ((= (substr (getvar "ACADVER") 1 5) "15.06")
              (setq dbxDoc  (vla-GetInterfaceObject app "ObjectDBX.AxDbDocument")
                 dbxopen (vl-catch-all-apply 'vla-open (list dbxDoc DwgName))))
             ((= (substr (getvar "ACADVER") 1 4) "16.0")
              (setq dbxDoc  (vla-GetInterfaceObject app "ObjectDBX.AxDbDocument.16")
                 dbxopen (vl-catch-all-apply 'vla-open (list dbxDoc DwgName))))
             ((= (substr (getvar "ACADVER") 1 4) "16.1")
              (setq dbxDoc  (vla-GetInterfaceObject app "ObjectDBX.AxDbDocument.16")
                 dbxopen (vl-catch-all-apply 'vla-open (list dbxDoc DwgName))))
     ((= (substr (getvar "ACADVER") 1 4) "16.2")
              (setq dbxDoc  (vla-GetInterfaceObject app "ObjectDBX.AxDbDocument.16")
                 dbxopen (vl-catch-all-apply 'vla-open (list dbxDoc DwgName)))))
           (if (vl-catch-all-error-p dbxopen)
             (setq dbxDoc nil))))
  dbxDoc)

;;; Close dbxDoc
;;; (jb:CloseDbxDocument dbxDocument)
(defun jb:CloseDbxDocument  (dbxdoc)
  (if (= (type dbxDoc) 'VLA-OBJECT)
    (progn (vlax-release-object dbxDoc) (setq dbxDoc nil))))



;;;(jb:GetLayerList "X_Base")
;;;(jb:GetLayerList "*")
;;;(jb:GetLayerList nil)
;;;(setq xref nil)
(defun jb:GetLayerList  (xref / layers ret)
  (setq layers (vla-get-layers jbthisdrawing))
  (cond ((= xref "*")
         (vlax-for x layers (setq ret (append ret (list (vla-get-name x))))))
        ((= xref nil)
         (vlax-for
                x  layers
           (if (not (vl-string-search "|" (vla-get-name x)))
             (setq ret (append ret (list (vla-get-name x)))))))
        (t
         (vlax-for
                x  layers
           (if (vl-string-search (strcat xref "|") (vla-get-name x))
             (setq ret (append ret (list (vla-get-name x))))))))
  ret)


(defun jb:load-plotstyle  (dbxDoc lpltstyle / tempobj doc)
  (if (not (member (cons 3 lpltstyle)
                   (dictsearch (namedobjdict) "ACAD_PLOTSTYLENAME")))
    (setq newln
           (vl-catch-all-apply
             'vla-CopyObjects
             (list
               dbxDoc
               (vlax-safearray-fill
                 (vlax-make-safearray vlax-vbObject '(0 . 0))
                 (list (vla-item
                         (vla-item (vla-get-Dictionaries dbxDoc) "ACAD_PLOTSTYLENAME")
                         lpltstyle)))
               (vla-item (vla-get-Dictionaries jbthisdrawing) "ACAD_PLOTSTYLENAME")))))
  newln)

(defun jb:LayerStateEngine  (lstatename dwgname layerlist / dbxdoc dbxdict dict dbxplotstyles
                             dbxlayernames dbxlinetypes)
  (setvar "clayer" "0")
  (princ "\nSetting the current layer to 0")
  (princ)
  (setq dbxdoc (jb:OpenDbxDocument DwgName))
  (if dbxdoc
    (progn (setq lstateobj (jb:getlayerobject))
           (if lstateobj
             (progn (vla-setdatabase lstateobj (vla-get-database dbxdoc))
                    (vlax-invoke lstateobj 'restore lstatename)
                    (setq dbxlayers (vla-get-layers dbxdoc)
                          layers    (vla-get-layers jbthisdrawing))
    ;get a list of layers in the dbxdoc - because there's no "has" method!
                    (vlax-for
                           x  (vla-get-layers dbxdoc)
                      (setq dbxlayernames
                             (append dbxlayernames (list (strcase (vla-get-name x))))))
    ;(setq n "X_Base43|A-Wall-Patt")
    ;(setq n(nth 3 layerlist))
                    (foreach
                           n  layerlist
                      (if (and (not (= n "0"))
                               (member (strcase (jb:striplayername n)) dbxlayernames))
                        (progn (setq lobj    (vla-item layers n)
                                     lobjdbx (vla-item dbxlayers (jb:striplayername n)))
                               (foreach
                                      property  (list "Freeze" "LayerOn" "Lineweight" "Lock"
                                                      "Plottable" "color")
                                 (vlax-put lobj property (vlax-get lobjdbx property)))
    ;set plotstyle
                               (setq ps (vlax-get lobjdbx "PlotStyleName"))
                               (jb:load-plotstyle dbxdoc ps)
                               (vlax-put lobj "PlotStyleName" ps)
    ;set linetype
                               (setq ln (vlax-get lobjdbx "Linetype"))
                               (if (not (tblsearch "ltype" ln))
                                 (setq newln
                                        (vl-catch-all-apply
                                          'vla-CopyObjects
                                          (list dbxDoc
                                                (vlax-safearray-fill
                                                  (vlax-make-safearray vlax-vbObject '(0 . 0))
                                                  (list (vla-item (vla-get-linetypes dbxDoc) ln)))
                                                (vla-get-linetypes jbthisdrawing)))))
                               (if (tblsearch "ltype" ln)
                                 (vlax-put lobj "Linetype" ln)))))))
           (jb:CloseDbxDocument dbxdoc)
           (vlax-release-object lstateobj)))
  (vla-regen jbthisdrawing acActiveViewport))


(defun jb:striplayername  (string / pos ret)
  (if (vl-string-position (ascii "|") string)
    (setq pos (+ (vl-string-position (ascii "|") string) 2)
          ret (substr string pos (+ (- (strlen string) pos) 1)))
    (setq ret string))
  ret)


;;;(jb:ReturnDBXLayerStates(jb:ReturnLayerStandardsFile))
(defun jb:ReturnDBXLayerStates (dwgname   /    dbxdoc
lstate-dict-object    lstate-dict
named-obj-dict   ldict    acad_lstate
acad_lstate_defs)
  (setq ret    nil
dbxdoc (jb:OpenDbxDocument DwgName))
  (if dbxdoc
    (progn
      (setq lstate-dict-object
     (vla-GetExtensionDictionary (vla-get-layers dbxdoc))
    lstate-dict
     (entget (vlax-vla-object->ename lstate-dict-object))
    named-obj-dict
     (vlax-vla-object->ename (vla-get-Dictionaries dbxdoc)))
      (if lstate-dict
(progn
  (if (setq ldict (member (cons 3 "ACAD_LAYERSTATES") lstate-dict))
    (progn (setq acad_lstate (cdr (assoc 360 ldict)))
   (foreach
  x  (entget acad_lstate)
     (if (and (eq 3 (car x)))
       (setq acad_lstate_defs (append acad_lstate_defs (list (cdr x))))))
   (vlax-release-object lstate-dict-object)))))
      (jb:CloseDbxDocument dbxdoc)))
  acad_lstate_defs)
 
James Buzbee
Windows 8

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Free from Displays, Visretain, and View Layer States
« Reply #3 on: May 09, 2006, 12:19:46 PM »
That's the code!  Now:

Go in and edit all your styles to use layers: you can use materials to make global changes easier, but have all the display properties tied to a specific layer.  An examle would be if you want to control the hatch of a wall put it on layer "A-Wall-Patt" and make all properties "bylayer".  In a file save all the different layer states for all the different plan conditions you use: I have 'Floor Plan', 'Reflected Plan', 'Screened', 'Reflected Screened', and 'Standard'.  Now you can have more, for different detail etc, but this is all I need.  I use the Layer Standard File to save my layer states - that way it's easy to find them via code (I'll include that code at the end of this post).

Now the easiest way to implement this would be to set up a pull down, or series of toolbar buttons, or even a tool palette.  Use the following in a macro:

Code: [Select]
(jb:LayerStateEngine lstatename dwgname layerlist)
'lstatename As String: the name of the layer state to run: "Floor Plan"
'Dwgname As String: the name and path of the drawing with the saved layer states.
'layerlist As List: a list of the layers to change

OK, the LayerList. 
Code: [Select]
(jb:GetLayerList "X_Base") returns all the layers associated with the xref "X_Base" ala "X_Base|A-Wall"
Code: [Select]
(jb:GetLayerList "*") returns all layer names xref and local
Code: [Select]
(jb:GetLayerList nil) returns only local layer names - no xrefs


So as you can see with this code you have complete control over xrefs and the display of their layers.
James Buzbee
Windows 8

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Free from Displays, Visretain, and View Layer States
« Reply #4 on: May 09, 2006, 12:26:34 PM »
Oops forgot the code to get the Layer Standard Drawing:

Code: [Select]
;;; ADT Variable Function ;
;;; Layer Standard Drawing (jb:GetADTVar 5) ;
;;; Layer Standard  (jb:GetADTVar 9) ;
;;; Drawing Scale(jb:GetADTVar 40) ;
;;; Annotation size (jb:GetADTVar 42) ;
;;; ;


;;; Return ADT Variable Value ;

(defun jb:GetADTVar  (var / dict vars ret)
    ;check to see if the dict exists, if not initialize it . . .
  (if (not (cdar (dictsearch (namedobjdict) "AEC_VARS")))
    (aeclayerkeylist))
  (setq dict (dictsearch
               (cdar (dictsearch (namedobjdict) "AEC_VARS"))
               "AEC_VARS_DWG_SETUP")
        vars (member '(100 . "AecDbVarsDwgSetup") dict)
        ret  (cdr (assoc var vars)))
  ret)

Now, the way I implement this is through a VBA form: I did use ODCL up until about a month ago.



If anyone wants the form let me know - I don't know how to upload files though??

James Buzbee
Windows 8