Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cycle UCS and rotate view accordingly

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
lecheconagujas
1331 Views, 10 Replies

Cycle UCS and rotate view accordingly

Hi everyone.

 

I was wondering if there's a way to alphabetically cycle through named (user defined) UCSs, automatically doing PLAN -> Current UCS for each cycle (maybe even better if there's some alternative to PLAN that keeps the current zoom level instead of doing zoom extents)

10 REPLIES 10
Message 2 of 11
_gile
in reply to: lecheconagujas

Hi,

 

I'm not sure this reply to your request but you could use the _DVIEW command with the _Twist option.

Here's an example which rotates the current view of 45° (pi / 4 radians).

 

(defun c:twistview (/ a)
  (setq	a (angtos
	    (+ (getvar 'viewtwist) (* pi 0.25))
	    (getvar 'aunits)
	    16
	  )
  )
  (command-s "_.dview" "" "_twist" a "")
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 11

I know this is probably what you already know, but still...

Have you tried UCSFOLLOW=1 ?

And I believe that it will automatically zoom Extents, which is what you wanted to avoid...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 4 of 11

I didn't know about this so thank you. It certainly helps in dropping the step of using PLAN so it solves part of the problem, even though it does have the problem of zooming extents which I guess is unavoidable (but that's secondary anyways). My main concern here is having a fast way to cycle through each of my named UCSs in a dwg file so that I can avoid either selecting them from the dropdown (it seems the only way to have a dropdown is having the ViewCube on, which I prefer off when working in 2D) or via regular UCS command which requires too many key presses

Message 5 of 11
lecheconagujas
in reply to: _gile

Hi, thanks for the reply. I did consider _Twist but it poses a few inconvenients. I need to switch between UCS so that my ortho axes will change too. Also, I don't want to twist the view in fixed increments, I need these views to be user defined so that I can easily cycle through them, adding/deleting as I deem convenient. Maybe there's a way to twist the view according to the current UCS?

This would solve the problem of the zoom level changing every time I switch UCS and adjust the view accordingly

Message 6 of 11
_gile
in reply to: lecheconagujas

Maybe you could start from this:

(defun c:ucscycle (/ ucs lst rot)
  (while (setq ucs (tblnext "UCS" (null ucs)))
    (setq lst (cons (cdr (assoc 2 ucs)) lst))
  )
  (setq lst (reverse lst))
  (if (setq ucs (cadr (member (getvar 'ucsname) lst)))
    (command "_ucs" "_restore" ucs)
    (command "_ucs" "_restore" (car lst))
  )
  (setq	rot (angtos
	    (angle '(0 0) (trans '(1 0) 0 1 T))
	    (getvar 'aunits)
	    16
	  )
  )
  (command-s "_.dview" "" "_twist" rot "")
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 11
_gile
in reply to: _gile

If you need to integrate WCS in the cycle:

(defun c:ucscycle (/ ucs lst)
  (while (setq ucs (tblnext "UCS" (null ucs)))
    (setq lst (cons (cdr (assoc 2 ucs)) lst))
  )
  (setq	lst (reverse lst)
	ucs (getvar 'ucsname)
  )
  (cond
    ((null (member ucs lst))
     (command-s "_.ucs" "_restore" (car lst))
    )
    ((null (setq ucs (cadr (member ucs lst))))
     (command-s "_.ucs" "_world")
    )
    (T (command-s "_.ucs" "_restore" ucs))
  )
  (command-s "_.dview"
	     ""
	     "_twist"
	     (angtos
	       (angle '(0 0) (trans '(1 0) 0 1 T))
	       (getvar 'aunits)
	       16
	     )
	     ""
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 11
lecheconagujas
in reply to: _gile

This works like a charm! Excuse me if I'm asking for too much but I'm a complete ignorant on autolisp, is there a way to have this work in both ways? That is, having UCSNEXT and UCSPREV

Message 9 of 11
_gile
in reply to: lecheconagujas

Here're two commands UCSFWD and UCSBWD to cycle UCSs forward or backword.

 

(defun c:ucsfwd () (ucscycle T))

(defun c:ucsbwd () (ucscycle nil))

(defun ucscycle	(fwd / ucs lst)
  (while (setq ucs (tblnext "UCS" (null ucs)))
    (setq lst (cons (cdr (assoc 2 ucs)) lst))
  )
  (if fwd
    (setq lst (reverse lst))
  )
  (setq ucs (getvar 'ucsname))
  (cond
    ((null (member ucs lst))
     (command-s "_.ucs" "_restore" (car lst))
    )
    ((null (setq ucs (cadr (member ucs lst))))
     (command-s "_.ucs" "_world")
    )
    (T (command-s "_.ucs" "_restore" ucs))
  )
  (command-s "_.dview"
	     ""
	     "_twist"
	     (angtos
	       (angle '(0 0) (trans '(1 0) 0 1 T))
	       (getvar 'aunits)
	       16
	     )
	     ""
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 10 of 11
_gile
in reply to: _gile

This one allows to choose the UCS in a little dialog.

 

(defun c:ucstwist (/ listbox lst ucs)
  
  (defun listbox (title keys / tmp file dcl_id choice)
  (setq	tmp  (vl-filename-mktemp "tmp.dcl")
	file (open tmp "w")
  )
  (write-line
    (strcat "ListBox:dialog{label=\"" title "\";")
    file
  )
  (write-line "spacer;:list_box{key=\"lst\";}spacer;ok_only;}" file)
  (close file)
  (setq dcl_id (load_dialog tmp))
  (if (not (new_dialog "ListBox" dcl_id))
    (exit)
  )
  (start_list "lst")
  (mapcar 'add_list keys)
  (end_list)
  (action_tile "lst" "(setq choice (nth (atoi $value) keys)) (done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete tmp)
  choice
)
  
  (while (setq ucs (tblnext "UCS" (null ucs)))
    (setq lst (cons (cdr (assoc 2 ucs)) lst))
  )
  (setq lst (cons "World" (cons "Previous" (reverse lst))))
  (if (setq ucs (listbox "UCS Twist" lst))
    (progn
      (cond
	((= ucs "World") (command-s "_.ucs" "_world"))
	((= ucs "Previous") (command-s "_.ucs" "_previous"))
	(T (command-s "_.ucs" "_restore" ucs))
      )
      (command-s "_.dview"
		 ""
		 "_twist"
		 (angtos
		   (angle '(0 0) (trans '(1 0) 0 1 T))
		   (getvar 'aunits)
		   16
		 )
		 ""
      )
    )
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 11
lecheconagujas
in reply to: _gile

Both of these are awesome. The one with the dialog box is more than I would have dared to ask for! Thanks a lot.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report