.NET

Reply
Valued Contributor
RichardCammeray
Posts: 56
Registered: ‎12-08-2010
Message 1 of 3 (280 Views)
Accepted Solution

Dynamic preview of entities (mimic dimension style manager preview)

280 Views, 2 Replies
09-08-2013 04:19 PM

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

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

Contributor
Matti72
Posts: 25
Registered: ‎09-28-2004
Message 2 of 3 (257 Views)

Re: Dynamic preview of entities (mimic dimension style manager preview)

09-08-2013 11:26 PM in reply to: RichardCammeray

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;
			}
		}

 

Valued Contributor
RichardCammeray
Posts: 56
Registered: ‎12-08-2010
Message 3 of 3 (235 Views)

Re: Dynamic preview of entities (mimic dimension style manager preview)

09-09-2013 11:14 PM in reply to: Matti72

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!