Optimization needed...

Discussion in 'AutoCAD' started by MNafo, May 7, 2004.

  1. MNafo

    MNafo Guest

    This routine ask for an entity in the drawing. If this entity intersect other entities, and those intersect again and so on...
    the program perform same operation on the entire group
    We pick one and manipulate many!!!
    But... the program is very slow on huge drawings: for example, it takes 2 minutes for a drawing with 2425 entities.
    If somebody could increase performance...
     
    MNafo, May 7, 2004
    #1
  2. MNafo

    bcoward Guest

    MNafo,

    Your not writing solid code. Have you thought of filtering instead of comparisons?

    Take note of the following statement, when you achieve the following your code will be faster, better, and able to leap small entities in a single bound.

    Use GoTo for function and procedure cleanup after error conditions. See if you can restructure your code differently (no...do restructure your code differently). As a general rule, your code should flow from top to bottom.

    Best of luck,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, May 7, 2004
    #2
  3. Well, duh! You're iterating EVERY object in model space:
    If you are looking for intersections, use a selection set. The selection
    set should be created using the SelectCrossing option with the points
    coming from the object's BoundingBox.
     
    Mike Tuersley, May 7, 2004
    #3
  4. MNafo

    MNafo Guest

    "Well, duh! You're iterating EVERY object in model space:"
    It's just the first shoot :)
    "If you are looking for intersections"...
    Points from object's BoundingBox must be visible on screen, isn't it (otherwise the method does not return correct results - I'll check again, anyway)? If so, this can be a problem.
     
    MNafo, May 10, 2004
    #4
  5. MNafo

    MNafo Guest

    I reply with changes according with your solutions (I guess...):
    Modified: 1. Selectionset based.
    2. Changed the operation for confirmation of the results (instead of rotating, I choose moving).
    3. Removed only one of those two Goto's. Still no solutions founded for the second.
    Disadvantage: Founded objects must lie inside visible screen area. Everything is outside, is not selected. Is something I do wrong?
    Advantages: very, very good speed (between 1 an 2 second on huge drawings).
     
    MNafo, May 10, 2004
    #5
  6. Founded objects must lie inside visible screen area. Everything is
    outside, is not selected. Is something I do wrong?

    No, you're not doing anything wrong. That is just how ACAD's selection
    methods work, unfortunately. You could use something similar to the
    following (very) rough code to make sure all your objects are visible before
    you use the selection set. You could also just zoomExtents, but if you have
    objects that are too small I think they can be missed if you're zoomed too
    far out.
    HTH,
    James


    'View...zoom...1x before to be sure view is saved in Zoom Prev buffer
    ZoomScaled 1, acZoomScaledRelativePSpace 'assumes you're in paper space

    'call boundingBoxOfSelectedEntities (yourSelectionSet, x1, y1, x2, y2)
    'pt1 = array (x1, y1, 0)
    'pt2 = array (x2, y2, 0)
    'zooomwindow pt1, pt2

    ' Restore original view
    ZoomPrevious



    Sub boundingBoxOfSelectedEntities(ss1 As AcadSelectionSet, MinX As Double,
    MinY As Double, MaxX As Double, MaxY As Double)
    ' This sub returns an overall bounding box of entities selected on screen.

    Dim lBox, uBox As Variant
    Dim x1, y1, x2, y2 As Double
    Dim i As Long

    ' Add a selection set, if it already exists, set it to be active
    On Error Resume Next
    Set ss1 = ThisDrawing.SelectionSets.Add("tifDSet")
    If Err Then
    Set ss1 = ThisDrawing.SelectionSets("tifDSet")
    End If
    On Error GoTo 0
    ss1.Clear

    ' Add entities to a selection set by prompting user to select on the
    screen
    ss1.SelectOnScreen

    ' Get the bounding box of the first item in the selection set (if Sel Set
    is not empty)
    If ss1.Count > 0 Then
    ss1(0).GetBoundingBox lBox, uBox
    MinX = lBox(0)
    MinY = lBox(1)
    MaxX = uBox(0)
    MaxY = uBox(1)
    End If

    ' Iterate through the objects in the selection set
    ' (first one has already been done so start at one)
    For i = 1 To ss1.Count - 1
    ' Get the bounding box of the current object
    ss1(i).GetBoundingBox lBox, uBox

    ' Get the Lower (x, y) of the bounding box of the entity
    x1 = lBox(0)
    y1 = lBox(1)

    ' Get the Upper (x, y) of the bounding box of the entity
    x2 = uBox(0)
    y2 = uBox(1)

    ' grow the group's bounding box to include the object's
    If x1 < MinX Then MinX = x1
    If y1 < MinY Then MinY = y1
    If x2 > MaxX Then MaxX = x2
    If y2 > MaxY Then MaxY = y2
    Next 'i

    End Sub 'boundingBoxOfSelectedEntities
     
    James Belshan, May 10, 2004
    #6
  7. MNafo

    Tim Arheit Guest

    I don't think so. Select by crossing line has always worked this way.
    It's rather strange when picking manually and you pan during the
    selection. In these cases I've simply had the program do a zoom
    extents before doing it's thing then zoom previous after.

    -Tim
     
    Tim Arheit, May 10, 2004
    #7
  8. MNafo

    MNafo Guest

    Good idea - I am not implement this (yet) but I think that everytime the selection set is growing, a "zoom" and a "regen" must be performed, so I think that speed will decrease substantially, because (sometimes??) a lot of objects could be "connected".
     
    MNafo, May 11, 2004
    #8
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.