PDA

View Full Version : Aligned World UCS


dkennard
2007-07-10, 04:09 AM
Hi Everyone,

I'm having trouble getting the following test routine to give me the correct results when working with a set of drawings that have the World UCS aligned to a model space object, it works fine on drawings that don't have a rotated UCS. The routine should place a circle in paper space over the point selected in model space.

I have tried several different variants of TRANS using WCS as the from argument to no avail, has anyone got any other ideas, how can I tell (programmatically) if the UCS has been rotated/aligned?

(defun c:tid ()
(command "mspace")
(setq pt1 (getpoint "\nPick a point: "))
(command "pspace")
(setq pt2 (trans pt1 2 3))
(command "_circle" pt2 5 "")
(princ)
)

Thanks.

Adesu
2007-07-10, 07:39 AM
Hi dkennard,
maybe you want like this

(defun c:tid (/ tm pt1 pt2)
;(command "mspace")
(setq tm (getvar "tilemode"))
(if
(= tm 0)
(setvar "tilemode" 1)
) ; if
(setq pt1 (getpoint "\nPick a point: "))
;(command "pspace")
(setvar "tilemode" 0)
(setq pt2 (trans pt1 2 3))
(command "_circle" pt2 5 "")
(setvar "tilemode" tm)
(princ)
)



Hi Everyone,

I'm having trouble getting the following test routine to give me the correct results when working with a set of drawings that have the World UCS aligned to a model space object, it works fine on drawings that don't have a rotated UCS. The routine should place a circle in paper space over the point selected in model space.

I have tried several different variants of TRANS using WCS as the from argument to no avail, has anyone got any other ideas, how can I tell (programmatically) if the UCS has been rotated/aligned?

(defun c:tid ()
(command "mspace")
(setq pt1 (getpoint "\nPick a point: "))
(command "pspace")
(setq pt2 (trans pt1 2 3))
(command "_circle" pt2 5 "")
(princ)
)

Thanks.

dkennard
2007-07-10, 08:34 AM
Adesu,

I tried your code and I get the same results if I'm working on a view that has a rotated UCS then the resultant point is miles away from where I'm expecting it to be, if I'm working on a plan view its fine.

I have had a dig around and the system variable VIEWTWIST appears to give my the rotation angle of the viewport (MVIEW), however I'm not sure how to translate the selected point + the view rotation to give me the same point in paper space.

I'll take a copy of an example drawing and post it so you can see what I'm getting at.

Thanks Dave.

Adesu
2007-07-10, 08:57 AM
Hi Dave,
Without seeing your drawing, I 'm getting trouble to solve your problem, post here your drawing before and after revised, I wait it.

dkennard
2007-07-10, 09:04 AM
Hi Dave,
Without seeing your drawing, I 'm getting trouble to solve your problem, post here your drawing before and after revised, I wait it.


Here is the drawing, if you run my original code and select a point on the non rotated viewport everything is sweet, however if run the code on the rotated viewport the circle is miles away.

Adesu
2007-07-10, 09:49 AM
I just test your drawing, that result as your comment, I think the problem maybe in trans function.

Here is the drawing, if you run my original code and select a point on the non rotated viewport everything is sweet, however if run the code on the rotated viewport the circle is miles away.

kennet.sjoberg
2007-07-10, 10:52 AM
You must involve WCS

(defun c:tid (/ ptU ptW ptD )
(command "mspace")
(setq ptU (getpoint "\nPick a point: ")) ; Get the point in current coordinatesystem WCS/UCS
(setq ptW (trans ptU 1 0 )) ; Convert from current to WCS
(command "pspace")
(setq ptD (trans ptW 2 3 )) ; Convert from WCS to DCS
(command "_circle" ptD 5 )
(princ)
)


: ) Happy Computing !

kennet

dkennard
2007-07-10, 03:18 PM
Kennet,

I just tried your code, at home on Acad 2000 and I get the same results ie non rotated viewports are fine, viewports with a rotation are not.

I will try it at work in the morning and let you know if its any different using acad 2006.

Cheers

Dave.

dkennard
2007-07-11, 02:25 AM
You must involve WCS

OK I tried your code at work this morning on AC2006 and it gives me the same results as I've been getting, it places the rotated views point miles away from where it should be.

The point ptW gives the exactly the same point as pt2 in my original post so it looks like the additional transformation is not required.

So I'm back where I started, gonna do some more digging as I'm sure I'm missing something fundamental.

Thanks.

dkennard
2007-07-11, 08:23 AM
I've worked out that the TRANS functions are working kind of, just the PSDCS offset is about 11012344mm off in the Y direction. The attached file shows points selected on the rotated views, the magenta triangle is the result (although offset). So TRANS is getting the relative geometry correct except with a massive offset.

This is beginning to drive me mad so any help or suggestions are welcomed.

Thanks.

dkennard
2007-07-11, 09:13 AM
The TARGET system variable appears to have something to do with the offset, initially the none rotated viewport works fine with Kennets code and TARGET is (0.0, 0.0, 0.0) if I DIVEW/TWIST the view to any angle then TARGET changes to (193761.0,7626394.3,0.00)and does not change back to (0.0,0.0,0.0) if I change the TWIST angle back to 0.

TARGET (Read-only)
Type: 3D-point
Saved in: Drawing
Initial value: 0.0000,0.0000,0.0000
Stores the location (as a UCS coordinate) of the target point for the current viewport.

David.Hoole
2007-07-11, 11:52 AM
Dave

Here's my code for creating and setting up viewports. It's a little long in the tooth I'm afraid.
It took me a loooong time to figure out the Target problem too. But this works for me. The trick is to set the Target property of the viewport object before setting the coordinates:




(defun mvp (drgunits / l1 sc1 sc2 om1 vp1 p1 p2 p2p p2m)
(if (= (getvar "tilemode") 0)
(progn
(setq om1 (getvar "orthomode"))
(setvar "orthomode" 0)
(setq l1 (getvar "clayer"))
(setvar "cmdecho" 0)
(if (= (tblsearch "layer" "Z000G_MVIEW") nil)
(command "._-layer" "m" "Z000G_MVIEW" "c" 4 "Z000G_MVIEW" "p" "n" "Z000G_MVIEW" "")
(command "._-layer" "t" "Z000G_MVIEW" "s" "Z000G_MVIEW" "p" "n" "Z000G_MVIEW" "")
)
(setvar "cmdecho" 1)
(command "._mview")
(while (> (getvar "cmdactive") 0)
(command pause)
)
(setvar "cmdecho" 0)
;;;*********************************
(command "._mspace")
(command "._dview" "" "TW" 0.0 "")
(setq Vportobj (vlax-ename->vla-object (entlast)))
(vlax-put-property vportobj 'Target (vlax-3d-point (list 0.0 0.0 0.0)))
(command "._zoom" "e")
(command "._pspace")
(setq vp1 (entget (entlast))
p2p (cdr (assoc 10 vp1))
p2m (trans p2p 3 2)
)
;;;*********************************
(command "._mspace")
(command "._zoom" "e")
(initget 7)
(setq sc1 (getint "\nEnter required scale: "))
(cond
((= drgunits "mm")(setq sc2 (strcat (rtos (/ 1.0 sc1)) "xp")))
((= drgunits "m")(setq sc2 (strcat (rtos (* 1000.0 (/ 1.0 sc1))) "xp")))
)
(initget 1)
(setq p1 (getpoint "\nPick centre of view:"))
(terpri)
(setq p2m (trans p2p 3 2))
(command "._pan" p1 p2m)
(command "._zoom" sc2)
(setvar "orthomode" om1)
(setvar "ucsfollow" 0)
(command "._pspace")
(command "._clayer" l1)
(setvar "cmdecho" 1)
)
(princ "\nThis command can only be used in PaperSpace!")
)
(princ)
)



Hope you find this useful.

dkennard
2007-07-12, 09:15 AM
David, thanks for the code i did find something interesting playing with the view port data in the drawing, when a DVIEW/TWIST is applied the only changes made to the definition of the viewport in the drawing data base are elements 12, 17,51 and 90. When DV TWIST'd Viewport center points in DCS and WCS switch places, when the target is reset they switch again altough the X and Y elements of the WCS are transposed. Does anyone else see this, Im using Vanilla 2006.

I'm going to manipulate the viewport data and apply a twist angle only and see what happens.

DXF CODE DEFINITION
12 = View Center point in DCS
17 = View target point in WCS
51 = View Twist angle (in radians)
90 = Viewport Status bit-coded

NON ROTATED VIEWPORT
(12 193761.0 7.62639e+006 0.0)
(17 0.0 0.0 0.0)
(51 . 0.0)
(90 . 835680)

DVIEW TWIST ROTATED VP (90)
(12 0.0 0.0 0.0)
(17 193761.0 7.62639e+006 0.0)
(51 . 1.5708)
(90 . 819296)

TARGET RESET (to 0.0 0.0 0.0)
(12 7.62639e+006 -193761.0 0.0)
(17 0.0 0.0 0.0)
(51 . 1.5708)
(90 . 819296)

dkennard
2007-07-17, 04:07 AM
SOLUTION: When using the TRANS function you must be in the correct space before the translation is performed.

(defun c:tid ()
(command "mspace")
(setq ptU (getpoint "nPick a point: ")) ; Get the point in current coordinatesystem WCS/UCS
(setq ptW (trans ptU 1 0 )) ; Convert from current to WCS
(setq ptD (trans ptW 0 2 )) ; Convert from WCS to DCS
(command "pspace")
(setq ptP (trans ptD 2 3 )) ; Convert from DCS to PSDCS
(command "_circle" ptP 5 )
(princ)
)

Which is what Kennet gave us a week ago and I've only just got my brain into gear. Thanks to all who helped.