Message 1 of 2
AddTransient won't draw image AutoCAD 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I want to draw a transient line by a specific distance when I hover over another line, but when I use the method ctm.AddTransient(line, AcGi.TransientDrawingMode.Main, 128, ints), it is not drawing any transient line. In another code I am using the method with block references as ctm.AddTransient(bref, AcGi.TransientDrawingMode.DirectShortTerm, 128, ints) and it works without problems.
Now I am working on a code which I changed some parts from another source in order to understand how I can achieve my goal.
Here is the full code for you to examine. I am a newbie so please be more specific about your suggestions and I will try to understand them as much as I can 😭. Thanks for your help.
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using System;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
public class PointMonitorTooltips
{
[CommandMethod("SM")]
public static void StartMonitor()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
ed.PointMonitor +=
new PointMonitorEventHandler(ed_PointMonitor);
}
[CommandMethod("XM")]
public static void StopMonitor()
{
Editor ed =
Application.DocumentManager.MdiActiveDocument.Editor;
ed.TurnForcedPickOn();
ed.PointMonitor -=
new PointMonitorEventHandler(ed_PointMonitor);
}
static void ed_PointMonitor(object sender, PointMonitorEventArgs e)
{
Editor ed = (Editor)sender;
AcGi.TransientManager ctm = AcGi.TransientManager.CurrentTransientManager;
IntegerCollection ints = new IntegerCollection(new int[] { });
try
{
FullSubentityPath[] paths = e.Context.GetPickedEntities();
// Open a transaction to create the transient line
using (Transaction tr = ed.Document.TransactionManager.StartTransaction())
{
foreach (FullSubentityPath path in paths)
{
ObjectId[] ids = path.GetObjectIds();
if (ids.Length > 0)
{
ObjectId id = ids[ids.GetUpperBound(0)];
// Get the entity
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
Type objtype = ent.GetType();
// Create a transient line based on the entity's position and orientation
if (objtype == typeof(Line))
{
Line linecoor = (Line)ent.Clone();
Point3d start = linecoor.StartPoint;
start = start.Add(new Vector3d(5.0, 5.0, 0.0));
Point3d end = linecoor.EndPoint;
end = end.Add(new Vector3d(5.0, 5.0, 0.0));
Line line = new Line(start, end);
// Add the transient line
ed.WriteMessage("\nAdding transient line..."); // This part constantly sending messages
ctm.AddTransient(line, AcGi.TransientDrawingMode.Main, 128, ints); // This part is not drawing anything
}
}
}
tr.Commit();
}
}
catch
{
// Exception handling code here
}
}
}