Check for a layerstate name

Discussion in 'AutoCAD' started by Allen Johnson, Jan 12, 2004.

  1. How can you check to see if a layerstate name exists?
     
    Allen Johnson, Jan 12, 2004
    #1
  2. Allen Johnson

    Jeff Mishler Guest

    This is one way:

    (defun chk_4_laystate (name / DICTS FOUND LAYS STATES)
    (setq lays (vla-get-layers
    (vla-get-activedocument
    (vlax-get-acad-object))))
    (if (vla-get-HasExtensionDictionary lays)
    (progn
    (setq dicts (vla-getextensiondictionary lays))
    (vlax-for x dicts
    (if (= (vla-get-name x) "ACAD_LAYERSTATES")
    (setq states x)
    )
    )
    (if states
    (progn
    (vlax-for x states
    (if (= (vla-get-name x) name)
    (setq found t)
    )
    )
    )
    )
    )
    );if
    (if found
    (princ (strcat "Layerstate " name " exists in drawing."))
    (princ (strcat "Layerstate " name " not found."))
    )
    (princ)
    )

    HTH,
    Jeff
     
    Jeff Mishler, Jan 12, 2004
    #2
  3. thanks.
     
    Allen Johnson, Jan 12, 2004
    #3
  4. Here is another way (limited testing)

    ; Jason Piercey . January 12th, 2004
    ; function to determine if a layerstate exists
    ; Arguments:
    ; [document] - vla-object, document object
    ; [layerstate] - string, layerstate name
    ; return: xrecord object if successful
    ; example:
    ; (layerstate-p (vla-get-activedocument (vlax-get-acad-object)) "test")
    (defun layerstate-p (document layerstate / res)
    (if
    (vl-catch-all-error-p
    (setq
    res
    (vl-catch-all-apply
    '(lambda ()
    (vla-item
    (vla-item
    (vla-getextensiondictionary
    (vla-get-layers document))
    "Acad_Layerstates"
    )
    layerstate
    )
    )
    )
    )
    )
    (vl-catch-all-error-message res)
    res
    )
    )
     
    Jason Piercey, Jan 12, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.