lisp problem regarding blocks, attributes, and trimming

Discussion in 'AutoCAD' started by Eugene, Sep 12, 2003.

  1. Eugene

    Eugene Guest

    Hello,

    I thought I had this all figured out with lots of help from the NG (thanks).
    After further testing I see the problem isn't really fixed..... Here's the
    program;
    Draw a pline from point 1 to point 2, (points are user defined)
    Place a block w/ attribute at point 2 (The block is a note symbol, such as a
    circle, square, hex, or triangle)
    User to edit block attribute
    Trim the pline from intersecting the block symbol.

    Please see the code below.......................

    ;;; CIRLEADER.LSP
    ;;;
    ;;; DESCRIPTION:
    ;;;
    ;;; This routine draws a leader line with a circle block note symbol
    ;;;
    ;;;ERROR HANDLING ROUTINE ;;;;;;;;;;;;;;;;;

    (defun myerror (s) ; If an error (such as CTRL-C) occurs
    while this command is active...
    (if (/= s "Function cancelled")
    (princ (strcat "\nError: " s))
    )
    (setvar "cmdecho" icm) ; Restore saved modes
    (setvar "filedia" ifd)
    (setvar "cmddia" icd)
    (setvar "cecolor" "bylayer")
    (setq *error* olderr) ; Restore old *error* handler
    (princ)
    )

    ;--MAIN PROGRAM------------------------------

    (defun dtr (ang1) ;converts degrees to radians (because AutoCAD
    (* pi (/ ang1 180.0)) ;works in dergees & AutoLISP works in radians)
    )



    (defun ALE_LASTENT ( / ename result )
    (and
    (setq result (entlast))
    (while (setq ename (entnext result)) (setq result ename))
    )
    result
    )

    (defun ALE_SS-AFTER (ename / ss)
    (cond
    ( (eq 'ename (type ename))
    (setq ss (ssadd))
    (while (setq ename (entnext ename))
    (if (entget ename) (ssadd ename ss)))
    (if (< 0 (sslength ss)) ss)
    )
    ( T (alert "Attention: error in selection set (lastent)") )
    ) )

    (defun c:cirleader (/ olderr ec as pa pm p1 p2 sz ad marker )
    (setq olderr *error* *error* myerror)
    (setq ec (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (setq as (getvar "autosnap"))
    (setq pa (getvar "polarang"))
    (setq pm (getvar "polarmode"))
    (command "ucs" "view")
    (setvar "autosnap" 47)
    (setvar "polarang" 0.523598776) ;30 degrees
    (setvar "polarmode" 2)
    (setq p1 (getpoint "\nPick Leader Start..."))
    (setq p2 (getpoint p1 "\nPick Note Location..."))
    (setq sz (getvar "dimscale"))
    ;(command "ucs" "Previous")
    (setvar "autosnap" as)
    (setvar "polarang" pa)
    (setvar "polarmode" pm)
    (setvar "cmdecho" ec)
    (command "pline" p1 p2 nil)
    (setq ad (getvar "attdia"))
    (setvar "attdia" 1)
    (setq marker (ALE_LASTENT))
    (command "-insert" "note-circle" p2 sz sz "0" )
    (command "trim" (ALE_SS-AFTER marker) "" p2 nil )
    (setvar "attdia" ad)
    (command "ucs" "Previous")
    (princ)

    )

    I think the program is using the attribute for the trimming edge selection
    not the block....supporting reason;
    Trimmed pline is sporadic...sometimes it trims, sometimes it doesn't
    Seems to depend on the pline angle and attribute value if the pline is
    trimmed or not...
    Seems if the attribute value takes up more block real-estate (ie 00 opposed
    to 1) and the pline angle is such that the runs through more of the
    attribute the higher chance the program will work.

    Please remember when testing to use different angles and different attribute
    values...I'm sure you will get the same results....If anyone is interested
    I'll post the block in the customer files named note-circle
    Also, I'm using WinXP & 2000i

    Thanks!!
    Eugene
     
    Eugene, Sep 12, 2003
    #1
  2. Eugene

    Rudy Tovar Guest

    Why even use trim?

    Since you're the one defining all the points, simply start your leader from
    the edge of any block you're defining.

    startpoint
    nextpoint
    (re-assign startpoint (polar startpoint (angle startpoint nextpoint))
    predefined-distance)
    nextpoint
    nextpoint
    etc.
     
    Rudy Tovar, Sep 12, 2003
    #2
  3. Eugene

    Mack Attack Guest

    Have you tried to insert the block first and then start the pline a given
    distance from the insertion point of that block
     
    Mack Attack, Sep 12, 2003
    #3
  4. Eugene

    Rudy Tovar Guest

    Excuse the wrong placement of the ) malformed list

    (setq startpoint (polar startpoint (angle startpoint nextpoint)
    predefined-distance));<---
     
    Rudy Tovar, Sep 12, 2003
    #4
  5. Eugene

    Eugene Guest

    Rudy and Mack......Thanks for your help,

    I see one problem....the defined distance .....it would work well for a
    circle, but what about a triangle? The distance from the insertion point
    (center of the triangle) to the edge of the triangle will differ with every
    angle.....and I cant lock the users to specific angles.....any ideas?

    I had another thought though....kind of a work around, to first insert a
    block the same shape as the block with attributes, trim to that shape,
    delete the shape, insert the block and edit the attribute. That would
    eliminate the whole attribute issue...but its a gum and shoe string
    solution, not very intelligent.

    Thanks
     
    Eugene, Sep 12, 2003
    #5
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.