Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

[V8i C# MDL] How do I marshal a MDL structure in C#

$
0
0

I'm trying to pass two stuctures to the mdPattern_addAssociative2 function in C#. The structures are the PatternParams and DwgHatchDefLIne. I have the following defined:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
        public unsafe struct dwgHatchDefLine
        {
            public double angle;
            public BCOM.Point2d through;
            public BCOM.Point2d offset;
            public short nDashes;
            public double[] dashes;
        };

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
        public unsafe struct dwgHatchDef
        {
            public short             nDefLines;
            public dwgHatchDefLine[] deprecatedLines;
            public double pixelSize;
            public short islandStyle;
        }

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1))]
        public unsafe struct patternParams
            {
                public BCOM.Matrix3d rMatrix;                        // pattern coordinate system       
                public BCOM.Point3d offset;                         // offset from element origin      
                public double space1;                         // primary (row) spacing           
                public double angle1;                         // angle of first hatch or pattern
                public double space2;                         // secondary (column) spacing      
                public double angle2;                         // angle of second hatch           
                public double scale;                          // pattern scale                   
                public double tolerance;                      // pattern tolerance               
                public char[] cellName;                       // name of cell - if id is zero    
                public Int64 cellId;                         // ID of shared cell definition    
                public UInt32 modifiers;                      // pattern modifiers bit field     
                public int minLine;                        // min line of multi-line element  
                public int maxLine;                        // max line of multi-line element  
                public UInt32 color;                          // pattern / hatch color           
                public UInt32 weight;                         // pattern / hatch weight          
                public UInt32 style;                          // pattern / hatch line style      
                public short holeStyle;                      // hole parity style               
                public dwgHatchDef dwgHatchDef;                    // DWG style hatch definition      
                public BCOM.Point3d origin;                         // hatch origin
            }


I declare the patternParams like this:

patternParams pParams = new patternParams();
pParams.modifiers |= 0x4000;
pParams.dwgHatchDef.nDefLines = 1;
pParams.dwgHatchDef.deprecatedLines = new dwgHatchDefLine[1];
pParams.dwgHatchDef.deprecatedLines[0].angle = 0;
pParams.dwgHatchDef.deprecatedLines[0].nDashes = 1;
pParams.dwgHatchDef.deprecatedLines[0].dashes = new double[1];
pParams.dwgHatchDef.deprecatedLines[0].dashes[0] = 6.5;

BCOM.Matrix3d pRot = new BCOM.Matrix3d();
BCOM.Point3d  pOrg = new BCOM.Point3d();
int modelRef = app.ActiveDesignFile.MdlModelRefP();

Finally i call the function


mdlPattern_addAssociative(ref pMsed, -1, -1, ref pParams, ref pOrg, ref pRot, 2, modelRef);

The DllImport definition:

static extern void mdlPattern_addAssociative2( ref int edPP, int line1, int line2, int pParams, int pHatchLine, ref BCOM.Point3d pPoint, ref BCOM.Matrix3d pRot, int option, int modelRef);     

Should the pParams and pHatchLine be type int or IntPtr whcih i have seen. I'm sure i should be using the Marash.PtrToStructure somewhere but not sure how it all fits together.  Also the arrays within the structures, in the mdl.h they are defined with a particular size so should I be Marshalling them with a size? If so, can I still allocate them with the new keword to populate them?


Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>