Author Topic: LayerStates  (Read 11690 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
LayerStates
« on: February 03, 2004, 12:03:01 PM »
Has anybody had any luck with exporting a layer state? Here's the script.
Code: [Select]
(setq laystatenam (substr (getvar 'dwgname) 5 4)
  stateprefix (getvar 'dwgprefix))
     (command ".layer" "a" "s" laystatenam "" "ex" laystatenam stateprefix "" "")

Under normal circumstances that should work, but in export all that is exported is .las. The layer state name is not there. The laystatenam variable should contain A000 and does create a state with that name, it just doesn't use it when it exports it. Is there a way to tell it to use it, without selecting it or typing it in?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
LayerStates
« Reply #1 on: February 03, 2004, 12:14:59 PM »
Will have to look into that one ....
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
LayerStates
« Reply #2 on: February 03, 2004, 12:23:24 PM »
Let's see if I can add to it. By adding a pause to the export so I can manually type the name in, works, but when I go to the specified folder to import it later, it is a .las file as I stated before, but when it imports in, it has the originally given name:? That's odd.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
LayerStates
« Reply #3 on: February 03, 2004, 01:03:19 PM »
i messed with layerstates a bit. (It aint easy) --This was on 02 but-- i couldnt acess the layerstates as a group perse, i did however access the manager thru lisp. eventualy i gave up, cause it was getting a bit to mich for my taste.  I'll look for the code i did endup with, but most likely i left it on my former job's computer along with 90% of my code.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
LayerStates
« Reply #4 on: February 03, 2004, 01:31:48 PM »
Quote
most likely i left it on my former job's computer along with 90% of my code.

That sucks. Why didn't you take it with you?

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
LayerStates
« Reply #5 on: February 03, 2004, 02:00:43 PM »
Cause i didnt really care. (I thought i could just re-wite what i needed; ya know? )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
LayerStates
« Reply #6 on: February 03, 2004, 02:05:22 PM »
Daron, here is a small snipit of code i did find. (I aint got much more then this but) Give this a whirl with a saved layer state called "test"

(vla-export (vla-Getinterfaceobject (vlax-get-object "AutoCAD.Application") "AutoCAD.AcadLayerStateManager") "test" "c:\test.las")
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
LayerStates
« Reply #7 on: February 03, 2004, 03:13:57 PM »
Not sure what you are doing Daron,
but does this do anything for you?

Code: [Select]
;;
;; By R. ROBERT BELL
;;
(defun C:LayerFiltersDelete ()
 (vl-Load-Com)
 (vl-Catch-All-Apply '(lambda ()
                       (vla-Remove
                        (vla-GetExtensionDictionary
                         (vla-Get-Layers
                          (vla-Get-ActiveDocument
                           (vlax-Get-Acad-Object)))) "ACAD_LAYERFILTERS")))
 (princ "\nAll layer filters have been deleted.")
 (princ)
)
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
LayerStates
« Reply #8 on: February 03, 2004, 03:27:57 PM »
CAB, Daron is hunting Layerstates. (That code is for the Layerfilters. )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
LayerStates
« Reply #9 on: February 03, 2004, 03:29:51 PM »
No, I don't want to delete filters. Are you familiar with the eNotThatKindofClass thread I started in General Autocad? Well, that works with some tweaking. First, it needs to select all graphical objects on the drawing, not the entire database. The problem is in the database. I'd love to be able to delete the dictionary, but this is starting to work. Anyway, the other problem is this: xref'ed objects don't retain their previous layer settings when they've been wblock'ed, so, the trick is to save and export the layer states before wblocking, wblock the drawing objects and drawing to itself, close the drawing without saving and reopen the drawing. Then I need to import the previously saved state. Does that help?

Nice code though. That Robert Bell, he's a nice guy. If you ever get the chance to meet him, take it. Se7en's code is closest yet, but I can't get it working.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
LayerStates
« Reply #10 on: February 03, 2004, 03:43:40 PM »
Daron i just noticed something. (I am using 2000 right now and there isnt a layer state mgr in that version --besides in the express tools-- but give this line a try and see if it returns something.

(vla-Getinterfaceobject (vlax-get-object "AutoCAD.Application") "AcadLayerStateManager")
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
LayerStates
« Reply #11 on: February 03, 2004, 03:50:47 PM »
No return, but this returns:
(vla-Getinterfaceobject (vlax-get-object "AutoCAD.Application") "AutoCAD.AcadLayerStateManager.16")
Your first one with a .16 at the end. From that it's the export that's messed up. I get Automatin Error. Not initialized yet.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
LayerStates
« Reply #12 on: February 03, 2004, 04:01:40 PM »
Don't mean to but it, but her is some more info.
I'll have to do some homework as i I don't understand it.


Code: [Select]
; Setup some pointers
(setq app (vlax-get-acad-object)
      doc (vla-get-activedocument app); this can be replaced with an
axdbdocument pointer
      lobj(vla-GetExtensionDictionary(vla-get-layers doc)))

; Now lets be safe because there may not be any layerstates
(setq lstdict (vl-catch-all-apply
      'vla-item(list lobj "ACAD_LAYERSTATES")))

(if (vl-catch-all-error-p lstdict)
  (princ "\nThere are no saved Layer States!")
; Now iterate through the dictionary collection
; and collect the layerstate names
(vlax-for l lstdict
  (setq lstates(append lstates (list(vla-get-name l))))))


; Return the list of names
lstates



;;;/////////////////////////////////////////////
;;;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

(vl-load-com)

(defun get-acadobject  ()
  (setq *acad*
  (cond
    (*acad*)
    ((vlax-get-acadobject))
    (T nil))))

(defun get-activedocument  ()
  (setq *doc*
  (cond
    (*doc*)
    ((vla-get-activedocument (get-acadobject)))
    (T nil))))

(defun delete-layerstate  (obj name)
  (if (vl-catch-all-error-p
 (vl-catch-all-apply
   'vla-delete
   (list obj name)))
    nil
    T))

(defun save-layerstate (obj name mask)
  (if (vl-catch-all-error-p
 (vl-catch-all-apply
   'vla-save
   (list obj name mask)))
    nil
    T))

(defun set-layerstate  (name mask)
  (setq state
  (vlax-create-object
    "AutoCAD.AcadLayerStateManager"))
  (vla-setdatabase
    state
    (vla-get-database (get-activedocument)))
  (delete-layerstate state name)
  (save-layerstate
    state
    name
    ;; acLsAll
    mask))

(defun get-statenames  (/ collection names)
  (if (not
 (vl-catch-all-error-p
   (setq collection
   (vl-catch-all-apply
     (function (lambda ()
          (vla-item (vla-getextensiondictionary
        (vla-get-layers
          (vla-get-activedocument
            (vlax-get-acadobject))))
      "ACAD_LAYERSTATES")))))))
    (vlax-for item  collection
      (setq names (cons (strcase (vla-get-name item)) names)))))

(defun restore-layerstate  (name)
  (if (and state
    (vl-position
      (strcase name)
      (get-statenames)))
    (progn (vla-restore state name)
    (delete-layerstate state name)
    (vlax-release-object state)
    (setq state nil))))
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.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
LayerStates
« Reply #13 on: February 18, 2004, 07:56:00 PM »
Half the credit goes to Se7en.
Code: [Select]

;;; return the LayerStateManager object ready to use
;;; tested on 2004
;;; for earlier versions change the '16' below to '15'
(defun return-lsm (/ db lsm)
  (vl-load-com)
  (setq db (vlax-get-property
             (vla-get-activedocument (vlax-get-acad-object))
             'Database
             )
        )
  (setq lsm
     (vl-catch-all-apply
        'vla-Getinterfaceobject
          (list (vlax-get-object "AutoCAD.Application")
             "AutoCAD.AcadLayerStateManager.16");< or 15
           )
        )
  (if (not (vl-catch-all-error-p lsm))
    (progn (vla-SetDatabase lsm db) lsm)
    )
  )

; Methods supported:
;   Delete (1)
;   Export (2)
;   Import (1)
;   Rename (2)
;   Restore (1)
;   Save (2)
;   SetDatabase (1)

; now do some testing
; save the current state
(if (setq lsm (return-lsm))
  (vlax-invoke-method lsm 'Save "new-state" acLsAll)
  )

; export it
(if lsm
  (vlax-invoke-method lsm 'Export "new-state" "c:/new-state.las")
  )

; change your layers so we can restore them
(if lsm
  (vlax-invoke-method lsm 'Restore "new-state")
  )

(vlax-release-object lsm)
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
LayerStates
« Reply #14 on: February 19, 2004, 12:14:48 AM »
Thanks. I'll have to look at that soon.