ent vs selectionSet

Discussion in 'AutoCAD' started by John Coon, Sep 19, 2004.

  1. John Coon

    John Coon Guest

    What operation ent vs selection filters is better or does it matter.
    I've seen a few online vba demo's and they seem to clearly like the
    ThisDrawing.Utility.GetEntity ent, pt, "Pick or whatever: " iterate thru
    the drawing.
    My question is what is better or faster. They seem to think that ent is fast
    enough for even robust operations.

    Thank you.
    John Coon

    I normally use this method
    Dim setOBJ As AcadSelectionSet
    Dim ftype(0) As Integer
    Dim fdata(0) As Variant
    Dim f_type As Variant
    Dim f_data As Variant
    Dim i As Integer
    Dim pt As Variant
    ftype(0) = 0
    fdata(0) = "INSERT"
    f_type = ftype
    f_data = fdata
    Set setOBJ = ThisDrawing.SelectionSets.Add("TEST2")
    setOBJ.SelectOnScreen
    and sometimes use a dataValue(1) = BLOCKNAME filter

    I tried below but can't seem to get it to create points on anything but the
    first ent. but it does put points on the selected
    block but for all enitities in the drawing. how do I get the count for the
    selected ent and filter by name. I can change to it to mtext label for those
    without land. I guess I'm looking to select one block and have it iterate
    thru the drawing get the insertion point and label all of the ent.name

    With ent how do you fileter for a selected block onscreen or by name?

    Public Sub pickblock()
    Dim dbPref As AeccDatabasePreferences
    Set dbPref = AeccApplication.ActiveDocument.Preferences
    Dim cogoPnts As AeccCogoPoints
    Dim setCogoPnt As AeccCogoPoint
    Set cogoPnts = AeccApplication.ActiveProject.CogoPoints
    Dim ent As AcadEntity
    Dim count As Integer

    Dim name As String
    ThisDrawing.Utility.GetEntity ent, pt, "Pick Block: "
    pt = ent.InsertionPoint
    name = ent.name

    For Each Entity In ThisDrawing.ModelSpace
    If TypeOf ent Is AcadBlockReference Then
    'why doesn't this count the number of blocks under enitity picked name
    If ent.name = name Then count = count + 1
    End If

    Set setCogoPnt = cogoPnts.Add(pt, kCoordinateFormatXYZ)

    Next

    End Sub
     
    John Coon, Sep 19, 2004
    #1
  2. You wouldn't use GetEntity to iterate thru the database.

    If you place the statement:

    Option Explicit

    .... at the beginning of your sample code, I think you will see what is wrong
    with your code.

    P.S. You really should set the VBAIDE option "Require Variable Declaration",
    which places Option Explicit in new modules, to help you avoid coding errors
    related to variables.

    --
    R. Robert Bell


    What operation ent vs selection filters is better or does it matter.
    I've seen a few online vba demo's and they seem to clearly like the
    ThisDrawing.Utility.GetEntity ent, pt, "Pick or whatever: " iterate thru
    the drawing.
    My question is what is better or faster. They seem to think that ent is fast
    enough for even robust operations.

    Thank you.
    John Coon

    I normally use this method
    Dim setOBJ As AcadSelectionSet
    Dim ftype(0) As Integer
    Dim fdata(0) As Variant
    Dim f_type As Variant
    Dim f_data As Variant
    Dim i As Integer
    Dim pt As Variant
    ftype(0) = 0
    fdata(0) = "INSERT"
    f_type = ftype
    f_data = fdata
    Set setOBJ = ThisDrawing.SelectionSets.Add("TEST2")
    setOBJ.SelectOnScreen
    and sometimes use a dataValue(1) = BLOCKNAME filter

    I tried below but can't seem to get it to create points on anything but the
    first ent. but it does put points on the selected
    block but for all enitities in the drawing. how do I get the count for the
    selected ent and filter by name. I can change to it to mtext label for those
    without land. I guess I'm looking to select one block and have it iterate
    thru the drawing get the insertion point and label all of the ent.name

    With ent how do you fileter for a selected block onscreen or by name?

    Public Sub pickblock()
    Dim dbPref As AeccDatabasePreferences
    Set dbPref = AeccApplication.ActiveDocument.Preferences
    Dim cogoPnts As AeccCogoPoints
    Dim setCogoPnt As AeccCogoPoint
    Set cogoPnts = AeccApplication.ActiveProject.CogoPoints
    Dim ent As AcadEntity
    Dim count As Integer

    Dim name As String
    ThisDrawing.Utility.GetEntity ent, pt, "Pick Block: "
    pt = ent.InsertionPoint
    name = ent.name

    For Each Entity In ThisDrawing.ModelSpace
    If TypeOf ent Is AcadBlockReference Then
    'why doesn't this count the number of blocks under enitity picked name
    If ent.name = name Then count = count + 1
    End If

    Set setCogoPnt = cogoPnts.Add(pt, kCoordinateFormatXYZ)

    Next

    End Sub
     
    R. Robert Bell, Sep 20, 2004
    #2
  3. John Coon

    john coon Guest

    Robert,

    Thanks, I see what you are talking about now.
    John Coon
     
    john coon, Sep 20, 2004
    #3
  4. Glad I could help.

    --
    R. Robert Bell


    Robert,

    Thanks, I see what you are talking about now.
     
    R. Robert Bell, Sep 20, 2004
    #4
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.