Count items in paper space

Discussion in 'AutoCAD' started by Chris Kelly, Oct 14, 2004.

  1. Chris Kelly

    Chris Kelly Guest

    Hi there,
    I am pretty used to working with autolisp and VBA but now and then I
    hit on a problem that keeps me up all night like in this case (this
    and another problem with getentity which I'll post separately). I have
    trawled through google groups for hours and I was really surprised
    that it has not come up before. What I am trying to do I really
    thought would be a simple process. I just want to count all the
    entities in paper space on a particular layer e.g. layer "0". Its very
    easy to do for model space (I've posted the code below). I've had a
    look through some old lisp routines I have and back then I managed to
    do it by switching to each viewport as I needed. But this seems like a
    very slow way to do it and would not suit what I'm doing at all. I
    would like to query AutoCAD and get the total number of ents in
    modelspace and the total in paperspace and then print the 2 on a form.
    This way I can decide whether or not to rename a layer depending on if
    it is being used in both paperspace and modelspace. Does anyone know
    how I can count items in all paperspace layouts at the same time. I've
    posted what I've got so far below. It's one of those situations where
    everything else is working and in 5 minutes more I was hoping to have
    it exactly the way I wanted but through my own stubborness I stayed up
    all night and I won't stop until I get it.
    Please help someone I'd really appreciate it.

    Function CountModelEntitiesOnLayer(layername As String) As Long
    On Error Resume Next
    Dim ent As AcadEntity
    Dim lay As AcadLayer
    Dim ii As Long

    ii = 0

    For Each ent In ThisDrawing.ModelSpace
    lay = ent.Layer
    If lay.Name = layername Then
    ii = ii + 1
    End If
    Next

    CountModelEntitiesOnLayer = ii
    End Function

    Function CountPaperspaceEntitiesOnLayer(layername As String) As Long
    'On Error Resume Next
    Dim ent as acadentity
    Dim lay As AcadLayer
    Dim ii As Long
    Dim jj As Long
    Dim alay As AcadLayout

    jj = 0

    For ii = 0 To ThisDrawing.PaperSpace.Count - 1
    For Each item In ThisDrawing.PaperSpace(ii)
    lay = ent.Layer
    Debug.Print ent.ObjectName
    jj = jj + 1
    Next
    Next

    CountPaperspaceEntitiesOnLayer = jj
    End Function
     
    Chris Kelly, Oct 14, 2004
    #1
  2. Chris Kelly

    Chris Kelly Guest

    Figured it out (no error checking here):

    Public Function paperspacecount(layname)
    Dim paSpace As AcadPaperSpace
    Dim obj As AcadEntity
    Dim count As Long
    Dim index As Long

    count = 0

    For index = 0 To paSpace.count - 1
    If paSpace.Item(index).Layer = layname Then
    count = count + 1
    End If
    Next index

    paperspacecount = count

    End Function
     
    Chris Kelly, Oct 25, 2004
    #2
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.