Print layer's name

Discussion in 'AutoCAD' started by A-Design, Apr 8, 2005.

  1. A-Design

    A-Design Guest

    Hi,

    Is it possible to write a code to print all layer's names.

    Thanks,
    A.K.
     
    A-Design, Apr 8, 2005
    #1
  2. A-Design

    Joe Sutphin Guest

    Are you referring to print as in "to a printer" or to display as in a
    messagebox?

    Joe
     
    Joe Sutphin, Apr 8, 2005
    #2
  3. A-Design

    A-Design Guest

    It was much better if I could first see them in a msgbox then send the
    contents of that msgbox to the printer.
    Thanks.
     
    A-Design, Apr 8, 2005
    #3
  4. A-Design

    Joe Sutphin Guest

    Here is the quick and dirty way.

    Public Sub ListLayers()
    Dim oLayer As AcadLayer

    For Each oLayer In ThisDrawing.Layers
    Debug.Print oLayer.Name
    Next oLayer

    End Sub

    Then highlight everything in the immediate window [Ctrl-A].

    C/P it to Notepad and print it.

    If you need a more substantial and permanently method then let me know.

    Joe
     
    Joe Sutphin, Apr 8, 2005
    #4
  5. A-Design

    Oberer Guest

    If you want the layer names sorted, you'll need to add them to an array or collection & process accordingly.
    Alternatively, you could always import this text file into excel and do a quick sort there...
    Code:
    Sub listem_V2()
    Dim oLYR As AcadLayer
    Dim strTemp As String
    Dim strFullFileName As String
    
    'output filename & path
    ' must make sure any directory(s) you specify here exist already
    strFullFileName = "g:\MyNewTest.TXT"
    
    strTemp = strTemp & "Begin Layer Listing" & vbNewLine
    
    'ThisDrawing.Utility.Prompt "Begin Layer Listing"
    'AcadApplication.Update
    
    For Each oLYR In ThisDrawing.Layers
    'Debug.Print oLYR.Name
    'ThisDrawing.Utility.Prompt oLYR.Name
    'AcadApplication.Update
    strTemp = strTemp & oLYR.Name & vbNewLine
    Next
    
    'output to file
    WriteStringToFile strFullFileName, strTemp
    ' view in notepad
    SendFileToNotePad strFullFileName
    End Sub
    
    Sub WriteStringToFile(pFileName As String, pString As String)
    Dim intFileNum As Integer
    
    intFileNum = FreeFile
    Open pFileName For Output As intFileNum
    Print #intFileNum, pString
    Close intFileNum
    End Sub
    
    
    Sub SendFileToNotePad(pFileName As String)
    Dim lngReturn As Long
    lngReturn = Shell("NOTEPAD.EXE " & pFileName, vbNormalFocus)
    End Sub
    
     
    Oberer, Apr 8, 2005
    #5
  6. A-Design

    A-Design Guest

    Thank you Obere this is very nice.
     
    A-Design, Apr 8, 2005
    #6
  7. A-Design

    A-Design Guest

    Thanks Joe.

     
    A-Design, Apr 8, 2005
    #7
  8. A-Design

    A-Design Guest

    Oberer,

    Can I also have information like COLOR,ON and OFF ,FREEZE & Etc. of each
    layer on that list ?

    Thanks
    A.K.
     
    A-Design, Apr 8, 2005
    #8
  9. A-Design

    Matt W Guest

    Change this line: strTemp = strTemp & oLYR.Name & vbNewLine
    to this line: strTemp = strTemp & oLYR.Name & "," & oLYR.Color & "," &
    oLYR.Linetype & "," & oLYR.Freeze & "," & oLYR.LayerOn & vbNewLine

    This will create a comma delimited file with layer name, color, linetype,
    freeze state (expressed as boolean), on/off state (expressed as boolean)

    --
    I support two teams: The Red Sox and whoever beats the Yankees.

     
    Matt W, Apr 8, 2005
    #9
  10. A-Design

    Matt W Guest

    That is slick!
    Man could I have used that many-a-time in the past!

    --
    I support two teams: The Red Sox and whoever beats the Yankees.

     
    Matt W, Apr 8, 2005
    #10
  11. A-Design

    Oberer Guest

    It's folks like you Joe who keep me coming back. There's SO much to learn.
    Very nice utliity.

    One request?
    How would i had the word app until it's finished formatting?
    I'm working with acad 2k2 and ld3 on xp sp 2, p4 3.6, 2 gigs of ram and the table formatting was kinda slow. I didn't realize it wasn't finished until i get a few more hourglasses...
     
    Oberer, Apr 8, 2005
    #11
  12. A-Design

    A-Design Guest

    Thank you all very much.



     
    A-Design, Apr 8, 2005
    #12
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.