Author Topic: vc++ code to c#  (Read 1799 times)

0 Members and 1 Guest are viewing this topic.

saranya

  • Guest
vc++ code to c#
« on: May 23, 2009, 07:34:32 AM »
Hi,

I am having the following vc++ code which will read the input from Layertable assign to variable of user-defined class cLayerInfo.

Code: [Select]
AcDbLayerTableRecord *pLay;
CStringArray asLayers;
CLayerInfo info;
info.color = pLay->color();
info.linetypeObjectId = pLay->linetypeObjectId();
info.lineWeight = pLay->lineWeight();
CMapLayerInfo m_mapLayerInfo;
m_mapLayerInfo.SetAt( asLayers.GetAt(i), info );
pLay->close();

The user defined class file in vc++ is

Code: [Select]
class CLayerInfo
{
public:
CLayerInfo() : lineWeight(AcDb::kLnWt000) {}
virtual ~CLayerInfo() {}

AcCmColor color;
AcDb::LineWeight lineWeight;
AcDbObjectId linetypeObjectId;
};




In c# I have created the class file as follows

Code: [Select]
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

using System.Runtime.InteropServices;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;

[assembly: CommandClass(typeof(SBK.CLayerInfo))]
namespace SBK
{
    class CLayerInfo
    {
       
        private Color color;
        private LineWeight lineweight;
        private ObjectId linetypeObjectId=new ObjectId();
        public static void CLayerInfo(Color color, LineWeight lineweight, ObjectId linetypeObjectId)
        {
            this.color=color;
            this.lineweight=lineweight;
            this.linetypeObjectId=linetypeObjectId;
        }                 
    }
}



and I have called the class file in another class file as follows

Code: [Select]
LayerTableRecord pLay = (LayerTableRecord)trans.GetObject(obj, OpenMode.ForRead);
CLayerInfo info = new CLayerInfo(pLay.Color, pLay.LineWeight, pLay.LinetypeObjectId);

But how to implement the below lines
Code: [Select]
CMapLayerInfo m_mapLayerInfo;
m_mapLayerInfo.SetAt( asLayers.GetAt(i), info ).


When I go for the definition for cMapLayerInfo it takes me into another header file which contains the following code

Code: [Select]
typedef CMap <CString, LPCSTR, CLayerInfo, CLayerInfo&> CMapLayerInfo;
If I go for CMap definition it takes me into afxtempl.h which is predefined header file.
Can anyone tell me how to convert the above code in c#.
Please it is urgent.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6941
  • AKA Daniel
Re: vc++ code to c#
« Reply #1 on: May 25, 2009, 05:41:07 AM »
Welcome to TheSwamp, I think there a few C# examples of playing with layers in the .NET area. As far as the CMap question, I might use the Dictionary class.

saranya

  • Guest
Re: vc++ code to c#
« Reply #2 on: May 26, 2009, 05:59:52 AM »
Can you provide sample code?
« Last Edit: May 26, 2009, 06:06:42 AM by saranya »