.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UCS by block

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
f.roels
623 Views, 4 Replies

UCS by block

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-

4 REPLIES 4
Message 2 of 5
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 5
f.roels
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

Message 4 of 5
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 5
f.roels
in reply to: Alfred.NESWADBA

thanks a lot

 

Filip

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost