I wrote a little program that creates a circle on a face of a cube. To do that I need to get the ECS of the cube which Entity.ECS should do, but it just gives me WCS. I got the program to work by using Autocad to set the UCS to that of the cube entity, but I want to get the ECS directly from the entity in .net. In the attached image I've printed out the value of current UCS which was set to the cube entity, and then I print the value of the ECS i got using entity.ECS - Both these should be identical, but they're not! Why does entity.ECS give me WCS or what am I missing here?
<CommandMethod("testECS")>
Public Sub testECS()
Dim pnt1 As Point3d
Dim cir As Circle
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim ed As Editor = acDoc.Editor
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Try
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim peo As PromptEntityOptions = New PromptEntityOptions("" & vbLf & "Select object : ")
peo.SetRejectMessage("" & vbLf & "Invalid selection...")
Dim pEntrs As PromptEntityResult = ed.GetEntity(peo)
If (PromptStatus.OK <> pEntrs.Status) Then
Return
End If
Dim cubeId As ObjectId = pEntrs.ObjectId
Dim cubeEnt As Entity = CType(acTrans.GetObject(cubeId, OpenMode.ForRead), Entity)
Dim curECS As Matrix3d = ed.CurrentUserCoordinateSystem
Dim cubeECS As Matrix3d = cubeEnt.Ecs
ed.WriteMessage(vbCrLf & "Current UCS: " & curECS.ToString)
ed.WriteMessage(vbCrLf & "Cube UCS: " & cubeECS.ToString & vbCrLf)
'' Create a circle
pnt1 = New Point3d(0.6858, 0.6858, 0.0)
cir = New Circle(pnt1, Vector3d.ZAxis, 0.5)
cir.TransformBy(cubeECS)
cir.TransformBy(curECS)
acBlkTblRec.AppendEntity(cir)
acTrans.AddNewlyCreatedDBObject(cir, True)
acTrans.Commit()
Catch ex As Exception
ed.WriteMessage("Error: " & ex.Message)
acTrans.Abort()
End Try
End Using
End Sub