Adding Layer

Discussion in 'AutoCAD' started by tsigwing, Sep 9, 2004.

  1. tsigwing

    tsigwing Guest

    How do I check to see if a layer exists in the layer table, and if not add it.
     
    tsigwing, Sep 9, 2004
    #1
  2. Why bother? The Add method _doesn't_ cause an error if the Layer object
    already exists.

    --
    R. Robert Bell


    How do I check to see if a layer exists in the layer table, and if not add
    it.
     
    R. Robert Bell, Sep 9, 2004
    #2
  3. tsigwing

    Jeff Mishler Guest

    You know, I almost answered with a nearly identical response. In most of my
    own code I used to use the Add method and be done with it.

    However, it has been suggested that that is a bad habit to get into, since
    most other collections will puke on the Add method if the item already
    exists. So I have been forcing myself to ALWAYS allow for an error being
    raised by the Add method, even when I know it won't. Who knows, maybe Adesk
    will "fix" the layers collection to act like all other collections in the
    future.

    Just my casual coder $0.01....
     
    Jeff Mishler, Sep 9, 2004
    #3
  4. In two years we'll all be coding in C# and forget about all this anyway,
    right?! ;^)

    --
    R. Robert Bell


    You know, I almost answered with a nearly identical response. In most of my
    own code I used to use the Add method and be done with it.

    However, it has been suggested that that is a bad habit to get into, since
    most other collections will puke on the Add method if the item already
    exists. So I have been forcing myself to ALWAYS allow for an error being
    raised by the Add method, even when I know it won't. Who knows, maybe Adesk
    will "fix" the layers collection to act like all other collections in the
    future.

    Just my casual coder $0.01....
     
    R. Robert Bell, Sep 9, 2004
    #4
  5. Do you really think it's going to take you that long to learn it?
     
    Tony Tanzillo, Sep 9, 2004
    #5
  6. No. But I was including the slugs.

    --
    R. Robert Bell


    Do you really think it's going to take you that long to learn it?
     
    R. Robert Bell, Sep 9, 2004
    #6
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.