翻譯|使用教程|編輯:黃竹雯|2018-12-14 14:51:56.000|閱讀 558 次
概述:CAD .NET系列問題解答連載旨在為大家提供更多可學習的參考資料。若是已經入手或者正準備入手CAD .NET的朋友千萬別錯過該系列教程哦。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
CAD .NET是一款在CAD領域被廣泛應用的控件,可以快速準確的閱讀DWG和DXF文件,并且通過Windows GDI+方法繪制件,支持多種文件格式,包括DWG、DXF、Gerber、光柵圖像等,并支持部分編輯功能。
![]() |
![]() |
![]() |
產品詳情 | 試用版下載 | 相關活動 |
接下來我們將以問答形式為大家解決在使用CAD .NET時所遇到的一些問題,該系列連載希望可以給大家一些幫助和參考。
問:從v11升級到v12后,我使用Selector.MultipleSelect時出現了另一個問題。在v12中,Selector類總是返回一個空集合。你可以調查一下是否可以按預期工作嗎?
答:在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 Viewer。打開所有類型的圖像并應用縮放功能。但是有兩個問題:當我打開圖像dwg或dxf時,沒有顏色,我無法解釋被奇怪符號替換的字母。我是忘記加了什么嗎?請參見以下截圖。
答:能否附上CAD Viewer的源代碼,以便我深入找一下原因?
問:請看:
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中)。
未完待續~
*點擊圖片查看活動詳情*
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn