Search code examples
lispautocadautolisp

draw a polygon over closed polylines


i try to describe this problem well with my humble English skills :
i have closed blocks on my dwg file, these blocks are consist of many Polylines which are joined together but they are not uni-body (integrated), all i want is a lisp to draw a polygon over this block and create a uni-body block. is there any way around ? thnx


Solution

  • Assuming that:

    • when you say "joined" you mean their ends are touching,
    • when you say "uni-body" you actually mean "joined" in the AutoCAD sense,

    then try the following:

    (defun convert_block_to_polyline (block / old_entlast new_entlast curr polylines_set)
      (setq old_entlast (entlast))
      (command "explode" block)
      (setq new_entlast (entlast))
      (setq
        curr (entnext old_entlast)
        polylines_set (ssadd)
        )
      (while (entnext curr)
        (ssadd curr polylines_set)
        (setq curr (entnext curr))
        )
      (command "join" (entlast) polylines_set "")
      (princ)
    )
    

    This function assumes:

    • You don't want to retain the original block, if you do then its a simple question of creating a copy before you explode it, and pasting it in the same place afterwards.
    • The block is made solely of objects which can be included in the join command (lines, polylines etc..)