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
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.
Mark Winegar said: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.
Mark Winegar said: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.
Mark Winegar said:if a cell has a rotation of 12.25,
A cell rotation cannot be 12.25, when formulated this way:
Mark Winegar said: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
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
I bypassed the entire matrix confusion by using the CreatePropertyHandler to extract the data more easily. This way as I am moving through the collection I can get the "Angle" property from the element in the Properties dialog. The matrix method requires knowledge on interpreting and then converting the data correctly. The PropertyHandler bypasses all of that.
Hi Mark,
Mark Winegar said:I bypassed the entire matrix confusion
It's good to know you find solution.
But, vector algebra and matrix operations (rotation and transformation matrices) is core mandatory knowledge for any CAD and GIS development. In fact, many operations cannot be implemented using them.
Mark Winegar said:The matrix method requires knowledge on interpreting and then converting the data correctly.
In fact, it is incorrect conclusion.
Matrices can be used without interpreting values directly, and as I wrote in previous answer, it is even not recommended. VBA API offers plenty of methods that do it, so e.g. when you need to check whether element is rotated around Z only, and what angle is it, you need to call proper methods only, which does not require to know that rotation around Z is represented by what cells in matrix and whether it is sin() or cos() value.
Mark Winegar said:The PropertyHandler bypasses all of that.
Yes, but the is pretty high cost you have to pay:
It is much slower and also specific limitations exist (even though not effective in the discussed case). There is a reason why PropertyHandler is recommended as "last chance" approach, when required functionality does not exists in API (e.g. to read EC data and element attributes, not published in API).