乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 76|回复: 6

[编程交流] vc++ code to c# autocad

[复制链接]

3

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2022-7-6 14:33:30 | 显示全部楼层 |阅读模式
Hi,
 
I am having the following vc++ code which will read the input from Layertable assign to variable of user-defined class cLayerInfo.
 
  1. 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
  1. 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
  1. 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
 
  1. 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.h  file.
 
Can anyone tell me how to convert the above code in c#.
Please it is urgent.
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 14:48:21 | 显示全部楼层
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.
回复

使用道具 举报

3

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2022-7-6 14:57:17 | 显示全部楼层
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 CMap  CMapLayerInfo;
 
If I go for CMap  definition 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#
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 15:07:16 | 显示全部楼层
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.
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 15:16:41 | 显示全部楼层
This is a bit of a coincidental thread don't ya think Sean...
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 15:32:57 | 显示全部楼层
There are a lot of us all headed in a similar direction. :wink:
回复

使用道具 举报

3

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
17
发表于 2022-7-6 15:35:22 | 显示全部楼层
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
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 00:37 , Processed in 0.607917 second(s), 77 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表