I'm not understanding ucs method!?!

I'm not understanding ucs method!?!

Anonymous
Not applicable
406 Views
11 Replies
Message 1 of 12

I'm not understanding ucs method!?!

Anonymous
Not applicable
Can anywone explain the following behaviour to me?
It does not seem to work as I would expect. (that's what I get for having
expectations!)

I start with blank dwg
create a box(3dsolid) at 0,0,0
W = 3, L = 2, H = 4
orbit to sw iso more or less to see the box and ucs icon

'...heres a function to change to 'right side ucs'
'...it should 'supposedly' change the current ucs (from world or ?) to right
side ucs
'... it then returns the new ucs object
Function UcR() As AcadUCS
Dim Neworigin(0 To 2) As Double
ThisDrawing.Utility.GetPoint Neworigin, "Pick a point, El Cadilator!"
'pick the lower right corner of box (world coord: 2,0,0)

Dim xAxisPoint(2) As Double
Dim YAxisPoint(2) As Double
Dim ucsObjR As AcadUCS


xAxisPoint(0) = Neworigin(0): xAxisPoint(1) = Neworigin(1) + 1:
xAxisPoint(2) = Neworigin(2)
YAxisPoint(0) = Neworigin(0): YAxisPoint(1) = Neworigin(1):
YAxisPoint(2) = Neworigin(2) + 1

Set ucsObjR = ThisDrawing.UserCoordinateSystems.Add(Neworigin,
xAxisPoint, YAxisPoint, "UCSRIGHT")
ThisDrawing.ActiveUCS = ucsObjR
'when the ucs origin did not change to the origin I sent to the add method
'i thought I could force it to move to the correct point with the next line
but it did no good....
'ucsObj.origin = Neworigin
'that line has no effect...(that I can see)

ThisDrawing.ActiveViewport.UCSIconOn = True
ThisDrawing.ActiveViewport.UCSIconAtOrigin = True
'the next line seems like a bug to me....
'ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
' I would expect that command to move the ucs icon to the point I picked for
new origin, instead it changes the ucs to world and zooms to a previous view
'if I comment out that line, the ucs changes to right side but the ucs icon
does not move to world 2,0,0 as it should according to the function above,
but rather it stays at 0,0,0 and just rotates to the right side direction.
...what am I not understanding???

Set UcR = ucsObjR
End Function


...here's a sub to test the above
Sub UCSMatrixTest2()
' Define a new UCS and turn on the UCS icon at the origin.
Dim ucsObj As AcadUCS
Set ucsObj = UcR 'ucs right hand side

'again this line, whether inside the function or out here, causes the ucs
change to fail and the drawing to revert to world ucs
ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport

Dim TransMatrix As Variant
TransMatrix = GetUCSMatrix(ucsObj)
Dim strMsg As String

strMsg = "Ucs matrix is: " & vbCr

Dim i As Integer
Dim j As Integer

'another weirdness (to me)
'this line bombs with subscript out of range (even though it's not)
'transmatrix has a lbound of 0 and ubound of 3
'when i = 0 I get a subscript out of range
'For i = LBound(TransMatrix) To UBound(TransMatrix)

For i = 0 To 3

'and likewise this line bombs like the above with subscript out of range
'even though it's not!
'For j = LBound(TransMatrix(i)) To UBound(TransMatrix(i))

'this hard code works and since I know the size of the matrix i guess that's
ok, except I thought it was bad practice to hard code arbitrary values and
it seems like I should be able to read the actual array size with lbound and
ubound?!?
For j = 0 To 3

strMsg = strMsg & TransMatrix(i, j) & ", "
Next j
strMsg = strMsg & vbCr
Next i
MsgBox strMsg, vbOKOnly, "Ace Destruction Co. Ucs Matrix Report"

End Sub
0 Likes
407 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Mark,



I don't have time to try your code at the moment, but a couple of ideas spring to mind:



> ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport

> I would expect that command to move the ucs icon to the point I picked for new origin, instead it changes the ucs to world and zooms to a previous view

My understanding is that this command only affects the view and not the UCS, so your origin could be set and facing where you want, but the view is from/to somewhere else.



> the ucs changes to right side but the ucs icon does not move to world 2,0,0 as it should according to the function above, but rather it stays at 0,0,0 and just rotates to the right side direction

I've noticed that sometimes AutoCAD "thinks" you won't see the origin icon properly if it puts it where it exists, so it puts it somewhere else and just rotates it correctly. If you zoom out enough the icon jumps to the right spot. This might be what's happening here.



> For j = LBound(TransMatrix(i)) To UBound(TransMatrix(i))

If you lookup the VBA Help for LBound you'll see there is an optional second parameter for using when there are multiple dimensions in an array. Not sure if that is the entire problem here but I think it is at least part of it.



Hope this helps.



Regards



Wayne Ivory

IT Analyst Programmer

Wespine Industries Pty Ltd
0 Likes
Message 3 of 12

Anonymous
Not applicable
An afterthought - LBound and UBound could fail if the TransMatrix Variant hasn't been initialised at the point where you're testing the bounds. This seems unlikely since you said it works hardcoded, but it is something else to consider. You could try doing a Debug.Print TypeName(TransMatrix) prior to the loop to see what you get.



Regards



Wayne
0 Likes
Message 4 of 12

Anonymous
Not applicable
Hi Wayne,

Thanks for the ideas. I'll check them
out


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

An afterthought - LBound and UBound could fail if the TransMatrix Variant
hasn't been initialised at the point where you're testing the bounds.

 

at the point of error:

a watch window shows the array to be an array of
four arrays, each with four elements and the tool tip shows the array is good
also,

must be the other idea you said about another
parameter, i'll check it out

 

 This seems unlikely since you said it works hardcoded, but it is
something else to consider. You could try doing a Debug.Print
TypeName(TransMatrix) prior to the loop to see what you get.

  
Regards
  
Wayne

 

do you agree that hardcoding is not the right way
to do it?

do you work the night shift or are you on the
other side of the globe? england?
0 Likes
Message 5 of 12

Anonymous
Not applicable
Who said programmers don't have a sense of humor?



> , "Pick a point, El Cadilator!"
0 Likes
Message 6 of 12

Anonymous
Not applicable
Wayne's right.
LBound(TransMatrix(i))
should be
LBound(TransMatrix, 2) to get the second index ubound and lbound

Also, your code would not run for me until i replaced
GetUCSMatrix(ucsObj) with ucsObj.GetUCSMatrix


James
0 Likes
Message 7 of 12

Anonymous
Not applicable
The way you have your GetPoint set up is not setting the value of
Neworigin -- instead it's being used as the base point, and the return value
is being lost into the vacuum of VBA. Try:

Dim Neworigin As Variant
Neworigin = ThisDrawing.Utility.GetPoint(, "Pick a point, El Cadilator!")

xAxisPoint = ...
YAxisPoint = ...

MsgBox "X: " & xAxisPoint(0) & ", " & xAxisPoint(1) & ", " &
xAxisPoint(2) & vbCrLf & _
"Y: " & YAxisPoint(0) & ", " & YAxisPoint(1) & ", " &
YAxisPoint(2)


James
0 Likes
Message 8 of 12

Anonymous
Not applicable
The following code moves and rotates the UCS icon to wherever I pick. I'm
not sure exactly which changes made the code seem to work for me now... it
just decided to start working.

Also, here's the UCS-related variables, in case it was changing one of those
that made it work.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Command: setvar
Enter variable name or [?] : ?

Enter variable(s) to list <*>: ucs*

UCSAXISANG 90
UCSBASE ""
UCSFOLLOW 0
UCSICON 3
UCSNAME "UCSRIGHT" (read only)
UCSORG 0.0000,1.5000,4.0000 (read only)
UCSORTHO 1
UCSVIEW 1
UCSVP 1
UCSXDIR 0.0000,1.0000,0.0000 (read only)
UCSYDIR 0.0000,0.0000,1.0000 (read only)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

James

Function UcRnew() As AcadUCS
Dim Neworigin As Variant
Neworigin = ThisDrawing.Utility.GetPoint(, "Pick a point, El
Cadilator!")

Dim xAxisPoint(2) As Double
Dim YAxisPoint(2) As Double
Dim ucsObjR As AcadUCS

xAxisPoint(0) = Neworigin(0): xAxisPoint(1) = Neworigin(1) + 1:
xAxisPoint(2) = Neworigin(2)
YAxisPoint(0) = Neworigin(0): YAxisPoint(1) = Neworigin(1):
YAxisPoint(2) = Neworigin(2) + 1

Set ucsObjR = ThisDrawing.UserCoordinateSystems.Add(Neworigin,
xAxisPoint, YAxisPoint, "UCSRIGHT")

ThisDrawing.ActiveUCS = ucsObjR

ThisDrawing.ActiveViewport.UCSIconOn = True
ThisDrawing.ActiveViewport.UCSIconAtOrigin = True

Set UcRnew = ucsObjR
End Function

Sub UCSMatrixTest2()
Dim ucsObj As AcadUCS
Set ucsObj = UcRnew
ThisDrawing.ActiveUCS = ucsObj

ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport

End Sub
0 Likes
Message 9 of 12

Anonymous
Not applicable
Aha! Thank you James,

That's how I had it at first, then I glanced at some help example and saw
that point arg and my brain thought it was a byref arg getting set by the
getpoint function (something like getxdata), DUH!!! DOUBLE DUH!!!

Thanks for clearing the cobwebs.
Mark



"James Belshan" wrote in message
news:23217ABB274C2BB23F7D109D96788EBE@in.WebX.maYIadrTaRb...
> The way you have your GetPoint set up is not setting the value of
> Neworigin -- instead it's being used as the base point, and the return
value
> is being lost into the vacuum of VBA. Try:
0 Likes
Message 10 of 12

Anonymous
Not applicable
fasculinating!
I copy paste your code and if I comment out the one line

> ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport

then it does move the ucs icon, but if I leave it in, it doesn't move it
(actually it moves it really fast then back again - I can just see the flash
of it changing position and returning)
leaving the line in causes the icon to be greyed out and dimmed also!
taking the line out causes the icon to be white as usual!
the ucs direction does change, but the location of the icon stays at (or
actually returns to) wcs 0,0,0
in my case the ucs point reads: id Specify point: X = 0.0000 Y =
0.0000 Z = -3.5200

My sys vars are identical to yours. Your code works exactly as mine does
(once I fixed my getpoint - thanks to you).
that one line is the buggaboo!?!
weirdness rulsez!

"James Belshan" wrote in message
news:7282E4B6B4758CAA1202D94103C15E9C@in.WebX.maYIadrTaRb...
> The following code moves and rotates the UCS icon to wherever I pick. I'm
> not sure exactly which changes made the code seem to work for me now... it
> just decided to start working.

>
> End Sub
>
>
0 Likes
Message 11 of 12

Anonymous
Not applicable
If I open up a new drawing, make a few 3d lines, and then run the VBA macro,
I get exactly the behavior you're talking about, and it's that
ActiveViewport line that makes the UCS icon move back and go gray. So there
must be some viewport setting that I changed in my first DWG file that
allowed the ActiveViewport line to work. If you really want to track it
down I can send you the DWG that works OK with the ActiveVP line... or you
can just comment out the line : ).

James
0 Likes
Message 12 of 12

Anonymous
Not applicable
Hi James,

I'm perfectly ok with commenting the line!
:-) that's one less line to worry about!
It's just my not knowing why that bugs me....doubt if I could figure it out
from your dwg but what the heck, if you want to send it I might play around
with it a little.
mark at atreng dot com

any way I appreciate your helping me out on this one.
It seems like that line should be necessary, but since it's not ...who needs
it?

the more I think about it, the viewport is really independent of the ucs, I
can be in any ucs while viewing from any one of an infinite number of
viewpoints. So maybe I'm incorrectly extrapolating from some vague help
examples, and from that point of view the line shouldn't be necessary. The
viewport must be responding to it's target or direction or center when
issuing a 'refresh' of the active viewport, and that wouldn't really have
anything to do with the ucs. Unless I issued a 'plan' command.

thanks again,
Mark

"James Belshan" wrote in message
news:074BF2EBA7E8985A142F767BB4BBC171@in.WebX.maYIadrTaRb...
> If I open up a new drawing, make a few 3d lines, and then run the VBA
macro,
> I get exactly the behavior you're talking about, and it's that
0 Likes