Author Topic: I found this code here... Now I have some answers  (Read 1874 times)

0 Members and 1 Guest are viewing this topic.

sourdough

  • Bull Frog
  • Posts: 367
I found this code here... Now I have some answers
« on: June 01, 2005, 01:26:52 AM »
Please see my new Post 6-2-05 Found all my answers...
And produced a SaveTabLayoutSuite.lsp for ways to Save
Layerstates per tablayout name and with each switch recall
Layerstate per that tab along with a Reactor LayoutSwitch
that recalls Ltscale/Psltscale per Model / Paperspace you can
redefine. Take some of the mystery out of Layerstates, and
if that isn't enough. How would you like to Update Layer Properties
in Selected TabLayouts/Layerstate Saves. I need testers.


I found this code here... what I didn't get was how to use it.
What exactly do you have to do to get it to work. Just how would you write code to list layerstate name 'get-statenames' as an example. This
looks like code that could do alot... if I could only put this piece of the puzzle together.

Thanks in Advance.... and yes still learning...

(6-1-05)

I would like to use the latter code function of layerstate saves...
The first does a nice job of listing layerstates... would like to learn
how to use the other function in the latter code to do there
defun functions...


Mike in Alaska

I found this code and it works: List LayerStates

Code: [Select]

(defun c:ListLayerStates (/ nme lsList)

(princ"\n*** Layer State List ***")
(vlax-for x
(vla-item
(vla-GetExtensionDictionary
(vla-get-layers
(vlax-get-property
(vlax-get-acad-object)
'activedocument)
)
)
"ACAD_LAYERSTATES"
)
(princ(strcat "\n" (setq nme(vlax-get x 'name))))
(setq lsList (cons nme lsList))
)
(textscr)
(princ)
);end of defun


Just Got this to work.... Yeah 6-1-05 1:24pm
Save Layerstates but doesn't error trap is no layerstate..

Code: [Select]

(defun c:savelayerstate (
 / acad doc layman state
   )
   (vl-load-com)
   
   
   (setq *acad* (vlax-get-acad-object);get the application
         doc (vla-get-activedocument *acad*);get the current drawing
         LayMan (vla-getinterfaceobject *acad* "AutoCAD.AcadLayerStateManager.16");get the LStateManager
   )
   ;;; set database to the activedocument
   (if layman
    (progn
(setq state (getvar "ctab"))
  (vla-setdatabase layman (vla-get-database doc))
  (vla-delete layman state)
(vla-save layman state acLsAll)
    )
    )
(princ)
)


This one doesn't work... Help needed here

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))))
LDC 2009/C3D 2010/C3D 2011/C3D 2016

Win 10 64bit

Amsterdammed

  • Guest
I found this code here... Now I have some answers
« Reply #1 on: June 01, 2005, 07:54:45 AM »
Nice that you found a code, there are so many out there. But what are you searching for in the first place, what is the problem to be solved?

 :?: