vc++ code to c# autocad
Hi,I am having the following vc++ code which will read the input from Layertable assign to variable of user-defined class cLayerInfo.
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
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
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;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
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
CMapLayerInfo m_mapLayerInfo;
m_mapLayerInfo.SetAt( asLayers.GetAt(i), info ). If I go for deinition of CMapLayerInfo it is taking me to the another afxtempl.hfile.
Can anyone tell me how to convert the above code in c#.
Please it is urgent. There is not typically a lot of C++ conversation on this forum.This may be a good question for the crew over at http://www.theswamp.org.
That being said, however, let me take a stab at it:
It appears that the C# code would require another class comparable to “CMapLayerInfo”.
Presumably, that class has a method setup to iterate through all the layers named in asLayers and transfer to them the information stored info.
If that actually is the case then I imagine your C# class CLayerInfo should make public the variables color, lineweight, and (perhaps) objecteId.Or, if validation is an issue, provide the appropriate Get/Set procedures. Whatever you have mentioned is absolutely correct.When I go for the definition for cMapLayerInfo it takes me into another header file which contains the following code
typedef CMapCMapLayerInfo;
If I go for CMapdefinition it takes me into afxtempl.h which is predefined header file.
So I cannot create class for cMapLayerInfo. Is there any other way to make use of afxtempl.h in c# It is possible to access some of the UnManaged objects and functions from Managed code using Platform Invoke.It is bit of an arcane art so you may have some luck at the Swamp, Autodesk’s Discussions ObjectARX forum, or even on the Through the Interface blog (http://through-the-interface.typepad.com/through_the_interface/2006/07/calling_objecta.html and
http://through-the-interface.typepad.com/through_the_interface/2008/08/using-the-pinvo.html).I even have a query (towards the bottom) on that second blog listing.
Unfortunately, the return advise may not come in a timely fashion. This is a bit of a coincidental thread don't ya think Sean... There are a lot of us all headed in a similar direction. :wink: Thank you for the guidance Seant. Also I want to convert the follwoing vc++ to c#. Can you help me in this.
removeSSgetFilterInputContextReactor( curDoc(), pAcSSGetFilterSBKMirror );
addSSgetFilterInputContextReactor( curDoc(), pAcSSGetFilterSBKMirror );
here pAcSSGetFilterSBKMirror is pointer
页:
[1]