c# raster mirror

Hi all,

I am creating a addin (C#) in MicroStation and I am looking for a good way to mirror a raster vertically. The raster is already attached in the rastermanager. Of course is it possible with a keyin, but is there also an nice method in C# code?

Regards, Aart

  • Hi Aart,

    please follow best practices and define exactly the version you use. Solution in V8i can be very different from solution in CONNECT Edition...

    Regards,

      Jan

  • I am using Bentley Descartes CONNECT edition Update 2 - Version 10.02.00.22

  • Unknown said:
    I am looking for a good way to mirror a raster vertically. I am using Bentley Descartes CONNECT

    The DgnPlatformNet RasterAttachmentEdit class may help.

    RasterAttachmentEdit.ApplyTransform (transformInfo) lets you apply a transform to an element. All you have to do is to write a mirror transform into a TransformInfo object.  It looks like TransformInfo.SetMirrorPlane was created just for you!

     
    Regards, Jon Summers
    LA Solutions

  • Hi John,

    In Visual Studio 2015 I have attached and using the reference Bentley.DgnPlatformNET.  But I'm not able to reach the RasterAttachmentEdit class. And as I look in the options of RasterAttachmentEdit I can't find the ApplyTransform object.

    This is the first time I use Visual Studio for an add-in, so I am a little confused how much options and references there are...

    Regards, Aart

  • Unknown said:
    I am using Bentley Descartes CONNECT edition Update 2 - Version 10.02.00.22
    And as I look in the options of RasterAttachmentEdit I can't find the ApplyTransform object.

    You're using a rather old version of MicroStation CONNECT!  I was quoting the DgnPlatformNet documentation for v10.06.  The .NET APIs have made great strides since the first release of CONNECT.

     
    Regards, Jon Summers
    LA Solutions

  • Unknown said:
    You're using a rather old version of MicroStation CONNECT!

    is not using MicroStation CONNECT, but MicroStation Descartes. And Descartes CONNECT Edition Update 2 is the most recent version of the product. I am not quite sure on what MicroStation version it's based, but probably not Update 6 (maybe Update 5?).

    Unknown said:
    In Visual Studio 2015 I have attached and using the reference Bentley.DgnPlatformNET. 

    It's not enough. You should always check NET API documentation (typically at least both DgnPlatformNET and MSTNPlatformNET.chm) to find what assembly should be referenced.

    Regards,

      Jan

  • Unknown said:
    I can't find the ApplyTransform object

    It's documented as living in this nested namespace:

    Bentley.DgnPlatformNET.Elements.RasterAttachmentEdit

    I created a simple project, and added a reference to Bentley.DgnPlatformNET.  That added the using statement below to make RasterAttachmentEdit accessible.

    using Bentley.DgnPlatformNET.Elements;
    
    namespace RasterEditExample
    {
      public class RasterEdit
      {
        RasterAttachmentEdit rasterAttachmentEditor_;
        IRasterAttachmentEdit* handler;
        Element element;
        RasterEdit()
        {
          rasterAttachmentEditor_ = new RasterAttachmentEdit(handler, element);
        }
      }
    }

    I note that it's in a DgnPlatform Managed Library. You have to treat IRasterAttachmentEdit in some special way, because it's passed as a pointer (in C#!). You'll have to investigate this further! 

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    I have tried to follow your example. I encountered an issue with the RasterAttachmentEdit constructor being protected, so I tried using a derived class, but Visual Studio is still giving me an error about the protection level. What can I do to solve this?

        unsafe class RasterEdit : BDM.RasterAttachmentEdit 
        {
            BDM.RasterAttachmentEdit rasterAttachmentEditor_;
                
            BD.IRasterAttachmentEdit* handler;
            BDM.Element element;
    
            public RasterEdit(BD.IRasterAttachmentEdit* handler, BDM.Element element) : base(handler, element)
            {
                rasterAttachmentEditor_ = new BDM.RasterAttachmentEdit(handler, element);
            }

  • Unknown said:
    I encountered an issue with the RasterAttachmentEdit constructor being protected

    You're blazing a new trail through areas of DgnPlatformNet that few have travelled.

    Usually, a private or protected contructor indicates that an object cannot be created directly but must be obtained via a cast or a factory method.  In this case, method GetAsRasterAttachmentEdit probably does what you want:

    GetAsRasterAttachmentEdit

    Provides methods for inspecting and editing the current raster attachment properties of an element. Implemented by Element handlers that define a raster attachment.

     
    Regards, Jon Summers
    LA Solutions

  • Sorry for the late response, but this is some sample code we created that may provide a good starting point to mirror a raster.

            private static void TEST_RasterCreate()
            {
                // Set file and model for raster attachment
                DgnFile dgnfile = Session.Instance.GetActiveDgnFile();
                DgnModel model = Session.Instance.GetActiveDgnModel();
    
                // Set base transform and extents
                DTransform3d transform = DTransform3d.Identity;
                DPoint2d extentInUOR = new DPoint2d(100.0, 100.0);
                string szFilename = "MyImage";
                string szFileSpec = "C:/Temp/MyImage.png";
    
                // Set document and properties
                DgnDocumentMoniker moniker = DgnDocumentMoniker.CreateFromRawData(szFilename, szFileSpec, null, RasterAttachmentQuery.GetSearchPath(model), false, null);
                RasterFrameElement rfe = new RasterFrameElement(model, null, moniker, transform, extentInUOR);
    
                // Modify raster element properties
                RasterAttachmentEdit rasterEdit = rfe.AsRasterAttachmentEdit();
                rasterEdit.AttachDescription = "Description";
                rasterEdit.LogicalName = "LogicalName";
                rasterEdit.SnappableState = true;
                rasterEdit.OpenReadWrite = true;
    
                // Apply Y axis mirror transform to raster.
                // NOTES:
                // 1.) The transform could have been provided during raster create step
                // 2.) You could also pass this transform to TransformInfo.SetMirrorPlane
                // 3.) DTransform3d in the form of: ColX, ColY, ColZ.  Use -1 to negate/mirror the value
                DTransform3d transMirrorY = new DTransform3d(1, 0, 0, 0, -1, 0, 0, 0, 1);
                Debug.WriteLine("transform: " + transMirrorY.ToString());
                rasterEdit.SetTransform(transMirrorY);
    
                // Save changes to raster
                rfe.AddToModel();
                rasterEdit.ReplaceInModel(rfe);
            }

    HTH,
    Bob