Microstation C# Update 16 : Set Scale and Active Angle

We want to scale an element and set its active angle.

We are applying the below chunk of code for scale of element. Is this the appropriate way to do it?

// where center is origin of the element and scale value as 0.25, 0.50, 0.75
DTransform3d transform = DTransform3d.FromUniformScaleAndFixedPoint(center, scale);
TransformInfo transformationInfo = new TransformInfo(transform);
newelement.ApplyTransform(transformationInfo);

How to set the active angle for an element and rotate it by that active angle?

Regards,

Varsha

  • How to set the active angle for an element and rotate it by that active angle?

    The active angle is a property of MicroStation, not an element.  Get the current value from the ActiveSettings object.

    Some elements, such as a cell or text, have a rotation property. In those cases, you can apply a rotation directly to the element.

    More generally, use a transform as you have done for the scale.  Create a rotation matrix and import that into your DTransform3d.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Varsha,

    We want to scale an element and set its active angle.

    I have to repeat, using other words, what Jon wrote, because using wrong terminology makes the question unclear.

    • Active angle is drawing aid, available at runtime as double value, used by some tools. No element has active angle assigned, but active angle can be used as one from settings, used when an element is placed using specific user tool.
    • Some elements (only a few) have rotation property, e.g. cell, text or text node. It is angle, stored as part of the element itself.
    We are applying the below chunk of code for scale of element. Is this the appropriate way to do it?

    In general, yes, even though there are plenty of dependencies: What exactly you want to achieve, what element is transformed etc.

    How to set the active angle for an element and rotate it by that active angle?

    Transformation matrix, represented by TransformInfo object, can handle all transformation you need: scale, rotation, movement...

    It is beyond scope of this discussion to explain vector algebra and how transformation matrix should be used to transform elements.

    Also, be aware that all transformations are applied in relation to coordinate system origin, so typically element must be moved to origin, rotated, scaled (or whatever else) and moved back.

    With regards,

      Jan

  • Hi Jon,

    We tried the code as below for rotation, but plate did not overturn. We are applying this on the text element, and unable to find direct properties on text element of setting rotation or angle.

    // center is  the origin of the text element
    // First rotate around X-Axis with fixed origin
    DMatrix3d xrotation = DMatrix3d.Rotation((int)Enum.Axis.X, Angle.FromRadians(0));
    DTransform3d rxTransform3D = DTransform3d.FromMatrixAndFixedPoint(xrotation, center);
    TransformInfo rxtransform = new TransformInfo(rxTransform3D);
    newelement.ApplyTransform(rxtransform);
    
    // Then rotate around Y-Axis with fixed origin
    DMatrix3d yrotation = DMatrix3d.Rotation((int)Enum.Axis.Y, Angle.FromRadians(0));
    DTransform3d ryTransform3D = DTransform3d.FromMatrixAndFixedPoint(yrotation, center);
    TransformInfo rytransform = new TransformInfo(ryTransform3D);
    newelement.ApplyTransform(rytransform);
    
    // Then rotated around Z-Axis with fixed origin
    DMatrix3d zrotation = DMatrix3d.Rotation((int)Enum.Axis.Z, Angle.FromRadians(0));
    DTransform3d rzTransform3D = DTransform3d.FromMatrixAndFixedPoint(zrotation, center);
    TransformInfo rztransform = new TransformInfo(rzTransform3D);
    newelement.ApplyTransform(rztransform);

    Are we doing something wrong in this?

  • plate did not overturn

    What does that mean?  You mention a text element , so what is a 'plate'?

    unable to find direct properties on text element of setting rotation or angle

    You're working in 3D space.  Use a matrix to describe rotation, because a 3D matrix is designed to work in 3D space.  An angle is meaningless in 3D space.

    It is beyond scope of this discussion to explain vector algebra and how transformation matrix should be used to transform elements

    We mention some relevant books here.

    We tried the code as below for rotation...
    // First rotate around X-Axis with fixed origin
    // Then rotate around Y-Axis with fixed origin
    // Then rotated around Z-Axis with fixed origin

    Rather than your piecemeal approach, build a final matrix by multiplying the individual X, Y and Z matrices.  Then apply that final matrix to your transform.  You'll find matrix multiplication methods in the API.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Varsha,

    We tried the code as below for rotation

    I do not see any rotation set in your code, because all rotation angles are set to 0 radians.

    Are we doing something wrong in this?

    Yes, my feeling is there is some misunderstanding how vector and matrix algebra work.

    I would suggest to start in 2D and check step by step all transformations work as expected, and in the next step, to move to 3D (which in general is much more complex).

    Without testing, I guess the error is in the angle used to define rotation, but there are more things I am not sure about:

    • What is expected result of FromMatrixAndFixedPoint? You want to rotate and move the element together?
    • It is better to define one transformation upfront and to apply it at once. This "step by step" transformation can lead to unexpected results, and is good for debugging only (because partial results can be verified).
    and unable to find direct properties on text element of setting rotation or angle.

    I recommend to study description of Text and TextBlock API in C++ documentation, because text is one from the most complex elements (with very complex API) in MicroStation.

    Regards,

      Jan