Draw polyline around a block

Discussion in 'AutoCAD' started by mgrigoriev, May 21, 2004.

  1. mgrigoriev

    mgrigoriev Guest

    Hi,
    I am trying to draw a LWPolyline around any given block. GetBoundingBox returns a rectangle that doesn't represent the actual shape of the block. I need to capture the exact shape of the block, so that, say, a triangle is shown as a triangle. Unfortunately, blocks can be more complicated than a triangle. They may consist of lines, arcs and polylines. All entities are connected, that is there is no entity in a block that lies away from the others.
    This is a very challenging task, and I would greatly appreciate any help.
    Thank you in advance,
    Mike
     
    mgrigoriev, May 21, 2004
    #1
  2. Complicated indeed.
    But how about copying all the entities in the block and converting them into
    regions, then do a boolean add ??


    --
    Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica
    (sorry, phony e-mail, SPAM made me do it)

    returns a rectangle that doesn't represent the actual shape of the block. I
    need to capture the exact shape of the block, so that, say, a triangle is
    shown as a triangle. Unfortunately, blocks can be more complicated than a
    triangle. They may consist of lines, arcs and polylines. All entities are
    connected, that is there is no entity in a block that lies away from the
    others.
     
    Jorge Jimenez, May 21, 2004
    #2
  3. mgrigoriev

    jcallenj Guest

    Could you offset all the nested items and union together the results? I
    haven't tried this myself, but I think it would work.

    I guess for nested text you would still use bounding box, and for non-closed
    items you would have to close them (I could see this part getting tricky).
    Once you've gotten that far use offset, addregion, and boolean(acUnion).

    I have thought about this before but never actually done anything with it.
    Maybe someone else has already done it?

    HTH,
     
    jcallenj, May 21, 2004
    #3
  4. Cheat: insert a new block at the same point with a slightly larger scale.
     
    Frank Oquendo, May 21, 2004
    #4
  5. mgrigoriev

    mgrigoriev Guest

    This sounds like a great idea. Closing entities will definitely be tricky, though. If we were just talking about lines.. When arcs are involved the final shape could become kinda unpredictable.
     
    mgrigoriev, May 22, 2004
    #5
  6. mgrigoriev

    mgrigoriev Guest

    I am sorry, but I can't understand how inserting a larger block can help.
     
    mgrigoriev, May 22, 2004
    #6
  7. mgrigoriev

    akseidel Guest

    Try this algorithm:

    Start with an imaginary circle that shares a center with the center of
    the bounding box. Save the coordinate for this circle's center.

    Iterating through all of the block's primtives one by one.

    Find the intersections for each primitive that also lie on the
    primitive. Break the primitive into fragments having ends at the
    intersections. Store the data for these fragments in a way that you can
    detect their orginal source. (Know they came from the same original
    primitive.) The end result will be line and arc fragments.

    Find the outermost original primitive. Start from its outer end. Search
    through the fragments belonging to it picking the correct on to use.
    This becomes the first part of you shape. Use its end closer to the
    center. Find the other fragments not originaly from the same primitive
    that share this coordinate. These are the intersecting fragments. Pick
    the one with the most outer direction from the center as defined by its
    other end. Add this to you shape. Remove it from the fragment list.

    Repeat the above until you reach the starting point. If no other
    fragment shares an end, then double back on the previous fragment since
    this must be an outer spike.
     
    akseidel, May 22, 2004
    #7
  8. Maybe you should recheck your strategy (approach) toward detecting if
    something is in or out of the block. Sometimes it's not easy to distinguish
    between the block itself and it's attributes when they're all rotated and
    possibly non-uniformly scaled. If you are programming a system that consists
    of the nodes (blocks) and polylines (links) interconnecting them, then
    redefine global strategy.

    Regards,
    Maksim Sestic
    www.geoinova.com
     
    Maksim Sestic, May 22, 2004
    #8
  9. myvar = block.explode

    'returns an array of entities in the block ie, three lines for a triangle
    poly

    myregion = ThisDrawing.ModelSpace.AddRegion(myvar)
    'creates a region from the object array.

    Thought it might help.

    Paul
     
    Paul Richardson, May 22, 2004
    #9
  10. mgrigoriev

    jcallenj Guest

    You could offset each sub both ways and connect the ends. This would trace
    around each sub individually, potentially leaving 'islands' after the union.
    But I think it would take care of closing the loops.

    In AutoCAD I would then explode the region, pedit/join the results back to
    plines, and erase the islands, but I'm not sure how to do the pedit/join in
    vba w/o sendcommand. Or how to tell programmatically which are the islands.

    James
     
    jcallenj, May 24, 2004
    #10
  11. How about using the bounding box to draw a rectangle around the entire
    block.
    Then somehow use bpoly and select just inside that rectangle.
    Erase the rectangle made with boundingbox and the one made with bpoly.
    Then you could offset the resulting polyline which should be a profile of
    your block.

    returns a rectangle that doesn't represent the actual shape of the block. I
    need to capture the exact shape of the block, so that, say, a triangle is
    shown as a triangle. Unfortunately, blocks can be more complicated than a
    triangle. They may consist of lines, arcs and polylines. All entities are
    connected, that is there is no entity in a block that lies away from the
    others.
     
    Mark Johnston, May 25, 2004
    #11
  12. mgrigoriev

    Paul Guest

    Hi,

    Do you have sample code for this algorithm?

    Thanks,

    Paul
     
    Paul, May 26, 2004
    #12
  13. mgrigoriev

    mgrigoriev Guest

    This sounds like another good idea. Although, how about if the block is devided into many small pieces inside? Using bpoly will return not the whole block but one small closed entity inside it.
     
    mgrigoriev, May 26, 2004
    #13
  14. Good question.
    If the block is made up of separated pieces bpoly will wrap each piece
    individually.
    I suppose what you want to do could still be done but since we're talking
    about using SendCommand it's going to be very messy.

    By the way if you connected each separate polyline (boundary) with a line
    then ran bpoly again the result would be one polyline instead of many small
    ones.

    Mark

    devided into many small pieces inside? Using bpoly will return not the whole
    block but one small closed entity inside it.
     
    Mark Johnston, May 29, 2004
    #14
  15. Mike,

    I just Xplode the block, which leaves the block in place and creates a copy.
    ie closed 3 sided poly turned into a block become a closed 3sided poly when
    ..xplode is issued.

    Am I missing something?

    Paul
    returns a rectangle that doesn't represent the actual shape of the block. I
    need to capture the exact shape of the block, so that, say, a triangle is
    shown as a triangle. Unfortunately, blocks can be more complicated than a
    triangle. They may consist of lines, arcs and polylines. All entities are
    connected, that is there is no entity in a block that lies away from the
    others.
     
    Paul Richardson, Jun 23, 2004
    #15
  16. Mike, You could also use GetSubEntity to find the entities that make up the
    block and their coordinates and then draw a pline.
    pr
    returns a rectangle that doesn't represent the actual shape of the block. I
    need to capture the exact shape of the block, so that, say, a triangle is
    shown as a triangle. Unfortunately, blocks can be more complicated than a
    triangle. They may consist of lines, arcs and polylines. All entities are
    connected, that is there is no entity in a block that lies away from the
    others.
     
    Paul Richardson, Jun 23, 2004
    #16
  17. Im not going to try to put any code to this but this is what I would do::

    Isolate the block
    Get the bounding box and draw a rectangle slightly bigger
    draw a "boundary" polyline, this will create 2 polylines, one for the
    bounding box
    delete the outer rectangles
    you are left with a tight fit polyline

    Lloyd Rubidge
     
    Lloyd Rubidge, Jun 30, 2004
    #17
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.