> Anything you can do on the command line you can do through the utility
> object. you build up the string of text you would type at the command
> window and pass it to the vba object and away it goes. ...
Which is exactly why you don't do it that way except for extreme situations
of which this isn't one of them. Using sendcommand also means your app
loses all contact with the command so you have no idea when it stops, if an
error occurs, etc.
Paul, here is VB.NET COM InterOp source code that you'll need to revise
for vb6/vba. For example, you need to supply a definition for PI and use
ATN for arctangent instead of Math.ATAN. The code also assumes a valid
cadDoc object is reference [ThisDrawing for vba] and it uses a polyline.
You just need to changeg it for a Line - get the startpoint/endpoint, calc
the angle between then add 90degrees in radians for the UCS "Y" value.
Public Sub UCSByObject(ByVal LwPoly As AcadLWPolyline)
Dim objUCS As AcadUCS
Dim objUCSs As AcadUCSs
Dim objUtil As AcadUtility
Dim dPnt() As Double
Dim dY() As Double
Dim dX() As Double
Dim strPrmt As String
Dim dNormalAngle As Double
objUCSs = cadDoc.UserCoordinateSystems
objUtil = cadDoc.Utility
dNormalAngle = getAngleBetweenTwoPoints(LwPoly.Coordinate(0),
LwPoly.Normal)
dPnt = LwPoly.Coordinate(0)
ReDim Preserve dPnt(2)
dPnt(2) = 0
dX = objUtil.PolarPoint(dPnt, dNormalAngle, 1)
dY = objUtil.PolarPoint(dPnt, dNormalAngle + Degrees2Radians(90), 1)
objUCS = objUCSs.Add(dPnt, dX, dY, "myUCS")
cadDoc.ActiveUCS = objUCS
End Sub
Public Function getAngleBetweenTwoPoints(ByVal dPT1 As Object, ByVal dPT2
As Object) As Double
'ArcTangent
Dim deltaX1 As Double = dPT1(0) - dPT2(0)
Dim deltaY1 As Double = dPT1(1) - dPT2(1)
Dim calcAngle As Double
If deltaX1 = 0 Then
'on vertical axis
If deltaY1 > 0 Then
calcAngle = Math.PI / 2
ElseIf deltaY1 < 0 Then
calcAngle = 3 / 2 * Math.PI
Else
'Zero-length vector
Return 0
Exit Function
End If
ElseIf deltaX1 > 0 Then
'quadrants I and IV
If deltaY1 >= 0 Then 'quadrant I
calcAngle = Math.Atan(deltaY1 / deltaX1)
Else 'quadrant IV
calcAngle = 2 * Math.PI + Math.Atan(deltaY1 / deltaX1)
End If
ElseIf deltaX1 < 0 Then
'quadrants II and III
calcAngle = Math.PI + Math.Atan(deltaY1 / deltaX1)
End If
Return calcAngle
End Function
Public Function Degrees2Radians(ByVal dValue As Double)
Degrees2Radians = dValue * Math.PI / 180
End Function
-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...