瞬态代码在acad中工作,而不是在bricscad中
我做了一个测试prog,在用户选择时在屏幕上画一个围栏。它在autocad中运行良好,但在bricscad v16中不行。我将很快在V17上尝试。
这是代码,非常典型的使用点监视器的示例例程。
您应该得到的是正在绘制的红色折线,就像绘制真正的样条线一样。
Escape杀死它,这只是一个示例prog。
//C# Usings
using System;
using System.Collections;
using SC = System.Collections;
using System.Collections.Generic;
using SCG = System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using SWF = System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Xml;
using System.Xml.Serialization;
using SM = System.Math;
using System.Linq;
//AutoCad Usings
#if ACAD
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.EditorInput;
using AcEd = Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcCo = Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Windows;
using AcWn = Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Customization;
#endif
#if BCAD
using Teigha.DatabaseServices;
using AcDb = Teigha.DatabaseServices;
using Bricscad.EditorInput;
using AcEd = Bricscad.EditorInput;
using Teigha.Geometry;
using AcGe = Teigha.Geometry;
using AcCo = Teigha.Colors;
using Teigha.Runtime;
using Teigha.GraphicsInterface;
using Bricscad.Runtime;
using Bricscad.ApplicationServices;
using AcAp = Bricscad.ApplicationServices.Application;
using Bricscad.Windows;
using AcWn = Bricscad.Windows;
#endif
namespace ProgTestingAcad {
public class Program2 {
public static void GetPts() {
Document dwg = AcAp.DocumentManager.MdiActiveDocument;
Editor ed = dwg.Editor;
MyptCmd cmd = new MyptCmd(dwg);
cmd.GetPts();
}
}
public class MyptCmd {
private Document _dwg;
private Editor _editor;
private List _points;
private List _origpoints = new List();
private Point2d _resPt;
private AcDb.Polyline _pline = null;
public MyptCmd(Document dwg) {
_dwg = dwg;
_editor = _dwg.Editor;
}
public void GetPts() {
_points = new List();
//get first point
PromptPointOptions opt = new PromptPointOptions("\nPick Point: ");
PromptPointResult res = _editor.GetPoint(opt);
if (res.Status == PromptStatus.OK) {
_origpoints.Add(new AcGe.Point2d(res.Value.X, res.Value.Y));
try {
//Handling mouse cursor moving during picking
_editor.PointMonitor += new PointMonitorEventHandler(_editor_PointMonitor);
bool loop = true;
//get more points
while (loop) {
if (!PickNewPoint())
loop = false; //no point
else
_origpoints.Add(_resPt);
}
}
catch {
throw;
}
finally {
ClearTransientGraphics();
//Remove PointMonitor handler
_editor.PointMonitor -= new PointMonitorEventHandler(_editor_PointMonitor);
}
}
}
private bool PickNewPoint() {
PromptPointOptions opt = new PromptPointOptions("\nPick Point: ");
PromptPointResult res = _editor.GetPoint(opt);
if (res.Status == PromptStatus.OK) {
_resPt = new AcGe.Point2d(res.Value.X, res.Value.Y);
return true;
}
else {
return false;
}
}
private void ClearTransientGraphics() {
TransientManager.CurrentTransientManager.EraseTransients(
TransientDrawingMode.DirectShortTerm,
128, new IntegerCollection());
if (_pline != null)
_pline.Dispose();
_pline = null;
}
private void _editor_PointMonitor(object sender, PointMonitorEventArgs e) {
ClearTransientGraphics();
Point2d pt = new Point2d(e.Context.RawPoint.X, e.Context.RawPoint.Y);
bool go = true;
//figure new points
//set _points to orig and add point
//we must do this as we cannot simply add a point
_points = new List();
_points.AddRange(_origpoints);
_points.Add(pt);
//draw new _pline
if (go) {
_pline = new AcDb.Polyline(_points.Count);
for (int i = 0; i < _points.Count; i++) {
_pline.AddVertexAt(i, _points, 0.0, 0.0, 0.0);
}
_pline.ColorIndex = 1;
TransientManager.CurrentTransientManager.AddTransient(
_pline, TransientDrawingMode.DirectShortTerm, 128
, new IntegerCollection());
}
}
}
}
有什么想法吗?
我尝试了DirectTop大多数和其他想法,那没关系。
thx
**** Hidden Message ***** 我注意到BricsCAD V17不会在PointMonitor期间更新瞬态实体,除非您滚动鼠标滚轮。只是静态瞬态实体工作正常。
Gent中的程序员知道这一点并将检查可能性。 不,不……。
开枪,我撞到虫子了
我在acad中做了大量编程,并且在bcad中尝试过瞬态,因此从未想过它们会在pointmonitor中表现不好<我希望他们能解决这个问题<谢谢你的提醒,huiz! 至少他们比另一家CAD软件公司更认真 黑客警报
if(go)
{
_ pline=新的AcDb.Polyline(_points.Count)
用于(int i=0;i
{
_ pline。AddVertexAt(i,_points,0.0,0.0,0.0)
}
_ pline。色度指数=1
TransientManager.CurrentTransientManager.AddTransient(
_ pline,瞬态绘图模式。DirectShortTerm,128
,新的IntegerCollection())
editor.SetCurrentView(_editor.GetCurrentView());//
}
编辑:需要这样处理。
使用(ViewTableRecord rec=_editor.GetCurrentView())进行编辑
{
编辑器SetCurrentView(rec)
}
可能有更好的替代方案,这在大型图纸上似乎有点滞后。
这真的很神奇,”....这真的是太神奇了。这实在是太神奇了,我想把它偷出来。-Zaphod Beeblebrox
这很有效,太简单了!非常感谢你的回复,现在我的Bricscad工作的很好,我欠你的! 确实,完美!在AutoCAD变体中,我没有设置当前视图,它以这种方式工作正常。如果我将SetCurrentView添加到代码中,它也可以在PointMonitor的BricsCAD中工作!
对不起詹姆斯,我错误地通知你,我不知道这个聪明的解决方案! 惠兹,你是对的,bricsys正在努力,他们也告诉我。
我还添加了一个#if BCAD...语句来运行bcad。
像这样的瞬态的使用将改变我已经做了这么多工具。
我曾经使用grDrew,但与瞬态相比,这是过时的。 谢谢你的变通方法,丹尼尔。在这里工作也不错
仅供参考,自Bricscad V18.1.02测试版起,瞬态仍然存在,需要.SetCurrentView调用才能显示。
页:
[1]