How to join into polyline and sweep out unwanted entities?

Discussion in 'AutoCAD' started by bm01, Dec 22, 2003.

  1. bm01

    bm01 Guest

    Please help me acheive the following two tasks with lisp rountines:

    Task-1) I have a drawing containning lines and arcs. The adjacent lines or arcs seem to be connected to each other.But when I zoom in the intersection portion,there is always a very small gap (0.0001mm ~ 0.5mm) between the two entities.Therefore,I can't join the adjacent lines and arcs into polyline objects. Is there a lisp routine to do the job quickly instead of fillet each two entities with 0 radius step by step?

    Task-2) Suppose that there are many open polylines in the drawing. And there are several entities (plines,lines,points,circles,arcs) within a user-defined polyline width.Those entities may be parallel,intersecting or laying under/on top of the polylines.
    I need a lisp routine to define a width value (for example 0.5 mm) by the user,then the lisp is able to sweep all the unwanted entities along each polyline paths.Entities, which are not totally located within the pline width area,are required to remain unchanged or untrimmed.

    Any solutions?

    Wish you all have a Merry Christmas!

    Rosa Hisao
     
    bm01, Dec 22, 2003
    #1
  2. bm01

    bestafor Guest

    HiHo;
    Here is a routine from this site.
    ;;; From AutoLISP FAQ (part 2/2) - Samples, code
    ;;; by Reini Urban <>
    ;;; This sample converts all selected elements to polylines and
    ;;; tries to join as much as possible.
    ;;;====================================
    (defun C:JOINPOLY (/ ele ss)
    (foreach ele (sslist (setq ss (ssget))) ;better process lists
    (if (entget ele) ;not already joined
    (cond ;(then it would be nil)
    ((istypep ele '("ARC" "LINE"))
    ;; in fact you should check Z of lines and UCS here too
    (command "_PEDIT" ele "_Y" "_J" ss "" ""); convert and JOIN
    )
    ((and (istypep ele '("POLYLINE" "LWPOLYLINE")) ;bugfix
    (not (flagsetp 1 ele)) ;not closed
    (< (rem (getflag ele) 128) 8)) ;ignore meshes and such
    (command "_PEDIT" ele "_J" ss "" "");ucs check omitted
    )
    );end cond
    );end if
    );end foreach
    (princ)
    );end defun c:joinpoly
    ;;;====================================
    (defun ISTYPEP (ele typ) ;better implementation to accept lists too
    (cond
    ((listp typ) (member (gettyp ele) typ)) ;bugfixed
    ((stringp typ) (= (gettyp ele) typ)) ;assume typ uppercase
    (T nil)));end defun ISTYPEP
    ;;;====================================
    ;;; Ex: (getflag pline) => 1 if closed
    (defun GETFLAG (ele) (getval 70 ele)) ;same with the entity flag
    ;;;====================================
    ;;; bitvalue val in flag of element set?
    ;;; Ex: (flagsetp 1 pline) => T if closed
    ;;; Ex: (flagsetp 16 vertex) => T if spline control point
    (defun FLAGSETP (val ele)
    (bitsetp val (getflag ele)))
    ;;;====================================
    ;;; Ex: (bitsetp 4 12) => T ;bitvalue 4 (=2.Bit) in 12 (=4+8) is set
    (defun BITSETP (val flag)
    (= (logand val flag) val))
    ;;;====================================
    ;;; convert selection set to list,
    ;;; Note: it's also wise to use ai_ssget, because some ents could be
    ;;; on locked layers
    ;;; Ex: (sslist (ai_ssget (ssget))) => list of selected unlocked ents
    ;;; or (mapcar 'entupd (sslist (ssget "X" '((8 . "TEMP")))))
    ;;; - regens all entities on layer TEMP
    (defun SSLIST (ss / n lst)
    (if (= (type ss) 'PICKSET)
    (repeat (setq n (sslength ss))
    (setq n (1- n)
    lst (cons (ssname ss n) lst)))))
    ;;;====================================
    ;;; apply a function to each ent in ss, in reversed order
    ;;; Faster, but not so easy to understand. see [22.2]
    ;;; [renamed from SSAPPLY to SSMAP to match the stdlib name]
    ;;; Ex: (ssmap 'entupd (ssget)) ; regenerate only some entities
    ; (defun SSMAP (fun ss / n)
    ; (if (= 'PICKSET (type ss))
    ; (repeat (setq n (sslength ss))
    ; (apply fun (list (ssname ss (setq n (1- n))))))))
    ;;;====================================
    ;;; Ex: (gettyp pline) => "POLYLINE"
    (defun GETTYP (ele) ;return type
    (getval 0 ele))
    ;;;====================================
    (defun stringp (s) (= (type s) 'STR))
    ;;;====================================
    ;;; returns the first group value of an entity.
    ;;; like the wellknown (dxf) function but accepts all kinds of
    ;;; entity representations (ename, entget list, entsel list)
    ;;; NOTE: For getting 10 groups in LWPOLYLINE's not usable!
    (defun GETVAL (grp ele) ;"dxf value" of any ent...
    (cond ((= (type ele) 'ENAME) ;ENAME
    (cdr (assoc grp (entget ele))))
    ((not ele) nil) ;empty value
    ((not (listp ele)) nil) ;invalid ele
    ((= (type (car ele)) 'ENAME) ;entsel-list
    (cdr (assoc grp (entget (car ele)))))
    (T (cdr (assoc grp ele))))) ;entget-list
    ;;;====================================

    And, at www.cadalyst.com in the "get the code" section
    there is, in the jan03, code a join polyline routine.
    Regarding the second question, I have never seen
    a solution for that. www.mcneel.com used to publish
    a "gaps.lsp" that will find all open spaces within a user
    specific distance. If you are interested I will look for
    it and send it to you.
    Please help me acheive the following two tasks with lisp rountines:

    Task-1) I have a drawing containning lines and arcs. The adjacent lines or
    arcs seem to be connected to each other.But when I zoom in the intersection
    portion,there is always a very small gap (0.0001mm ~ 0.5mm) between the two
    entities.Therefore,I can't join the adjacent lines and arcs into polyline
    objects. Is there a lisp routine to do the job quickly instead of fillet
    each two entities with 0 radius step by step?

    Task-2) Suppose that there are many open polylines in the drawing. And there
    are several entities (plines,lines,points,circles,arcs) within a
    user-defined polyline width.Those entities may be parallel,intersecting or
    laying under/on top of the polylines.
    I need a lisp routine to define a width value (for example 0.5 mm) by the
    user,then the lisp is able to sweep all the unwanted entities along each
    polyline paths.Entities, which are not totally located within the pline
    width area,are required to remain unchanged or untrimmed.

    Any solutions?

    Wish you all have a Merry Christmas!

    Rosa Hisao
     
    bestafor, Dec 22, 2003
    #2
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.