The UCS X axis and Y axis are not perpendicular ???

The UCS X axis and Y axis are not perpendicular ???

Anonymous
Not applicable
1,861 Views
5 Replies
Message 1 of 6

The UCS X axis and Y axis are not perpendicular ???

Anonymous
Not applicable
hi

i am trying to create a ucs from the current ucs, however, when i use the
ucs variables i get this error
"The UCS X axis and Y axis are not perpendicular", could some steer me in
the right direction please...

'code

Set eCurrentUcs =
ThisDrawing.UserCoordinateSystems.Add(ThisDrawing.GetVariable("ucsorg"),
ThisDrawing.GetVariable("ucsxdir"), ThisDrawing.GetVariable("ucsydir"),
"TempCurrent")


thanks in advance

cheers

mark
0 Likes
1,862 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
I'm no guru in this area, but I think the problem is that you are confusing vectors with points. UCSXDIR returns a vector (or direction), whereas the UserCoordinatesSystems.Add method requires "a point on the positive X axis of the UCS". I can't recall (and don't have time to research) how to apply the vector to the origin to determine a point but I think this should get you on the way.



One other observation: rather than using system variables I would use the ActiveUCS object and the related properties Origin, XVector and YVector.



Regards



Wayne Ivory

IT Analyst Programmer

Wespine Industries Pty Ltd
0 Likes
Message 3 of 6

Anonymous
Not applicable
Actually I think the method I used to determine an X-point was by adding the components of the origin and the vector together like this.


Const X As Byte = 0, Y As Byte = 1, Z As Byte = 2

Sub Test()
Dim CurrentUCS as AcadUCS, NewUCS as AcadUCS
Dim orig() as Double, xvec() as Double, yvec() as Double
Dim xpnt(X To Z) as Double, ypnt(X To Z) as Double

Set CurrentUCS = ThisDrawing.ActiveUCS
orig = CurrentUCS.Origin
xvec = CurrentUCS.XVector
yvec = CurrentUCS.YVector

xpnt(X) = orig(X) + xvec(X)
xpnt(Y) = orig(Y) + xvec(Y)
xpnt(Z) = orig(Z) + xvec(Z)
ypnt(X) = orig(X) + yvec(X)
ypnt(Y) = orig(Y) + yvec(Y)
ypnt(Z) = orig(Z) + yvec(Z)

Set NewUCS = ThisDrawing.UserCoordinateSystems.Add(orig, xpnt, ypnt, "TempCurrent")
End Sub

NB: Straight out of my head and untested.



Regards



Wayne
0 Likes
Message 4 of 6

Anonymous
Not applicable
Interesting how questions seem to travel in packs. Here's a similar
question from a few days ago.

http://groups.google.com/groups?threadm=7677A80E1D7B6DCE63BFD206697C48B6%40i
n.WebX.maYIadrTaRb

The short answer is that it seems the test for perpendicularity is very
stringent. Wayne's idea to replace the UCSXDIR with UCS.XVector may get you
more precision and solve your problem. Please let us know if it does not.
Because another possible solution would be a function that:
- takes 2 vectors (that aren't parallel) as input
- finds a 3rd vector that is in the plane formed by the first two vectors,
but is perpendicular to the first one.
- use the 1st and 3rd vectors as the UCS X and Y vectors of a new UCS
object.

If the math is all done with Doubles, maybe the new (3rd) Y vector would be
perpendicular enough to avoid the error message....

Please keep us ifnormed about how your project progresses.

James
0 Likes
Message 5 of 6

Anonymous
Not applicable
This may not be the answer your looking for, but i found a while ago when creating a new ucs by copying details from an old one, that i first had to create it with an origin point of 0,0,0 plus the x- and y-axis directions, then i just changed the location of the origin to where i wanted. When i tried to do it all at once it gave me the error that you're experiencing.

e.g code along the lines of (& not bothering with obvious declarations):

origin(0) = 0: origin(1) = 0: origin(2) = 0
Set ucsObj = DwgUCSColl.Add(origin, XVector, YVector, NewUCSname)
ucsObj.origin = neworigin

Don't know why, just some funny bug in the way Autodesk wrote the object i guess.
0 Likes
Message 6 of 6

Anonymous
Not applicable
Well... I wrote the function (Add_UCS_improved) I mentioned in my previous
post, and a test function to demonstrate it.
It solves the problem of the vectors having to be perfectly perpendicular
(by making its own perpendicular Y vector)

I have not thoroughly checked it, though, so if there are errors it could be
due to what Terence mentioned in his post. If that's the case, this could
still be used to make the ucs at the origin, without running into the
perpendicularity problem.

Good luck, check for word-wrap, hope this helps you out.
James


Sub test_Improved_UCS()

' Create a UCS named "New_UCS" in current drawing
Dim ucsObj As AcadUCS
Dim origin(0 To 2) As Double
Dim xAxisPnt(0 To 2) As Double
Dim yAxisPnt(0 To 2) As Double

' Define the UCS #1
origin(0) = 4#: origin(1) = 5#: origin(2) = 3#
xAxisPnt(0) = 5#: xAxisPnt(1) = 5#: xAxisPnt(2) = 3#
yAxisPnt(0) = 4.5: yAxisPnt(1) = 6.7: yAxisPnt(2) = 3#

' call the improved ADD function
Set ucsObj = Add_UCS_improved(origin, xAxisPnt, yAxisPnt, "New_UCS")
MsgBox ucsObj.Name & " has been added." & vbCrLf & _
"Origin: " & ucsObj.origin(0) & ", " & ucsObj.origin(1) _
& ", " & ucsObj.origin(2) & vbCrLf & _
"X Axis: " & ucsObj.XVector(0) & ", " & ucsObj.XVector(1) _
& ", " & ucsObj.XVector(2) & vbCrLf & _
"Y Axis: " & ucsObj.YVector(0) & ", " & ucsObj.YVector(1) _
& ", " & ucsObj.YVector(2), , "Add Example"

' Define the UCS #2
origin(0) = 0.1: origin(1) = 0.2: origin(2) = 0.3
xAxisPnt(0) = 0.25: xAxisPnt(1) = 0.1: xAxisPnt(2) = 0.15
yAxisPnt(0) = 0.13: yAxisPnt(1) = -0.06: yAxisPnt(2) = 0.2

' Add the UCS to the UserCoordinatesSystems collection
Set ucsObj = Nothing
Set ucsObj = Add_UCS_improved(origin, xAxisPnt, yAxisPnt, "NewUCS#2")
MsgBox ucsObj.Name & " has been added." & vbCrLf & _
"Origin: " & ucsObj.origin(0) & ", " & ucsObj.origin(1) _
& ", " & ucsObj.origin(2) & vbCrLf & _
"X Axis: " & ucsObj.XVector(0) & ", " & ucsObj.XVector(1) _
& ", " & ucsObj.XVector(2) & vbCrLf & _
"Y Axis: " & ucsObj.YVector(0) & ", " & ucsObj.YVector(1) _
& ", " & ucsObj.YVector(2), , "Add Example"

End Sub


Function Add_UCS_improved(origin() As Double, xAxisPnt() _
As Double, yAxisPnt() As Double, ucsName As String) As AcadUCS
' origin, xAxisPnt, and yAxisPnt must all be dimmed (0 to 2)

Dim ucsObj As AcadUCS
Dim xAxisVec(0 To 2) As Double
Dim yAxisVec(0 To 2) As Double
Dim perpYaxisPnt(0 To 2) As Double
Dim xCy As Variant, perpYaxisVec As Variant

xAxisVec(0) = xAxisPnt(0) - origin(0)
xAxisVec(1) = xAxisPnt(1) - origin(1)
xAxisVec(2) = xAxisPnt(2) - origin(2)
yAxisVec(0) = yAxisPnt(0) - origin(0)
yAxisVec(1) = yAxisPnt(1) - origin(1)
yAxisVec(2) = yAxisPnt(2) - origin(2)

xCy = Cross3D(xAxisVec, yAxisVec)
perpYaxisVec = Cross3D(xCy, xAxisVec)

perpYaxisPnt(0) = perpYaxisVec(0) + origin(0)
perpYaxisPnt(1) = perpYaxisVec(1) + origin(1)
perpYaxisPnt(2) = perpYaxisVec(2) + origin(2)

Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPnt,
perpYaxisPnt, ucsName)
Set Add_UCS_improved = ucsObj

End Function

Function Cross3D(A As Variant, B As Variant) As Variant
' A and B must be dimensioned Double(0 to 2)
Dim C(0 To 2) As Double
C(0) = A(1) * B(2) - A(2) * B(1)
C(1) = -(A(0) * B(2) - A(2) * B(0))
C(2) = A(0) * B(1) - A(1) * B(0)
Cross3D = C
End Function
0 Likes