OK, Acad LayerStates instead

Discussion in 'AutoCAD' started by Gordon Price, Mar 5, 2005.

  1. Gordon Price

    Gordon Price Guest

    So, I have pretty much given up on using the archT functions, and gone on to
    using Acad LayerStates, but I am having trouble there too.

    The code below SHOULD load the given LAS file, then restore the appropriate
    LayerState.
    (command "-Layer" "stAte" "Import" "P:/_Standards/LayerStates/XREF_FLR.las"
    "Restore" "XREF_FLR" "" "" "" "")

    Hoever, at the Import step, I get this error:
    Command: (command "-Layer" "stAte" "Import"
    "P:/_Standards/LayerStates/XREF_FLR.las")
    Could not import layer states from file provided.

    Because sometimes the LayerState is already loaded. Now, I could try to
    delete the LayerState each time I use it, and as long as nobody loads it
    manually I am somewhat OK, but is there a better way. Perhaps a way to
    search for the layerState in a dictionary, and delelte only if present, then
    proceed to load?

    Any help is greatly appreciated.

    Gordon
     
    Gordon Price, Mar 5, 2005
    #1
  2. Gordon Price

    Jeff Mishler Guest

    Look at the "LayerStateManager" Object in the ActiveX and VBA developer
    reference, it should give you an idea of how to work around this.
     
    Jeff Mishler, Mar 5, 2005
    #2
  3. Gordon Price

    Tom Smith Guest

    Gordon, I use the same approach, and delete the layer state before importing it. Never had a problem with that. The only kink is that you have to feed an extra return to the delete option if the state wasn't found. The cmdactive trick works there. Oh, and you have to make sure all your standard linetypes are present too, or the imported layers will default to continuous if their ltype is missing.
     
    Tom Smith, Mar 5, 2005
    #3
  4. Gordon Price

    Tom Smith Guest

    Utility functions loaded on startup. I call the loadlayers function from a toolbar button. The layer state is "tbinc."

    (defun loadltypes ()
    (setvar "filedia" 0)
    (foreach n '("center" "dashed" "hidden" "phantom")
    (if (null (tblsearch "ltype" n))
    (command "-linetype" "load" n "acad.lin" "")))
    (setvar "filedia" 1)
    (princ))

    (defun wipelstate ()
    (command "-layer" "state" "delete" "tbinc" "" "")
    (if (zerop (getvar "cmdactive"))
    (princ)
    (command "")) ;extra return if lstate not found
    (princ))

    (defun loadlayers ()
    (loadltypes)
    (wipelstate)
    (command "-layer" "state" "import" "tbinc.las" "restore" "tbinc" "" "")
    (princ))
     
    Tom Smith, Mar 5, 2005
    #4
  5. There are plenty of functions about this, do a google search...

    I have posted here in the past a full function module for this, like many others too....
     
    Luis Esquivel, Mar 7, 2005
    #5
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.