Try UCSV from autocad command line.
It prompts you to select two points.
It creates a ucs using the first point selected (but with zero elevation) as the origin and
the xaxis passing through the second point (also with zero elevation)
the yaxis is passing vertical above the origin.
Public Class class_AutoCAD_Utilities
<CommandMethod("UCSv")> PublicSub UCSvertical()
SetToWCS()'routine of mine-code comes next
Dim Pt1 As Autodesk.AutoCAD.Geometry.Point3d = CAD.NET.SelectPointAsPoint3D("Select origin ")
If IsNothing(Pt1) ThenExit Sub
Dim Pt2 As Autodesk.AutoCAD.Geometry.Point3d = CAD.NET.SelectPointAsPoint3D("Select a point on axis X ")
If IsNothing(Pt2) ThenExit Sub
Dim ORGN AsNew Autodesk.AutoCAD.Geometry.Point3d(Pt1.X, Pt1.Y, 0)
Dim Xaxis AsNew Autodesk.AutoCAD.Geometry.Vector3d((Pt2.X - Pt1.X), (Pt2.Y - Pt1.Y), 0)
Dim Yaxis AsNew Autodesk.AutoCAD.Geometry.Vector3d(0, 0, 1)
Dim CS AsNew Autodesk.AutoCAD.Geometry.CoordinateSystem3d(ORGN, Xaxis, Yaxis)
Dim acadDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acadDB As Autodesk.AutoCAD.DatabaseServices.Database = acadDoc.Database
Dim acadEditor As Autodesk.AutoCAD.EditorInput.Editor = acadDoc.Editor
Using acadTRNS As Autodesk.AutoCAD.DatabaseServices.Transaction = acadDB.TransactionManager.StartTransaction()
Dim acadUCSTbl As Autodesk.AutoCAD.DatabaseServices.UcsTable
acadUCSTbl =
CType(acadTRNS.GetObject(acadDB.UcsTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.UcsTable)
Dim acadUCSTblRec As Autodesk.AutoCAD.DatabaseServices.UcsTableRecord = New Autodesk.AutoCAD.DatabaseServices.UcsTableRecord
acadUCSTbl.UpgradeOpen()
acadUCSTbl.Add(acadUCSTblRec)
acadTRNS.AddNewlyCreatedDBObject(acadUCSTblRec,
True)
With acadUCSTblRec
.Origin = CS.Origin
.XAxis = CS.Xaxis
.YAxis = CS.Yaxis
EndWith
acadTRNS.Commit()
EndUsing
UCS.SetActiveViewportToUCS(CS, True)'routine of mine-code comes next
EndSub
PublicFunction SetToWCS(OptionalByVal ShowNameNotFoundMessage AsBoolean = True) AsBoolean
Dim acadDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acadDB As Autodesk.AutoCAD.DatabaseServices.Database = acadDoc.Database
Try
Using acadTRNS As Autodesk.AutoCAD.DatabaseServices.Transaction = acadDB.TransactionManager.StartTransaction
Dim acadVPortsTableRecord As Autodesk.AutoCAD.DatabaseServices.ViewportTableRecord = CType(acadTRNS.GetObject(acadDoc.Editor.ActiveViewportId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.ViewportTableRecord)
acadVPortsTableRecord.SetUcsToWorld()
acadDoc.Editor.UpdateTiledViewportsFromDatabase()
acadTRNS.Commit()
ReturnTrue
EndUsing
Catch ex AsException
If ShowNameNotFoundMessage Then MsgBox("Failed to set WCS current" + vbNewLine + ex.Message, MsgBoxStyle.Information, "Info")
ReturnFalse
EndTry
EndFunction
PublicFunction SetActiveViewportToUCS(ByVal UCSis As Autodesk.AutoCAD.Geometry.CoordinateSystem3d, OptionalByVal ShowErrorMessage AsBoolean = True) AsBoolean
Dim acadDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acadDB As Autodesk.AutoCAD.DatabaseServices.Database = acadDoc.Database
Try
Using acadTRNS As Autodesk.AutoCAD.DatabaseServices.Transaction = acadDB.TransactionManager.StartTransaction
Dim acadVPortsTableRecord As Autodesk.AutoCAD.DatabaseServices.ViewportTableRecord = CType(acadTRNS.GetObject(acadDoc.Editor.ActiveViewportId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Autodesk.AutoCAD.DatabaseServices.ViewportTableRecord)
acadVPortsTableRecord.SetUcs(UCSis.Origin, UCSis.Xaxis, UCSis.Yaxis)
acadDoc.Editor.UpdateTiledViewportsFromDatabase()
acadTRNS.Commit()
Return True
EndUsing
Catch ex AsException
If ShowErrorMessage Then MsgBox("Failed to set UCS current" + vbNewLine + ex.Message, MsgBoxStyle.Information, "Info")
ReturnFalse
EndTry
EndFunction
End Class