"Loop all Solids"?

Discussion in 'AutoCAD' started by MarkusV, Apr 29, 2004.

  1. MarkusV

    MarkusV Guest

    HI!

    I'm new to VBA in AutoCad but can someone help me with looping all Acad3DSolids in my drawing...

    I don't understand why this doesn't work:

    Dim s As Acad3DSolid
    For Each s In ThisDrawing.ModelSpace
    MsgBox s.ObjectName
    Next

    If I change the s variabel to:
    Dim s As AcadObject

    and uses the same for each statement it works fine. The problem with using AcadObject is that it will go through ALL objects in the drawing, which will take to much time when there is many objects in the drawing. I just want to have the solids, can someone help me with this?

    Thanx!
     
    MarkusV, Apr 29, 2004
    #1
  2. MarkusV

    Luis Alberto Guest

    Perhaps you could try by using a selectionset and selecting the solids with
    ".select" method

    object.Select Mode[, Point1][, Point2][, FilterType][, FilterData]

    I do not know the values to do it, but FilterType should by the falue for
    "type of entity" and the FilterData the name of the Acad3dSolids.

    If this works you will have the entities you want in an selectionset, ready
    for futher operations.

    Hope this helps.

    AcadObject is that it will go through ALL objects in the drawing, which will
    take to much time when there is many objects in the drawing. I just want to
    have the solids, can someone help me with this?
     
    Luis Alberto, Apr 29, 2004
    #2
  3. MarkusV

    Perion Guest

    The only way I know to access a particular set of objects is to either walk
    through the whole collection storing references to the ones you want or, like
    stated by a previous post, try to create a filtered selection set - something
    like:

    Dim ss3DSolids As AcadSelectionSet

    Set ss3DSolids = ThisDrawing.SelectionSets.Add("My3DSolids")

    ss3DSolids.Select acSelectionSetAll, FilterType:= 0, FilterData:="3DSOLID"

    Then you can access each solid object in the selection set by something like
    this:
    Dim obj3DSolid as AcadObject
    For Each obj3DSolid In ss3DSolids

    'Do whatever you want using obj3DSolid's properties and methods

    Next obj3DSolid

    See http://www.vbdesign.net/activecad/how_to/selsets.html for good info on using
    SelectionSets

    Perion
    [I don't gaurantee anything I say or do is even close to being right]
     
    Perion, Apr 29, 2004
    #3
  4. MarkusV

    Ken Hutson Guest

    It would work if EVERY object in the drawing were an Acad3DSolid. During
    execution of the For .. Each block, it may encounter any object type. VBA
    will perform type checking on variable assignment. You get a type mismatch
    every time the loop encounters an object which is not Acad3DSolid.

    I for one have never noticed any performance penalties when iterating over
    an entire drawing database. Then again, I haven't tried any filtered
    selection methods either and therefore have no frame of reference.

    Cheers,
    Ken Hutson
    San Antonio, TX
     
    Ken Hutson, Apr 29, 2004
    #4
  5. MarkusV

    Perion Guest

    Someone pointed out to me the following: You probably should supply dummy
    variables to the two Pont arguments in the Select filter and the two filter args
    should be elements of an array - (Im not sure I agree with them on that, but
    whatever...).

    The Select method is defined as:
    object.Select Mode[, Point1][, Point2][, FilterType][, FilterData]

    So, instead of:

    ss3DSolids.Select acSelectionSetAll, FilterType:= 0, FilterData:="3DSOLID"

    They think the correct code should probably be:

    Dim filterType(0) As Integer
    Dim filterData(0) As Variant
    Dim dummy as Variant

    filterTypes(0) = 0
    filterData(0) = "3DSOLID"

    ss3DSolids.Select acSelectionSetAll, dummy, dummy, filterType, filterData

    I should try all this but I keep getting interupted with having "work" :-0

    Perion
     
    Perion, Apr 29, 2004
    #5
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.
Similar Threads
There are no similar threads yet.
Loading...