CAD .NET系列问题解答连载旨在为大家提供更多可学习的参考资料。若是已经入手或者正准备入手CAD .NET的朋友千万别错过该系列教程哦。
![]() |
![]() |
![]() |
产品详情 | 试用版下载 | 相关活动 |
接下来我们将以问答形式为大家解决在使用CAD .NET时所遇到的一些问题,该系列连载希望可以给大家一些帮助和参考。
一:Selector.MultipleSelect(dRect,True,False)返回空集合
问:从v11升级到v12后,我使用Selector.MultipleSelect时出现了另一个问题。在v12中,Selector类总是返回一个空集合。你可以调查一下是否可以按预期工作吗/p>
答:在v12中,CADSelector.MultipleSelect()方法的行为取决于CADSelector.UseShiftToAddSelected属性值,该值确定了一种可用的选择模式:
CADSelector.UseShiftToAddSelected = False(默认情况下) – 允许每个选定的对象(对象组)被添加到当前选择集而不丢弃先前的选择。你必须按住Shift键并使用鼠标左键放弃先前的选择。
CADSelector.UseShiftToAddSelected = True – 在选择一个或多个项目后尝试在图形中选择更多对象时,先前选择的对象将变为未选中状态。你必须按住Shift键并使用鼠标左键才能将新对象添加到选择集。
上述选择模式的工作方式与使用Shift添加到 AutoCAD中的选择选项的方式相同:

CADSelector.MultipleSelect()方法的第二个参数实际上采用Shift键状态(按下并保持或未按下)。当CADSelector.UseShiftToAddSelected = False并且此参数设置为True(模拟按住Shift键时的情况)时,你只能放弃先前的选择。这是符合预期的行为。
二:图像消失了
问:我正在使用CAD .NET 11,对空间数据进行测试并使用CADtoDXF类导出到DXF文件。当我在AutoCAD中加载DXF文件时,没有出现问题。但我把它保存为dwg文件,dxf中的所有图像都断开连接并消失。我不知道如何解决这个问题,可以帮帮我吗有我想知道是否有在CAD .NET中导出为dwg格式的方法。
答:如果光栅图像作为IMAGE对象添加到CAD工程图中,并且图像文件无法位于相应imagedef对象中指定的文件路径,则光栅图像可能会丢失。至于导出到DWG,从版本12.1开始支持使用CAD .NET附带的附加动态链接库sgcadexp.dll,可以在以下文件夹中找到它:
c: Users USER_NAME Documents CAD。 NET 12 bin DWGExportLib Win32
c: Users USER_NAME Documents CAD .NET 12 bin DWGExportLib Win64
要将CADImage对象导出为DWG格式,你需要将文件sgcadexp.dll复制到使用CADImport.dll的文件夹并调用静态方法CADtoDWG.SaveAsDWG。例如以下代码:
public static void SaveCADImageAsDWG(CADImage cadImage, string dwgFilePath){ CADImport.Export.CADtoDWG.SaveAsDWG(cadImage, dwgFilePath);}
三:CAD查看器问题
我在演示之后实现了CAD Viewer。打开所有类型的图像并应用缩放功能。但是有两个问题:当我打开图像dwg或dxf时,没有颜色,我无法解释被奇怪符 替换的字母。我是忘记加了什么吗参见以下截图。

答:能否附上CAD Viewer的源代码,以便我深入找一下原因/p>
问:请看:
public void LoadFile(string fileName) { _fileName = fileName; if (fileName != null) { if (cadImage != null) { cadImage.Dispose(); cadImage = null; //this.lForm.LayerList.Clear(); } ImageScale = 1.0f; this.cadImage = CADImage.CreateImageByExtension(fileName); CADImport.CADConst.DefaultSHXParameters.UseSHXFonts = this.useSHXFonts; if (this.useSHXFonts) DoSHXFonts(); else DoTTFFonts(); this.cadImage.ChangeGraphicsMode(graphicsMode, renderMode); this.cadImage.GraphicsOutMode = graphicsMode; this.cadImage.ChangeDrawMode(graphicsMode, cadPictBox); this.cadImage.ChangeGraphicsMode(graphicsMode, renderMode); if (this.cadImage is CADRasterImage) (this.cadImage as CADRasterImage).Control = this.cadPictBox; } if (this.cadImage != null) { CADImage.CodePage = System.Text.Encoding.Default.CodePage;//note - charset was set here CADImage.LastLoadedFilePath = Path.GetDirectoryName(fileName); CreateNewLoadThread(fileName); } }
private void LoadCADImage(object fileNameObj) { lock (cadImage) { string fileName = (string)fileNameObj; if (CADConst.IsWebPath(fileName)) this.cadImage.LoadFromWeb(fileName); else cadImage.LoadFromFile(fileName); } SetCADImageOptions(); }
public void SetCADImageOptions() { cadImage.IsShowLineWeight = this.showLineWeight; cadImage.IsWithoutMargins = true; cadImage.UseDoubleBuffering = this.useDoubleBuffering; cadImage.TTFSmoothing = TTFSmoothing.None; this.useSelectEntity = false; if (cadPictBox.BackColor == Color.White) White_Click(); else Black_Click(); if (this.DrawMode == false) this.DoBlackColor(); ObjEntity.cadImage = cadImage; ObjEntity.propGrid = this.propGrid; DoResize(true, true); this.cadPictBox.Invalidate(); }
其余功能几乎相同。如果你需要更具体的内容,可以问我。
答:我注意到你的代码包含DoBlackColor()调用,在ViewerDemo项目中,给定方法呈现黑白CAD图像。要确定当前使用的渲染模式,你应该检查CADImage.DrawMode属性值,该值可能如下所示:
public enum CADDrawMode { // All colors are shown. Normal = 0, // CAD image is shown in black and white. Black = 1, // CAD image is shown in grayscale. Gray = 2, }
错误字符的问题可能与使用不正确的字体有关。请检查图形文件所需的SHX和TTF字体(例如,在AutoCAD中)。
未完待续~
热门活动推荐
*点击图片查看活动详情*

标签:CADCAD浏览
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!