Hi all,
VB.NET is pretty new to me (I'm sorry if I ask stupid questions). But now I have a problem with UCS in VB.NET.
I try to write a routine in VB.NET which place the UCS accoording u block (sames as the AutoCAD command: UCS - Object)
I had succeeded in VBA. But don't know how to start in VB.NET.
code:
Dim bref As BlockReference = DirectCast(tr.getObject(BlockRefID, OpenMode.ForRead), BlockReference)
ed.CurrentUserCoorinateSystem = bref.Ecs
This is not the way. The UCS stays the same, while the block was rotated 15°. (I think this reflects the UCS when the block was placed)
-Filip-
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Hi,
check this:
Public Shared Function setUcsToBlockRefMatrix() As Boolean Dim tRetVal As Boolean = False Dim tAcadDoc As Document = Nothing Dim tAcadDocLock As DocumentLock = Nothing Dim tTrAct As Transaction = Nothing Try tAcadDoc = Application.DocumentManager.MdiActiveDocument tAcadDocLock = tAcadDoc.LockDocument tTrAct = tAcadDoc.TransactionManager.StartTransaction Dim tEntPrompt As PromptEntityResult = tAcadDoc.Editor.GetEntity(vbNewLine & "Select BlockRef: ") If tEntPrompt.Status = PromptStatus.OK Then If tEntPrompt.ObjectId.ObjectClass.DxfName = "INSERT" Then Dim tBlRef As BlockReference = CType(tTrAct.GetObject(tEntPrompt.ObjectId, OpenMode.ForRead), BlockReference) tAcadDoc.Editor.CurrentUserCoordinateSystem = tBlRef.BlockTransform tTrAct.Commit() Else tAcadDoc.Editor.WriteMessage("Select BlockRef - selected entity was no BlockRef.") End If Else tAcadDoc.Editor.WriteMessage("Select BlockRef - input canceled") End If Catch ex As Exception Call MsgBox("Error occured!" & vbNewLine & ex.Message) Finally If tTrAct IsNot Nothing Then tTrAct.Dispose() : tTrAct = Nothing If tAcadDocLock IsNot Nothing Then tAcadDocLock.Dispose() : tAcadDocLock = Nothing End Try Return tRetVal End Function
HTH, - alfred -
thanks
it works perfectl. Have you got a piece of code that you can rotate the UCS around its X, Y and Z axis
best
Filip
Hi,
sorry, lost this thread ;(
>> Have you got a piece of code that you can rotate the UCS around its X, Y and Z axis
One sample is enough?
'first a MOVE/ROTATE/SCALE-transformation to be equal to BlockReference Dim tMat1 As Matrix3d = tBlRef.BlockTransform 'now a definition for a rotation of 45° where rotation-axis = Z-axis Dim tMat2 As Matrix3d = Matrix3d.Rotation(Math.PI / 4, New Vector3d(0, 0, 1), Point3d.Origin) 'combine these Dim tMat3 As Matrix3d = tMat1 * tMat2 'set UCS tAcadDoc.Editor.CurrentUserCoordinateSystem = tMat3
HTH, - alfred -