get cell angle MVBA

MicroStation Connect update 16

MVBA

I am trying to get cell rotation in the active dgn. When I move through the file and gather data, if a cell has a rotation of 12.25, ee.Current.AsSharedCellElement.Rotation.RowZ.Z does not report it correctly or am I missing something? The value comes back as 1. Here is a snippet of the code I am exploring with:

Sub GetData()
    Dim myElem As element
    Dim ee As ElementEnumerator
    Dim myFilter As New ElementScanCriteria
    Dim myCollection As New Collection
    Dim RangeBox As Range3d

'set filter criteria - set what to look for
'This module is set to only look at cells excuding all other element types
    myFilter.ExcludeAllTypes
    myFilter.IncludeType msdElementTypeSharedCell  'Shared Cells
    myFilter.IncludeType msdElementTypeCellHeader   'Normal Cells
    
    'Start scanning file
    Set ee = ActiveModelReference.GraphicalElementCache.Scan(myFilter)
    Do While ee.MoveNext
        'Shared Cells
        If ee.Current.Type = msdElementTypeSharedCell Then
            RangeBox = ee.Current.AsSharedCellElement.Range
            CellName = ee.Current.AsSharedCellElement.Name
            'CellName = LCase(ee.Current.AsSharedCellElement.Name) 'CASE SENSITIVE
            CellType = ee.Current.AsSharedCellElement.Type
            CellScale = ee.Current.AsSharedCellElement.Scale.X & ", " & ee.Current.AsSharedCellElement.Scale.Y
            CellScaleX = ee.Current.AsSharedCellElement.Scale.X
            CellScaleY = ee.Current.AsSharedCellElement.Scale.Y
            CellScaleZ = ee.Current.AsSharedCellElement.Scale.Z
            CellOrigin = ee.Current.AsSharedCellElement.Origin.X & ", " & ee.Current.AsSharedCellElement.Origin.Y & ", " & ee.Current.AsSharedCellElement.Origin.Z
            CellOriginX = ee.Current.AsSharedCellElement.Origin.X
            CellOriginY = ee.Current.AsSharedCellElement.Origin.Y
            CellOriginZ = ee.Current.AsSharedCellElement.Origin.Z
            CellRotation = ee.Current.AsSharedCellElement.Rotation.RowZ.Z
        End If
    Loop
End Sub

Parents
  • Hi Marc,

    be aware this is general Developers and Programming forum. Because your question is about MicroStation, I recommend to move it to MicroStation Programming forum. To move existing discussion to another forum, use More > Move tool, available under your original post.

    I also recommend to use standardized subject format, described in the best practices. In your case, the subject [MStn CE U16.0 VBA] Get cell angle provides all mandatory information (product, version, language/API) in efficient way.

    I am trying to get cell rotation in the active dgn.

    It would be better to share code snippet with "get rotation from shared cell" only, not complete, because it requires extra work to analyze code with no relation to discussed problem.

    Here is a snippet of the code I am exploring with:

    I would recommend to scan for shared cells and normal cells independently, but maybe it only because it is testing code.

    if a cell has a rotation of 12.25,

    A cell rotation cannot be 12.25, when formulated this way:

    • Do you mean rotation around what axis? Or you work with 2D model (which you did not tell), so it is always rotation around Z axis?
    • 12.25 of what? Degrees? Be aware all angles in API are expressed in radians.
    ee.Current.AsSharedCellElement.Rotation.RowZ.Z does not report it correctly or am I missing something?

    It looks like a misunderstanding how rotation matrix works. If I remember right, when the matrix contains rotation around Z axis, the last value in last row is always 1.

    It is even written in VBA Matrix3d documentation: Matrix3d encompasses a set of Double values. However, you should not attempt to interpret these values directly. (because it requires to understand what exactly every value in matrix does).

    For simple rotation (no mirror, skew, around Z axis only), you can use Matrix3dIsXYRotation method. When more complex analysis is necessary, methods like Matrix3dIsXRotationYRotationZRotationScale and Matrix3dIsXYRotationSkewAndScale can help you.

    With regards,

      Jan

Reply
  • Hi Marc,

    be aware this is general Developers and Programming forum. Because your question is about MicroStation, I recommend to move it to MicroStation Programming forum. To move existing discussion to another forum, use More > Move tool, available under your original post.

    I also recommend to use standardized subject format, described in the best practices. In your case, the subject [MStn CE U16.0 VBA] Get cell angle provides all mandatory information (product, version, language/API) in efficient way.

    I am trying to get cell rotation in the active dgn.

    It would be better to share code snippet with "get rotation from shared cell" only, not complete, because it requires extra work to analyze code with no relation to discussed problem.

    Here is a snippet of the code I am exploring with:

    I would recommend to scan for shared cells and normal cells independently, but maybe it only because it is testing code.

    if a cell has a rotation of 12.25,

    A cell rotation cannot be 12.25, when formulated this way:

    • Do you mean rotation around what axis? Or you work with 2D model (which you did not tell), so it is always rotation around Z axis?
    • 12.25 of what? Degrees? Be aware all angles in API are expressed in radians.
    ee.Current.AsSharedCellElement.Rotation.RowZ.Z does not report it correctly or am I missing something?

    It looks like a misunderstanding how rotation matrix works. If I remember right, when the matrix contains rotation around Z axis, the last value in last row is always 1.

    It is even written in VBA Matrix3d documentation: Matrix3d encompasses a set of Double values. However, you should not attempt to interpret these values directly. (because it requires to understand what exactly every value in matrix does).

    For simple rotation (no mirror, skew, around Z axis only), you can use Matrix3dIsXYRotation method. When more complex analysis is necessary, methods like Matrix3dIsXRotationYRotationZRotationScale and Matrix3dIsXYRotationSkewAndScale can help you.

    With regards,

      Jan

Children