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

UCS to Viewport's FrontZ

1 REPLY 1
SOLVED
Reply
Message 1 of 2
kpennell
374 Views, 1 Reply

UCS to Viewport's FrontZ

Hello All,

 

I have the following developed.

 

(command "ucs" "World")

(setq CVPort (getvar "cvport"))
(setq VPEnt (ssget "X" (list (cons 0 "VIEWPORT")(cons 69 CVPort))))
(setq VPEnt (ssname VPEnt 0))
(setq VPEnt (entget VPEnt))
(setq FrontClip (cdr (assoc 43 VPEnt)))

 

(setq GetDirection (getvar "viewdir"))
(setq GetDirectionX (atof (rtos (car GetDirection) 2 8)))
(setq GetDirectionY (atof (rtos (cadr GetDirection) 2 8)))
(setq GetDirectionZ (atof (rtos (caddr GetDirection) 2 8)))

(cond
((and (< GetDirectionX 0)(= GetDirectionY 0)(= GetDirectionZ 0))(command "ucs" "Z" "270" "ucs" "X" "90"))
((and (> GetDirectionX 0)(= GetDirectionY 0)(= GetDirectionZ 0))(command "ucs" "Z" "90" "ucs" "X" "90"))
((and (= GetDirectionX 0)(< GetDirectionY 0)(= GetDirectionZ 0))(command "ucs" "X" "90"))
((and (= GetDirectionX 0)(> GetDirectionY 0)(= GetDirectionZ 0))(command "ucs" "Z" "180" "ucs" "X" "90"))
((and (= GetDirectionX 0)(= GetDirectionY 0)(> GetDirectionZ 0)))
((and (= GetDirectionX 0)(= GetDirectionY 0)(< GetDirectionZ 0))(command "ucs" "Z" "270" "ucs" "X" "90"))
(T(Alert "Your view in this viewport is not a true plan view!")(command "undo" "Back")(exit))
)

 

(setq MoveZ (list 0.0 0.0 FrontClip))
(command "ucs" "New" MoveZ)

 

In theory, this should work, but for some reason it's not.  Do I need a target camera calculation or something?

1 REPLY 1
Message 2 of 2
kpennell
in reply to: kpennell

So I figured out that the front clipping plane location is a calculation of the Target Point (X or Y or Z depending on which way you're looking), and the "FrontZ".

 

So if anyone wants to set their UCS to the front in "true" plan-type views, here is my contribution.  Organized so I can understand it 🙂

 

(command "ucs" "World")

(setq CVPort (getvar "cvport"))
(setq VPEnt (ssget "X" (list (cons 0 "VIEWPORT")(cons 69 CVPort))))
(setq VPEnt (ssname VPEnt 0))
(setq VPEnt (entget VPEnt))
(setq FrontClip (cdr (assoc 43 VPEnt)))
(setq TargetX (car (cdr (assoc 17 VPEnt))))
(setq TargetY (cadr (cdr (assoc 17 VPEnt))))
(setq TargetZ (caddr (cdr (assoc 17 VPEnt))))

(setq GetDirection (getvar "viewdir"))
(setq GetDirectionX (atof (rtos (car GetDirection) 2 8)))
(setq GetDirectionY (atof (rtos (cadr GetDirection) 2 8)))
(setq GetDirectionZ (atof (rtos (caddr GetDirection) 2 8)))

(cond
((and (< GetDirectionX 0)(= GetDirectionY 0)(= GetDirectionZ 0)(< (- TargetX FrontClip) 0))

   (command "ucs" "Z" "270" "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (abs (- TargetX FrontClip)) 0.0001))))
((and (< GetDirectionX 0)(= GetDirectionY 0)(= GetDirectionZ 0)(> (- TargetX FrontClip) 0))

   (command "ucs" "Z" "270" "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (* (abs (- TargetX FrontClip)) -1) 0.0001))))
((and (> GetDirectionX 0)(= GetDirectionY 0)(= GetDirectionZ 0)(> (+ TargetX FrontClip) 0))

   (command "ucs" "Z" "90" "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (abs (+ TargetX FrontClip)) 0.0001))))

((and (> GetDirectionX 0)(= GetDirectionY 0)(= GetDirectionZ 0)(< (+ TargetX FrontClip) 0))

   (command "ucs" "Z" "90" "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (* (abs (+ TargetX FrontClip)) -1) 0.0001))))
((and (= GetDirectionX 0)(< GetDirectionY 0)(= GetDirectionZ 0)(< (- TargetY FrontClip) 0))

   (command "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (abs (- TargetY FrontClip)) 0.0001))))
((and (= GetDirectionX 0)(< GetDirectionY 0)(= GetDirectionZ 0)(> (- TargetY FrontClip) 0))

   (command "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (* (abs (- TargetY FrontClip)) -1) 0.0001))))
((and (= GetDirectionX 0)(> GetDirectionY 0)(= GetDirectionZ 0)(< (+ TargetY FrontClip) 0))

   (command "ucs" "Z" "180" "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (* (abs (+ TargetY FrontClip)) -1) 0.0001))))
((and (= GetDirectionX 0)(> GetDirectionY 0)(= GetDirectionZ 0)(> (+ TargetY FrontClip) 0))

   (command "ucs" "Z" "180" "ucs" "X" "90")

   (setq MoveZ (list 0.0 0.0 (- (abs (+ TargetY FrontClip)) 0.0001))))
((and (= GetDirectionX 0)(= GetDirectionY 0)(< GetDirectionZ 0)(< (- TargetZ FrontClip) 0))

   (command "ucs" "Y" "180")

   (setq MoveZ (list 0.0 0.0 (- (abs (- TargetZ FrontClip)) 0.0001))))
((and (= GetDirectionX 0)(= GetDirectionY 0)(< GetDirectionZ 0)(> (- TargetZ FrontClip) 0))

   (command "ucs" "Y" "180")

   (setq MoveZ (list 0.0 0.0 (- (* (abs (- TargetZ FrontClip)) -1) 0.0001))))
((and (= GetDirectionX 0)(= GetDirectionY 0)(> GetDirectionZ 0)(< (+ TargetZ FrontClip) 0))

   (setq MoveZ (list 0.0 0.0 (- (* (abs (+ TargetZ FrontClip)) -1) 0.0001))))
((and (= GetDirectionX 0)(= GetDirectionY 0)(> GetDirectionZ 0)(> (+ TargetZ FrontClip) 0))

   (setq MoveZ (list 0.0 0.0 (- (abs (+ TargetZ FrontClip)) 0.0001))))
(T(Alert "Your view in this viewport is not a true plan view!"))
)

(setq ViewAngle (/ (* (getvar "viewtwist") 180) pi))
(command "ucs" "Z" (* ViewAngle -1))
    
(setq OldOsnap (getvar "osmode"))
(setvar "osmode" 0)
(command "ucs" "New" MoveZ)
(setvar "osmode" OldOsnap)

 

Use it abuse it as you see fit.

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

Post to forums  

Autodesk Design & Make Report

”Boost