文檔首頁>>VectorDraw Developer Framework使用教程>>VDF常見問題整理(四十七):如何單擊到多邊形并選擇該面
VDF常見問題整理(四十七):如何單擊到多邊形并選擇該面
VectorDraw Developer Framework(VDF)是一個用于應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何單擊到多邊形并選擇自己想要的一面?
答:
下面的代碼使用Select3D,然后使用RenderSelect的各種方法來獲取內(nèi)部實體以及所選面所需的MAtrix。
private void TestIt() { vdDocument doc = vd.BaseControl.ActiveDocument; gPoint userpt = null; StatusCode s = doc.ActionUtility.getUserPoint(out userpt); if (s == StatusCode.Success) { gPoint pointW = doc.User2WorldMatrix.Transform(userpt); gPoint tmppt = doc.World2PixelMatrix.Transform(pointW); Point screenpt = new Point((int)tmppt.x, (int)tmppt.y); doc.EntitySelectMode = VectorDraw.Render.PickEntityMode.EyeNearest; //Very important so it is selected the eye nearest face , your drawing had default DrawOrder which in many occasions will return you the bottom face VectorDraw.Render.RenderSelect.RenterSelectObjectArray selectedents = null; doc.ActiveLayOut.Select3d(false, doc.ActiveLayOut.Entities, screenpt, doc.GlobalRenderProperties.PickSize, false, out selectedents); if (selectedents != null && selectedents.Count > 0) { VectorDraw.Render.RenderSelect.RenterSelectObject pfacerender = selectedents[0]; //Get the polyface vdPolyface pface = pfacerender.mFigStackItem[0].mFigure as vdPolyface; if (pface != null) { //The UserID gives you the segment of the polyface that was selected int SegCount = pfacerender.UserId; gPoints pts = new gPoints(); if (SegCount >= 0) { int seg = 5 * SegCount; if (seg <= (pface.FaceList.Count - 5)) { pts.Add(new gPoint(pface.VertexList[System.Math.Abs(pface.FaceList[seg + 0]) - 1])); pts.Add(new gPoint(pface.VertexList[System.Math.Abs(pface.FaceList[seg + 1]) - 1])); pts.Add(new gPoint(pface.VertexList[System.Math.Abs(pface.FaceList[seg + 2]) - 1])); if (pface.FaceList[seg + 3] != pface.FaceList[seg + 0]) pts.Add(new gPoint(pface.VertexList[System.Math.Abs(pface.FaceList[seg + 3]) - 1])); int[] array_faces = { 1, 2, 3, 4, -1 }; Int32Array faces = new Int32Array(array_faces); var pf = new vdPolyface(doc, pts, faces); //Calculate the Matrix to transform the face to World Coordinate System because the face is inside a block and has a completelly different coordinate system Matrix matt = pfacerender.mFigStackItem[0].mMatrix * doc.ActiveLayOut.View2WorldMatrix; pf.Transformby(matt); pf.PenColor.SystemColor = Color.BlueViolet; doc.ActionLayout.Entities.Add(pf); doc.Redraw(true); } } } } } }
以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會及時回復。此系列的問答教程我們會持續(xù)更新,如果您感興趣,可以多多關注本教程。
熱門文章推薦:
=======================================================
如果您對想要購買正版授權VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關問題。
關注慧聚IT微信公眾號 ???,了解產(chǎn)品的最新動態(tài)及最新資訊。