I have the dialog window with the settings for entities graphical appearance used in my plugin.
My goal is to create the same preview as AutoCAD dimension style manager dialog has, the dynamic thumbnail of the entities while user changes the settings in dialog.
Can someone give me idea or some approach how to do it.
Probably one option is to create temporary block (created based on data from settings dialog) and then use BlockTableRecord.PreviewIcon, but I am not sure if there is some other way.
Thank you,
Richard
Solved! Go to Solution.
Solved by RichardCammeray. Go to Solution.
A better result than using the block preview bitmap you will get by this approach:
private IntPtr m_hDevice = IntPtr.Zero; private Device m_device = null; private acView m_view = null; private Model m_model = null; private Autodesk.AutoCAD.DatabaseServices.Database m_previewDB = null; private bool _SuspendPreview = false; private bool _SettingLayers = false; private void CreatePreviewBitmap() { if (_SuspendPreview) return; if (_SettingLayers) return; Bitmap bmpResult = null; m_hDevice = pbPreview.Handle; try { Document doc = acApp.DocumentManager.MdiActiveDocument; Manager gsm = doc.GraphicsManager; m_device = gsm.CreateAutoCADDevice(m_hDevice); m_device.DeviceRenderType = RendererType.Default; string sProfileKey = DFMgHelp.GetCurrentProfileRegPath(); sProfileKey += "\\Drawing Window"; m_device.BackgroundColor = backColor; m_view = new acView(); m_device.Add(m_view); m_device.Update(); m_model = gsm.CreateAutoCADModel(); m_previewDB = new Autodesk.AutoCAD.DatabaseServices.Database(); using (Transaction transTemp = m_previewDB.TransactionManager.StartTransaction()) { if (transTemp != null) { BlockTable bt = transTemp.GetObject(m_previewDB.BlockTableId, OpenMode.ForRead) as BlockTable; ObjectId idBTR = bt[BlockTableRecord.ModelSpace]; BlockTableRecord msBtr = transTemp.GetObject(idBTR, OpenMode.ForWrite) as BlockTableRecord; msBtr.AppendEntity(EntityToPreview); transTemp.AddNewlyCreatedDBObject(EntityToPreview, true); m_view.Add(EntityToPreview, m_model); transTemp.Commit(); } } m_view.Update(); m_view.Mode = Autodesk.AutoCAD.GraphicsSystem.RenderMode.GouraudShaded; m_view.VisualStyle = new GI.VisualStyle(GI.VisualStyleType.Realistic); Point3d newTarget = new Point3d(0.0, 0.0, 0.0); Point3d newPosition = new Point3d(0.0, 0.0, 10); Vector3d newUpVector = new Vector3d(0.0, 1.0, 0.0); double height = 1; if (Math.Abs(_SchichtSum) > height) height = Math.Abs(_SchichtSum); double width = 1; if (Math.Abs(_VersatzSum) > width) width = Math.Abs(_VersatzSum); m_view.SetView(newPosition, newTarget, newUpVector, width * 2.2, height * 2.2, Projection.Perspective); m_model.Invalidate(InvalidationHint.InvalidateAll); m_view.Invalidate(); m_view.Update(); bmpResult = m_view.GetSnapshot(new Rectangle(0, 0, pbPreview.Width, pbPreview.Height)); pbPreview.Image = bmpResult; } catch (System.Exception ex) { ex.Message.WriteToErrorLog(); ex.Message.WriteToEditorIfDebug(); } finally { DisposeView(); } } private void DisposeView() { if (m_device != null) { m_device.Dispose(); m_device = null; } if (m_model != null) { m_model.Dispose(); m_model = null; } if (m_view != null) { m_view.EraseAll(); m_view.Dispose(); m_view = null; } if (m_previewDB != null) { m_previewDB.Dispose(); m_previewDB = null; } }
Thank you for your example and for idea what to search for.
I have found also these links for similar topic
ObjectARX BlockView and show MS in Dialog
Thank you,
Richard