翻譯|使用教程|編輯:黃竹雯|2018-12-14 14:51:56.000|閱讀 558 次
概述:CAD .NET系列問(wèn)題解答連載旨在為大家提供更多可學(xué)習(xí)的參考資料。若是已經(jīng)入手或者正準(zhǔn)備入手CAD .NET的朋友千萬(wàn)別錯(cuò)過(guò)該系列教程哦。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
CAD .NET是一款在CAD領(lǐng)域被廣泛應(yīng)用的控件,可以快速準(zhǔn)確的閱讀DWG和DXF文件,并且通過(guò)Windows GDI+方法繪制件,支持多種文件格式,包括DWG、DXF、Gerber、光柵圖像等,并支持部分編輯功能。
![]() |
![]() |
![]() |
產(chǎn)品詳情 | 試用版下載 | 相關(guān)活動(dòng) |
接下來(lái)我們將以問(wèn)答形式為大家解決在使用CAD .NET時(shí)所遇到的一些問(wèn)題,該系列連載希望可以給大家一些幫助和參考。
問(wèn):從v11升級(jí)到v12后,我使用Selector.MultipleSelect時(shí)出現(xiàn)了另一個(gè)問(wèn)題。在v12中,Selector類總是返回一個(gè)空集合。你可以調(diào)查一下是否可以按預(yù)期工作嗎?
答:在v12中,CADSelector.MultipleSelect()方法的行為取決于CADSelector.UseShiftToAddSelected屬性值,該值確定了一種可用的選擇模式:
CADSelector.UseShiftToAddSelected = False(默認(rèn)情況下) - 允許每個(gè)選定的對(duì)象(對(duì)象組)被添加到當(dāng)前選擇集而不丟棄先前的選擇。你必須按住Shift鍵并使用鼠標(biāo)左鍵放棄先前的選擇。
CADSelector.UseShiftToAddSelected = True - 在選擇一個(gè)或多個(gè)項(xiàng)目后嘗試在圖形中選擇更多對(duì)象時(shí),先前選擇的對(duì)象將變?yōu)槲催x中狀態(tài)。你必須按住Shift鍵并使用鼠標(biāo)左鍵才能將新對(duì)象添加到選擇集。
上述選擇模式的工作方式與使用Shift添加到 AutoCAD中的選擇選項(xiàng)的方式相同:
CADSelector.MultipleSelect()方法的第二個(gè)參數(shù)實(shí)際上采用Shift鍵狀態(tài)(按下并保持或未按下)。當(dāng)CADSelector.UseShiftToAddSelected = False并且此參數(shù)設(shè)置為True(模擬按住Shift鍵時(shí)的情況)時(shí),你只能放棄先前的選擇。這是符合預(yù)期的行為。
問(wèn):我正在使用CAD .NET 11,對(duì)空間數(shù)據(jù)進(jìn)行測(cè)試并使用CADtoDXF類導(dǎo)出到DXF文件。當(dāng)我在AutoCAD中加載DXF文件時(shí),沒(méi)有出現(xiàn)問(wèn)題。但我把它保存為dwg文件,dxf中的所有圖像都斷開連接并消失。我不知道如何解決這個(gè)問(wèn)題,可以幫幫我嗎?還有我想知道是否有在CAD .NET中導(dǎo)出為dwg格式的方法。
答:如果光柵圖像作為IMAGE對(duì)象添加到CAD工程圖中,并且圖像文件無(wú)法位于相應(yīng)imagedef對(duì)象中指定的文件路徑,則光柵圖像可能會(huì)丟失。至于導(dǎo)出到DWG,從版本12.1開始支持使用CAD .NET附帶的附加動(dòng)態(tài)鏈接庫(kù)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對(duì)象導(dǎo)出為DWG格式,你需要將文件sgcadexp.dll復(fù)制到使用CADImport.dll的文件夾并調(diào)用靜態(tài)方法CADtoDWG.SaveAsDWG。例如以下代碼:
public static void SaveCADImageAsDWG(CADImage cadImage, string dwgFilePath) { CADImport.Export.CADtoDWG.SaveAsDWG(cadImage, dwgFilePath); }
我在演示之后實(shí)現(xiàn)了CAD Viewer。打開所有類型的圖像并應(yīng)用縮放功能。但是有兩個(gè)問(wèn)題:當(dāng)我打開圖像dwg或dxf時(shí),沒(méi)有顏色,我無(wú)法解釋被奇怪符號(hào)替換的字母。我是忘記加了什么嗎?請(qǐng)參見(jiàn)以下截圖。
答:能否附上CAD Viewer的源代碼,以便我深入找一下原因?
問(wèn):請(qǐng)看:
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(); }
其余功能幾乎相同。如果你需要更具體的內(nèi)容,可以問(wèn)我。
答:我注意到你的代碼包含DoBlackColor()調(diào)用,在ViewerDemo項(xiàng)目中,給定方法呈現(xiàn)黑白CAD圖像。要確定當(dāng)前使用的渲染模式,你應(yīng)該檢查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, }
錯(cuò)誤字符的問(wèn)題可能與使用不正確的字體有關(guān)。請(qǐng)檢查圖形文件所需的SHX和TTF字體(例如,在AutoCAD中)。
未完待續(xù)~
*點(diǎn)擊圖片查看活動(dòng)詳情*
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn