[求助]为何我用drawjig插入块,无法动态显示?求解!
如题,我用drawjig从外部一个特定文件读入特定block插入到当前文档,有时能动态显示图块,大部分时候不显示,只是一个十字光标!是不是代码有问题呢?求教高人,多谢!vs2005c# + cad2007 public class InsertBlk : DrawJig
{
private BlockReference newBlkRef;
private Point3d mCenterPt;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
//-----------------------------------
public void InsertBlock(string strFilename, string strBlkname)
{
mCenterPt = new Point3d(0, 0, 0);
Database db = HostApplicationServices.WorkingDatabase;
Matrix3d mt = ed.CurrentUserCoordinateSystem;
PromptResult resJig;
ReadBlock(strBlkname, strFilename);
do
{
Transaction tr = doc.TransactionManager.StartTransaction();
BlockTable bt = (BlockTable)tr.GetObject(this.doc.Database.BlockTableId, OpenMode.ForRead);
this.newBlkRef = new BlockReference(mCenterPt, bt);
tr.Commit();
this.newBlkRef.Normal = db.Ucsxdir.CrossProduct(db.Ucsydir);
resJig = ed.Drag(this);
if (resJig.Status == PromptStatus.OK)
{
AppendEntity(this.newBlkRef);
}
}
while (resJig.Status != PromptStatus.Cancel);
}
//-----------------------------------
private ObjectId AppendEntity(Entity ent)
{
ObjectId entId;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
entId = btr.AppendEntity(newBlkRef);
trans.AddNewlyCreatedDBObject(newBlkRef, true);
trans.Commit();
}
return entId;
}
//-----------------------------------
private bool ReadBlock(string strBlkname, string strFilename)
{
using (Transaction tr = this.doc.TransactionManager.StartTransaction())
{
using (Database db = new Database(false, true))
{
db.ReadDwgFile(strFilename, System.IO.FileShare.Read, true, null);
using (Transaction trm = db.TransactionManager.StartTransaction())
{
BlockTable sourceBlkTbl = (BlockTable)trm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
if (!sourceBlkTbl.Has(strBlkname))
{
ed.WriteMessage("\n"+strBlkname+" does not exist in this dwg.");
return false;
}
ObjectIdCollection blockIds = new ObjectIdCollection();
blockIds.Add(sourceBlkTbl);
IdMapping IdMap = new IdMapping();
db.WblockCloneObjects(blockIds, this.doc.Database.BlockTableId, IdMap, DuplicateRecordCloning.Replace ,false);
}
}
tr.Commit();
}
return true;
}
//-----------------------------------
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
draw.Geometry.Draw(this.newBlkRef);
return true;
}
//-----------------------------------
protected override SamplerStatus Sampler(JigPrompts prompts)
{
optJigDis.UserInputControls = UserInputControls.Accept3dCoordinates;
PromptPointResult resJigDis = prompts.AcquirePoint(optJigDis);
Point3d tempPt = resJigDis.Value;
if (resJigDis.Status == PromptStatus.Cancel)
{
return SamplerStatus.Cancel;
}
if (mCenterPt != tempPt)
{
mCenterPt = tempPt;
this.newBlkRef.Position = mCenterPt;
return SamplerStatus.OK;
}
else
{
return SamplerStatus.NoChange;
}
}
}
http://bbs.mjtd.com/xwb/images/bgimg/icon_logo.png 该贴已经同步到 晋A青少年的微博
if (mCenterPt != tempPt)//这里想办法让鼠标点走远一点再刷新图形,比如加个公差或距离判断;目前应该是刷新太频繁了
91.
{
92.
mCenterPt = tempPt;
93.
this.newBlkRef.Position = mCenterPt;
94.
return SamplerStatus.OK;
95.
}
if (_pos.DistanceTo(ppr.Value) >= Tolerance.Global.EqualPoint) 多谢!
if (tempPt .DistanceTo (mCenterPt )>= Tolerance .Global .EqualPoint )
不过好像效果不是很明显,十字光标也一直闪,不过我发现小的图形可以显示了,复杂点的还是看不到,总算有进展了。。。 请问高手,Sampler(JigPrompts prompts)中的optJigDis提示错误,上下文不存在optJigDis,怎样解决?
JigPromptPointOptions optJigDis = new JigPromptPointOptions(); 同求解决方法 把公差的EqualPoint设置大些
页:
[1]