Create a layer by referencing text in excel?

Discussion in 'AutoCAD' started by TERRY.D, Dec 28, 2003.

  1. TERRY.D

    TERRY.D Guest

    Can anyone help please:

    I'm trying to create several new layers in my drawing, the names of which are text in a column of an excel spread sheet.

    I can reference cells in excel which have a numerical value, using coding eg, rotatepoint(0) =cells (23, 3).value.

    I can also create new layers using vba (without referencing excel cells).

    However, what I can't do is create new layers by referencing text in an excel column. I have an excel spreadsheet where cell (23,1) has the text pipe1, (24,1) has pipe2, (25,1) has pipe3 etc, etc.

    I've created several pipes (cylinders) and I want each one to be on an individual layer. In conjunction with a for-to loop where c is the counter, I'm using the coding:

    set dwg=acad.activedocument

    dwg.layers.add =("cells(c+23,1).value")

    but this doesn't work. Any help much appreciated.

    Terry
     
    TERRY.D, Dec 28, 2003
    #1
  2. TERRY.D

    Jeff Mishler Guest

    Did you try this?

    dwg.layers.add = cells(c+23,1).value

    Jeff

    are text in a column of an excel spread sheet.
    eg, rotatepoint(0) =cells (23, 3).value.
    excel column. I have an excel spreadsheet where cell (23,1) has the text
    pipe1, (24,1) has pipe2, (25,1) has pipe3 etc, etc.
    individual layer. In conjunction with a for-to loop where c is the counter,
    I'm using the coding:
     
    Jeff Mishler, Dec 28, 2003
    #2
  3. TERRY.D

    TERRY.D Guest

    Thanks Jeff, I did try your code, but the autocad drg just shows up blank? When I don't include the add layers line, the pipes show up.??
     
    TERRY.D, Dec 29, 2003
    #3
  4. TERRY.D

    Norman Yuan Guest

    Didn't you get "compile error" on such a syntex: dwg.Layers.Add="xxxx"?

    It should be

    Call dwg.Layers.Add("LayerName")

    or

    dwg.Layers.Add "LayerName"

    No "=" following "Add".

    are text in a column of an excel spread sheet.
    eg, rotatepoint(0) =cells (23, 3).value.
    excel column. I have an excel spreadsheet where cell (23,1) has the text
    pipe1, (24,1) has pipe2, (25,1) has pipe3 etc, etc.
    individual layer. In conjunction with a for-to loop where c is the counter,
    I'm using the coding:
     
    Norman Yuan, Dec 29, 2003
    #4
  5. Hi Norman,

    I've been writing VBA code in AutoCAD for the last several years and am yet
    to use the word "Call" in my code. There may be some obscure feature which
    requires it, but in general it is obviously not needed.

    I would use code such as:
    Sub CreateLayers()
    Dim ssLayers As AcadLayers
    Dim oLayer As AcadLayer

    Set ssLayers = ThisDrawing.Layers
    With ssLayers
    Set oLayer = .Add (ValueFromTheRelevantExcelCell)
    With oLayer
    .Color = ValueFromTheRelevantExcelCell
    .Linetype = ValueFromTheRelevantExcelCell
    etc
    End With
    End With
    End Sub




    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Dec 29, 2003
    #5
  6. Hi Terry,

    If you read the value from the cell, you don't need to distinguish if it is
    text or a number, the program will create a layer with the name of the
    characters in the cell. Try the code below if you are unsure of this

    Sub fred()
    ThisDrawing.Layers.Add 1234567
    ThisDrawing.Layers.Add "2345678"
    End Sub

    I assumed you had code to read the Excel cells and hence this is why I
    simply used a descriptor "ValueFromTheRelevantExcelCell" for that data.

    If you don't have code to read the Excel cells, then look at the samples
    files supplied with the Software for ExcelLink.dvd and work from there.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    the others in relating to the line:
    name them pipe1, pipe2, etc in the vba programming. i.e. it doesn't actually
    reference the cells in excel by their unique row and column identity,
    therefore defeating the purpose of what I am trying to achieve. I don't
    want to write out the name of each layer in my program, but rather reference
    the excel cell in which the layer name resides.
    something that made vba realise that an excel cell was either a number or
    some text string, and the vba code still used the:
    when I'm creating and rotating the pipes, therefore why can't I simply do
    the same to create a layer. As I mentioned in an earlier email, I can also
    create layers in vba where I am not referencing any excel cell.
    of: cells(c+23,1).value combined with: dwg.Layers.Add "LayerName".
    look forward to email reply number 6.
     
    Laurie Comerford, Jan 7, 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.