lips improvement needs a little help please

Discussion in 'AutoCAD' started by John Crocco, Feb 17, 2004.

  1. John Crocco

    John Crocco Guest

    I have the below lisp that inserts a cw symbol on a horizontal line with 1
    click. I have another for a verticle line. Is there a way (Theres always a
    way) that with this lisp modified and 1 pick I can have it go onto a line in
    any direction or angle? I kinda have an idea, but cant seem to get it to
    work. I use a similar one to insert a "G" for gas piping, and could modify
    it then to do that as well.

    I think if I have it get the line information (could it also be a polyline?)
    it can then get the angle of the start and end points, and insert it in the
    middle and rotated by the angle. That example is below the lisp.

    Any help would be appreciated.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Custom commands by John Crocco
    ;breaks horizontal line and inserts CW symbol (1 dash).
    (DEFUN C:CWH (/ pt1 pt2 sc len os *Error*)
    ;;;;;;;;; Application error handler
    (defun *Error* (Msg)
    (command "._Undo" "_End") ; end undo group
    (cond
    ((not Msg)) ; no error, do nothing
    ((member (strcase Msg T) ; cancel, do undo
    '("console break"
    "function cancelled"
    "quit / exit abort"))
    (command "._U")
    (setvar "cmdecho" cecho)
    (command "osmode" os);UNDO COMMANDS HERE
    ;
    ;
    ;
    );END OF MEMBER
    ((princ (strcat "\nError: " Msg)))
    ) ; END OF COND
    (princ)
    ); END OF DEFUN ERROR
    (setq cecho (getvar "cmdecho"))
    (setvar "CmdEcho" 0) ; turn echo off
    (command "._Undo" "_End") ; close any open group
    (command "._Undo" "_BEgin") ; start new group
    ;;;;;;;;;;;;;;;;;;;;;;
    (setq os (getvar "osmode"))
    (command "osmode" "512")
    (setq pt1 (getpoint "\nInsertion Point: "))
    (setq sc (getvar "userr1"))
    (setq pt2 (* 24.0 sc))
    (setq len (polar pt1 0.0 pt2))
    (command "BREAK" pt1 len)
    (command "INSERT" "cwpipe" pt1 sc sc 0)
    (command "osmode" os)
    (setvar "cmdecho" cecho)
    (*Error* nil) ;call error handler w/no error
    )

    --
    John Crocco
    AutoCad 2002 in XP PRO

    Something I could use is kinda like this below!!!

    (setq pt1 (getpoint "\nSelect first point... "))
    (setq ang (rtd (angle pt0 pt1)))
    (setvar "osmode" 0);sets osnap mode to NONE
    (cond
    ((> sc 0.5) (setq bdist 10));greater than .5
    ((= sc 0.5) (setq bdist 5));equals .5
    ((< sc 0.5) (setq bdist 2.5));less than .5
    )
    (cond
    ((or (= ang 0) (= ang 180)) (setq ang1 (* pi 0.25) ang2 (* pi 1.5) ang3 pi
    ang4 0))
    (T (setq ang1 (* pi 0.75) ang2 0 ang3 (* pi 1.5) ang4 (* pi 0.5)))
    )
    (command ".break" "c" (polar pt0 ang1 4) (polar pt0 ang2 6) (polar pt1 ang3
    bdist) (polar pt1 ang4 bdist))
    (setvar "osmode" 32)
    (setq pt2 (getpoint "\nSelect second point... "))
    (setvar "osmode" 0)
    (command ".break" "c" (polar pt0 ang1 4) (polar pt0 ang2 6) (polar pt2 ang3
    bdist) (polar pt2 ang4 bdist))
     
    John Crocco, Feb 17, 2004
    #1
  2. John Crocco

    TCEBob Guest

    Yes. What I did (for labeling contours, many moons ago) was set osnap to
    near, have the user pick an insert point and then pick a point for
    direction. I'd like to do as you suggest, let the routine decide on the
    angle by referring to the object properties. However there are problems.
    You may or may not want the insert to follow the direction of the
    object. Perhaps you want it to obey the Dimension rules of deciding
    whether it reads up and right or down and left. Much more programming in
    there than you or I am competent to do.

    PS - I don't recommend breaking the object. At least in civil work
    there's too much changing and it can get to be a real pain fixing the
    breaks. However: if you make a block consisting of a wipeout and an
    attribute as a group, you could write a little shell lisp to insert it
    at the right location, scale it to the current text height and wait for
    you to click an angle. Then it would demand the text for the attribute.

    Gee, that's pretty good. Think I'll try it myself.

    rs
     
    TCEBob, Feb 17, 2004
    #2
  3. John Crocco

    TCEBob Guest

    Yeah, I thought of that. I believe vlax-curve-getFirstDeriv respects
    curves, too. But we haven't addressed the issue of which direction the
    text will go in at. LDT gives a choice of "uphill" or "readable."
    Personally I opt for uphill because it seems to be standard in usgs maps
    and because it gives the reader a bit more info.

    rs
     
    TCEBob, Feb 18, 2004
    #3
  4. John Crocco

    Joe Burke Guest

    John,

    This might give you some ideas. It assumes the block should not be inserted at an
    angle between 90 and 270 degrees. TCEBob's point.

    Works with lines and plines. Would be funky if you pick an arc in a pline.

    There's two functions. The good stuff is by John Uhden.

    Joe Burke

    ;; 2/17/2004
    ;; demo - no error checking
    (defun c:InsertAng ( / osm ent pt endpts ang )
    (setq osm (getvar "osmode"))
    (setq ent (entsel "\nSelect line or pline at point to insert block: "))
    (setq pt (cadr ent))
    (setq endpts (SegmentPts ent))
    (setq ang (angle (car endpts) (cadr endpts)))
    (if (< (* pi 0.5) ang (* pi 1.5)) ;if between 90 and 270 degrees
    (setq ang (+ pi ang))
    )
    (setq ang (/ (* ang 180.0) pi)) ;rtd
    (setvar "osmode" 512)
    (command "-insert" "Center Line" pt 24 "" ang) ;your block name
    (setvar "osmode" osm)
    (princ)
    ) ;end

    ;returns a list of two 3D points, the end points of the segment picked
    ;argument: ENT as returned by entsel (not ename)
    ;works with lines, arcs and all types of plines
    ;by John Uhden - revised 9/28/02
    (defun SegmentPts (ent / e pnt vobj Name param1 param2 p1 p2)
    (vl-load-com)
    (and
    (setq e (car ent))
    (= (type e) 'ENAME)
    (setq pnt (cadr ent))
    (listp pnt)
    (not (atom (cdr pnt)))
    (vl-every (function (lambda (x)(= (type x) 'REAL))) pnt)
    (setq vobj (vlax-ename->vla-object (car ent)))
    (setq pnt (trans (cadr ent) 1 0))
    (setq pnt (vlax-curve-getClosestPointTo vobj pnt))
    (setq Name (vla-get-ObjectName vobj))
    (cond
    ((vl-position Name '("AcDbArc" "AcDbLine"))
    (setq p1 (vlax-curve-getStartPoint vobj))
    (setq p2 (vlax-curve-getEndPoint vobj))
    )
    ((wcmatch (strcase Name) "*POLYLINE")
    (setq param1 (vlax-curve-getParamAtPoint vobj pnt))
    (setq param1 (fix param1))
    (setq param2 (1+ param1))
    (if (equal param1 (vlax-curve-getStartParam vobj) 1e-10)
    (setq p1 (vlax-curve-getStartPoint vobj))
    (setq p1 (vlax-curve-getPointAtParam vobj param1))
    )
    (if (equal param2 (vlax-curve-getEndParam vobj) 1e-10)
    (setq p2 (vlax-curve-getEndPoint vobj))
    (setq p2 (vlax-curve-getPointAtParam vobj param2))
    )
    )
    (T (prompt (strcat "\nHaven't figured out a(n) " Name " yet.")))
    )
    p1 p2
    )
    (list p1 p2)
    ) ;end
     
    Joe Burke, Feb 18, 2004
    #4
  5. John Crocco

    John Crocco Guest

    What if we made it a two pick, and inserted the text or object in the same
    direction as the pick sequence? It would really be nice if it could work
    for polylines, splines, different segment lines, etc.
     
    John Crocco, Feb 18, 2004
    #5
  6. John Crocco

    TCEBob Guest

    If you look above you will see that that's what I first suggested. Even
    though it is inelegant I really don't mind clicking twice.

    rs
     
    TCEBob, Feb 18, 2004
    #6
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.