.NET

Reply
Contributor
f.roels
Posts: 12
Registered: ‎09-23-2011
Message 1 of 5 (273 Views)
Accepted Solution

UCS by block

273 Views, 4 Replies
09-23-2011 05:58 AM

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-

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 -

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 -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,595
Registered: ‎06-29-2007
Message 2 of 5 (269 Views)

Betreff: UCS by block

09-23-2011 06:15 AM in reply to: f.roels

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
f.roels
Posts: 12
Registered: ‎09-23-2011
Message 3 of 5 (265 Views)

Betreff: UCS by block

09-23-2011 06:27 AM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,595
Registered: ‎06-29-2007
Message 4 of 5 (243 Views)

Betreff: UCS by block

09-24-2011 02:19 AM in reply to: f.roels

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
f.roels
Posts: 12
Registered: ‎09-23-2011
Message 5 of 5 (240 Views)

Betreff: UCS by block

09-24-2011 03:14 AM in reply to: Alfred.NESWADBA

thanks a lot

 

Filip

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.