Again. Rotate block ?

Discussion in 'AutoCAD' started by Miles, Nov 17, 2004.

  1. Miles

    Miles Guest

    All,
    I am still searching for a lisp/vba that will allow me to select either TEXT
    or INSERTS to rotate, then a base LINE, then the objects selected will
    rotate to match the angle of the LINE (but not move), then finally rotate
    themselves PERPENDICULAR to the base LINE.

    Anyone ?
    Thanks.
     
    Miles, Nov 17, 2004
    #1
  2. You should be able to skip the middle step there, and get them rotated
    perpendicular directly. Use (assoc 10) and (assoc 11) on the line to get
    the endpoints, and calculate its angle. Adjust that by (/ pi 2) radians,
    and apply the new angle to the block insertion or text angle, with
    (entmod)/(entupd). One thing you might have to experiment with is the
    relationship between the line direction and the perpendicular angle, since
    you can't tell by looking at a line which way it goes (which end is 10 and
    which is 11). That could matter more for the text than the blocks. You can
    test for what range the Line's angle is in, to decide whether to add or
    subtract to find the perpendicular direction.

    That ought to work if it's really a Line you're using. It's a lot more
    complicated if it's a line segment within a Polyline, or part of a Block, or
    something.

    I wonder (without digging into it more) whether it will be possible to make
    one routine that would do this for either text or blocks. If the code for
    rotation angle is the same in both, it could work (maybe even for both types
    within the same selection). Otherwise, you'd have to either make separate
    routines, or test for the entity type before telling it which code to
    modify.
     
    Kent Cooper, AIA, Nov 17, 2004
    #2
  3. Miles

    Miles Guest

    Thank you very much. This is the code that I found while surfing around. I
    will try and apply your suggestions.
    This code aligns the INSERTS and TEXT perfectly, however, I cannot get the
    perpendicular portion to work.

    (defun c:CHGANGLE (/ OCM OSM EN1 EN2 LEN PT1 PT2
    X1 Y1 X2 Y2 INDEX ANG SKIND PT3
    PT4 PT5 DIST2
    )
    (setq OCM (getvar "cmdecho")
    OSM (getvar "osmode")
    )
    (setvar "cmdecho" 0)
    (setvar "osmode" 0)
    (princ "\nSelect TEXT, BLOCK or LINE for rotation: ")
    (while (setq S (ssget))
    (setq LEN (sslength S)
    INDEX 0
    )
    (If (setq EN1
    (car
    (entsel
    "\nPick TEXT, BLOCK, LINE or ARC to parallel:"
    )
    )
    )
    (progn
    (setq EN1 (entget EN1)
    KIND (cdr (assoc 0 EN1))
    )
    (if (or (= KIND "INSERT") (= KIND "TEXT"))
    (setq ANG (cdr (assoc 50 EN1)))
    (progn
    (setq X1 (cadr (assoc 10 EN1))
    X2 (cadr (assoc 11 EN1))
    PT1 (cdr (assoc 10 EN1))
    PT2 (cdr (assoc 11 EN1))
    )
    (if (> X2 X1)
    (setq ANG (angle PT1 PT2))
    (setq ANG (angle PT2 PT1))
    )
    ;(setq ANG (+ ANG (+ 90)))
    )
    )
    )
    ; (setq ANG (getangle "\nSelect 1st point: "))
    )
    (while (< INDEX LEN)
    (setq EN2 (entget (ssname S INDEX)))
    (if (= (cdr (assoc 0 EN2)) "LINE")
    (setq PT3 (cdr (assoc 10 EN2))
    PT4 (cdr (assoc 11 EN2))
    DIST2 (distance PT3 PT4)
    PT5 (polar PT3 ANG DIST2)
    EN2 (subst (cons 11 PT5) (cons 11 PT4) EN2)
    )
    (setq EN2 (subst (cons '50 ANG) (assoc 50 EN2) EN2))
    )
    (entmod EN2)
    (setq INDEX (1+ INDEX))
    )
    ; (princ "\nSelect TEXT, BLOCK or LINE for rotation: ")
    )
    (setvar "cmdecho" OCM)
    (setvar "osmode" OSM)
    (setq OSM nil
    OCM nil
    EN1 nil
    EN2 nil
    LEN nil
    PT1 nil
    PT2 nil
    X1 nil
    Y1 nil
    X2 nil
    Y2 nil
    INDEX nil
    ANG nil
    S nil
    KIND nil
    PT3 nil
    PT4 nil
    PT5 nil
    DIST2 nil
    )
    (prin1)
    )
     
    Miles, Nov 17, 2004
    #3
  4. In a quick look-through, it appears you have a line to add 90 degrees to the
    ANG value, but it's "commented out" with a semi-colon in front of it. And I
    don't get why it's got an extra plus sign and parentheses connected with the
    90. Also, I don't see any radians/degrees compensation in there. I think
    you want to change the line

    ;(setq ANG (+ ANG (+ 90)))

    to

    (setq ANG (+ ANG (/ pi 2)))

    [or possibly minus instead of plus, depending on circumstances].
     
    Kent Cooper, AIA, Nov 17, 2004
    #4
  5. Miles

    Miles Guest

    Thanks - that did the trick =) The +90 was my failed attempt at trying to
    get it perpendicular.
    Thanks again for all your help.

     
    Miles, Nov 17, 2004
    #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.