Author Topic: Rotate North Block to Viewport WCS  (Read 1816 times)

0 Members and 1 Guest are viewing this topic.

Shoey

  • Mosquito
  • Posts: 8
  • I used to be indecisive but now I'm not quite sure
Rotate North Block to Viewport WCS
« on: March 13, 2018, 01:48:47 PM »
Hello All

I have the lisp code below, which aligns a block in paper space (in this case a north point block) to the WCS (north) of the model space view.
I would like modifications to this but need help if anybody can help?
The modification i would like is for an error trap.
I would like it to loop if i miss or select anything but a viewport or the polyline boundary of the polygon viewport.
And also if i select anything but the block it errors.
Any help appreciated.

Code: [Select]
;;Wriiten by Mike Roberts
(defun c:RN()
   (setq tw(entget(car(entsel" Select a Viewport:"))))
   (setq new (cdr (assoc 0 tw)))
 (cond
                 ((= new "VIEWPORT")(setq rt(cdr(assoc 51 tw))))
 ((= new "LWPOLYLINE")(setq temp (entget(cdr (assoc 330 tw))))(setq rt(cdr(assoc 51 temp))))
              )
   (setq en(car(entsel" Select North Arrow: ")))
   (setq elist(entget en))
   (setq elist(subst (cons 50 rt)(assoc 50 elist) elist))
   (entmod elist)
   (princ)
 )

Many thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Rotate North Block to Viewport WCS
« Reply #1 on: March 13, 2018, 02:25:45 PM »
Try the following instead:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rn ( / ent obj sel )
  2.     (if (= 1 (getvar 'cvport))
  3.         (progn
  4.             (while
  5.                 (progn (setvar 'errno 0) (princ "\nSelect a viewport: ")
  6.                     (not
  7.                         (or (setq sel (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
  8.                             (= 52 (getvar 'errno))
  9.                         )
  10.                     )
  11.                 )
  12.                 (princ "\nMissed, try again.")
  13.             )
  14.             (if sel
  15.                 (while
  16.                     (progn
  17.                         (setvar 'errno 0)
  18.                         (setq ent (car (entsel "\nSelect north arrow: ")))
  19.                         (cond
  20.                             (   (= 7 (getvar 'errno))
  21.                                 (princ "\nMissed, try again.")
  22.                             )
  23.                             (   (null ent) nil)
  24.                             (   (/= "INSERT" (cdr (assoc 0 (entget ent))))
  25.                                 (princ "\nThe selected object is not a block.")
  26.                             )
  27.                             (   (not (vlax-write-enabled-p (setq obj (vlax-ename->vla-object ent))))
  28.                                 (princ "\nThe selected block is on a locked layer.")
  29.                             )
  30.                             (   (vla-put-rotation obj (cdr (assoc 51 (entget (ssname sel 0))))))
  31.                         )
  32.                     )
  33.                 )
  34.             )
  35.         )
  36.         (princ "\nCommand only available in Paperspace.")
  37.     )
  38.     (princ)
  39. )

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Rotate North Block to Viewport WCS
« Reply #2 on: March 13, 2018, 03:01:09 PM »
There is also THIS from many moons ago.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Shoey

  • Mosquito
  • Posts: 8
  • I used to be indecisive but now I'm not quite sure
Re: Rotate North Block to Viewport WCS
« Reply #3 on: March 14, 2018, 12:36:34 PM »
Thanks to Lee Mac and Ronjonp.
Appreciate your time and feedback.