TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mohan on July 28, 2022, 09:57:35 AM

Title: Align North
Post by: mohan on July 28, 2022, 09:57:35 AM
Help to fix this route!
Code - Auto/Visual Lisp: [Select]
  1. (defun c:autorotatenorth (/ ss ent1 tw new rt temp blo ent2 elist)
  2. (setvar 'ctab tab)
  3.       (setq ss (ssget "_x" '((0 . "VIEWPORT") (100 . "AcDbViewport") (8 . "-TEXT"))))
  4.       (setq ent1 (ssname ss 0))
  5.       (setq tw (entget ent1))
  6.       (setq new (cdr (assoc 0 tw )))
  7. (cond ((= new "VIEWPORT") (setq rt (cdr (assoc 51 tw))))
  8.       ((= new "LWPOLYLINE") (setq temp (entget (cdr (assoc 330 tw)))) (setq rt (cdr (assoc 51 temp)))))
  9.       (setq blo (ssget "_x" '((2 . "NORTH") (8 . "Symbol"))))
  10.       (setq ent2 (ssname blo 0))
  11.       (setq elist (entget ent2))
  12.       (setq elist (subst (cons 50 rt) (assoc 50 elist) elist))
  13.   (entmod elist)) (princ))

It will work through Layouts to match viewports
Title: Re: Align North
Post by: ronjonp on July 28, 2022, 05:19:44 PM
I wrote this about 15 years ago  :-o
http://www.theswamp.org/index.php?topic=19285.msg234463#msg234463
Title: Re: Align North
Post by: Lee Mac on July 28, 2022, 06:04:30 PM
Time flies :-(
Title: Re: Align North
Post by: BIGAL on July 28, 2022, 11:44:49 PM
Not as long, my attempt only 2 years old. Just rotates any object so no need for block name.

Code: [Select]
; Rotate a block in pspace to match world in model
; By Alan H Aug 2020

(defun c:roblklay ( / obj1 obj rot ent)
(command "._PSPACE")
(setvar 'nomutt 1)
(princ "\nSelect a viewport")
(setq sss (ssget "_+.:E:S" (list (cons 0 "Viewport"))))
(setq obj1 (vlax-ename->vla-object (ssname sss 0)))
(setq ang (vlax-get obj1 'TwistAngle))

(while (setq ent (entsel "Pick block Enter to exit"))
(setq obj (vlax-ename->vla-object (car ent)))
(vla-put-rotation obj ang)
)

(princ)
)
(c:roblklay)

Title: Re: Align North
Post by: tombu on July 29, 2022, 09:19:09 AM
For those using AutoCAD Map 3D & verticals only the undocumented "-MAPINSERTPLE" command will add North Arrows in Paper Space matching Model Space Rotation by selecting a Viewport Boundary. If you twist the viewport afterwards the North Arrow automatically rotates to match.
Described here: https://forums.autodesk.com/t5/civil-3d-customization/civil-3d-2015-mapinsertple-command/m-p/9970125#M19256 (https://forums.autodesk.com/t5/civil-3d-customization/civil-3d-2015-mapinsertple-command/m-p/9970125#M19256)
and here: http://www.theswamp.org/index.php?topic=48049.0;all (http://www.theswamp.org/index.php?topic=48049.0;all)
For the record, here are the 3 "types":

2 = North Arrow
3 = Scale Bar
4 = Legend

(The "Select a viewport for the <type>:" command prompt changes based on which number you use.)

 The Symbols folder for the "Map - North Arrows.dwg" can be opened with the Macro:
Code: [Select]
^C^C^P(progn(startapp "explorer" (strcat "/n,/e," (vl-string-subst (strcat "Map" (chr 92) "Sample" (chr 92) "Symbols") "express" (vl-filename-directory (findfile "acetauto.lsp")))))(princ));
I modified all of them to use masked Mtext with Standard text style referencing TrueType fonts so they wouldn't require adding additional text styles and displayed better over images into "Blocks.dwg" attached. Added a drop-down with macros of the North Arrows I've used like this one:
Command Name: Aerial N↑
Macro:                ^C^C(command "-MAPINSERTPLE" "G://ENGDESGN//BeaufordT//Blocks//Blocks.dwg,Aerial,2")
Notice macro includes drawing name with path,block name,type=2.