Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guy.
I have a Twist lisp attached below.
I would like to convert this Lisp to C#.
Thank you so much.
Solved! Go to Solution.
Hi Guy.
I have a Twist lisp attached below.
I would like to convert this Lisp to C#.
Thank you so much.
Solved! Go to Solution.
Hi,
Here's a way but it do not handle RText objects because they're not exposed to the .NET API.
[CommandMethod("TW", CommandFlags.NoPaperSpace)]
public static void TwistView()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
using (var tr = db.TransactionManager.StartTransaction())
{
var pao = new PromptAngleOptions("\nSpecify the twistview angle or [Block angle/Line angle/Text angle]", "Block Line Text");
pao.AllowNone = false;
var par = ed.GetAngle(pao);
double angle = 0.0;
switch (par.Status)
{
case PromptStatus.Keyword:
switch (par.StringResult)
{
case "Block":
while (true)
{
var peo = new PromptEntityOptions("\nSelect block: ");
peo.SetRejectMessage("\nSelected object is not a block.");
peo.AddAllowedClass(typeof(BlockReference), true);
var per = ed.GetEntity(peo);
if (per.Status == PromptStatus.Cancel)
{
return;
}
if (per.Status == PromptStatus.OK)
{
var br = (BlockReference)tr.GetObject(per.ObjectId, OpenMode.ForRead);
angle = br.Rotation;
break;
}
}
break;
case "Line":
while (true)
{
var peo = new PromptEntityOptions("\nSelect line: ");
peo.SetRejectMessage("\nSelected object is not a line.");
peo.AddAllowedClass(typeof(Line), true);
var per = ed.GetEntity(peo);
if (per.Status == PromptStatus.Cancel)
{
return;
}
if (per.Status == PromptStatus.OK)
{
var line = (Line)tr.GetObject(per.ObjectId, OpenMode.ForRead);
var pt = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem);
angle = pt.DistanceTo(line.EndPoint) < pt.DistanceTo(line.StartPoint) ?
Vector3d.XAxis.GetAngleTo(line.EndPoint - line.StartPoint, Vector3d.ZAxis) :
Vector3d.XAxis.GetAngleTo(line.StartPoint - line.EndPoint, Vector3d.ZAxis);
break;
}
}
break;
case "Text":
default:
while (true)
{
var peo = new PromptEntityOptions("\nSelect text: ");
peo.SetRejectMessage("\nSelected object is not a text, mtext, attribute reference or definition.");
peo.AddAllowedClass(typeof(DBText), false);
peo.AddAllowedClass(typeof(MText), true);
var per = ed.GetEntity(peo);
if (per.Status == PromptStatus.Cancel)
{
return;
}
if (per.Status == PromptStatus.OK)
{
if (per.ObjectId.ObjectClass.DxfName == "MTEXT")
{
var mtext = (MText)tr.GetObject(per.ObjectId, OpenMode.ForRead);
angle = mtext.Rotation;
}
else
{
var text = (DBText)tr.GetObject(per.ObjectId, OpenMode.ForRead);
angle = text.Rotation;
}
break;
}
break;
}
break;
}
break;
case PromptStatus.OK:
angle = par.Value;
break;
default:
return;
}
using (ViewTableRecord view = ed.GetCurrentView())
{
var center = new Point3d(view.CenterPoint.X, view.CenterPoint.Y, 0.0)
.TransformBy(
Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) *
Matrix3d.Displacement(view.Target.GetAsVector()) *
Matrix3d.PlaneToWorld(view.ViewDirection));
view.ViewTwist = -angle;
center = center.TransformBy(
Matrix3d.WorldToPlane(view.ViewDirection) *
Matrix3d.Displacement(view.Target.GetAsVector().Negate()) *
Matrix3d.Rotation(view.ViewTwist, view.ViewDirection, view.Target));
view.CenterPoint = new Point2d(center.X, center.Y);
ed.SetCurrentView(view);
}
Application.SetSystemVariable("SnapAng", angle);
tr.Commit();
}
}