Measure element lengths within fence using the overlap setting.

I have a lot of line elements drawn and I want to create a fence and measure the portion of lines that are enclosed by the fence.  I have my fence setting set to Overlap which successfully gets the contents of the fence but I don't know how to get lengths for only the parts of the lines that are within the fence.  Strictly speaking this appears to be possible by setting the fence to clip and then getting the contents but by doing that all my lines would then be clipped, and that's no good.  Perhaps I should clip the lines and then programmatically undo the clips immediately after collecting the lengths.  Is this possible?  Is this my best route or might there be another route I haven't considered?


  • After looking into it a bit more I'm really not sure how I would even programatically undo anything executed in VBA.  For now, the way I see it, my best option would be to do a "Save As" and let my fence clip the lines to get the lengths I'm interested in.  I hope this is not the best option.

  • You're right to be cautious about executing a destructive action, even if you can undo it. Here's an alternative …

    1. Create a new, empty, model
    2. Make the new model the active model
    3. Attach the model that contains your measurement candidates as a reference
      • At this point the user sees whatever was previously on screen
      • Ask the user to place a fence
    4. Enumerate the fence contents programmatically
    5. Add each element (i.e. a copy or clipped copy of the original) to the active model
    6. Do whatever you want to the active model
    7. Activate the original model
      • Discard (delete) the temporary model containing the clipped elements

    Regards, Jon Summers
    LA Solutions

    Regards, Jon Summers
    LA Solutions

  • Thanks for the help, Jon.  I had already gone down another path and figured out a way to do it without doing a "Save As" or attaching the file as a reference as you suggested.

    Here's what my sub basically ends up doing:

    1) Gets the highest element id

    2) Clones everything in the fence using

    dim oEnum as ElementEnumerator

    Set oEnum = oFence.GetContents(True)

    The oFence.GetContents(True) was the real trick/solution.

    3) Collects all the data (length, start x, start y, etc) into collections within collections (elements are in collections based on their levels)

    4) The clones have been given element id's so the sub then removes all elements higher than the previously defined highest id

    5) Outputs everything to Excel

    And it's working like a charm.