为何加入多义线总出错
<P> Public Function addpl()<BR> Dim db As Database = HostApplicationServices.WorkingDatabase()<BR> Dim trans As Transaction = db.TransactionManager.StartTransaction()<BR> MsgBox("0")<BR> Try<BR> Dim pl As New Circle(New Point3d(0, 0, 0), Vector3d.ZAxis, 100)<BR> MsgBox("1")<BR> Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)<BR> MsgBox("2")<BR> Dim btrid As ObjectId = bt.Item(BlockTableRecord.ModelSpace)<BR> <FONT color=#ff0000>Dim btr As BlockTableRecord = trans.GetObject(btrid, OpenMode.ForWrite)<BR></FONT> MsgBox("3")<BR> Dim ObjId As ObjectId<BR> MsgBox("4")<BR> ObjId = btr.AppendEntity(pl)<BR> MsgBox("5")<BR> trans.AddNewlyCreatedDBObject(pl, True)<BR> MsgBox("6")<BR> trans.Commit()<BR> Catch ex As Exception<BR> MsgBox("pl error.")<BR> Finally<BR> trans.Dispose()<BR> End Try<BR> End Function</P><P>上面程序中红色代码总出错。请高手指点。</P> 我可按照教程一个字都不差,不知为什么就是不行。 <P><FONT color=#ff0000>好像是这样吧?</FONT></P>
<P><FONT color=#ff0000>Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceID, OpenMode.ForWrite)</FONT><BR></P> 谢谢楼上的弟兄回复。但我试了还是不行。我将<FONT color=#ff0000>OpenMode.ForWrite换成OpenMode.ForRead就好了,但下面出错。因为不是以写方式打开的。是什么毛病?</FONT> 这是我在C#里面的代码:(成功的)
//绘制轻量多段线函数
public Polyline m_LightWeightPolyline(Point2dCollection m_ptarr)
{
Polyline m_lwpline = new Polyline();
for (int i = 0; i < m_ptarr.Count; i++)
{
m_lwpline.AddVertexAt(i, m_ptarr, 0.0, 0, 0);
}
Database m_db= HostApplicationServices.WorkingDatabase;
Transaction m_tr = m_db.TransactionManager.StartTransaction();
m_tr = m_db.TransactionManager.StartTransaction();
BlockTableRecord m_btr = (BlockTableRecord)m_tr.GetObject(m_db.CurrentSpaceId, OpenMode.ForWrite , false);
try
{
m_btr.AppendEntity(m_lwpline);
m_tr.AddNewlyCreatedDBObject(m_lwpline,true);
m_tr.Commit();
}
catch(System.Exception ex)
{
Editor m_ed= Application.DocumentManager.MdiActiveDocument.Editor;
m_ed.WriteMessage("多义线创建不成功!"+" --->错误信息: "+ex.Message);
}
finally
{
m_tr.Dispose();
}
return m_lwpline;
} <P> <FONT color=#ff0000>Dim btr As BlockTableRecord = trans.GetObject(btrid, OpenMode.ForWrite)<BR></FONT></P>
<P><FONT color=#ff0000>改写为下面试试</FONT><FONT color=#ff0000><FONT color=#000000> <BR> </FONT><FONT color=#ff0000>Dim btr As BlockTableRecord = (BlockTableRecord)trans.GetObject(btrid, OpenMode.ForWrite)</FONT></FONT></P>
<P><FONT color=#ff0000><FONT color=#ff0000>我的意思是加一步显式转换,我忘了VB是不是这样转换了,C#是<BR></P></FONT></FONT> 本帖最后由 作者 于 2006-8-22 21:00:23 编辑 <br /><br /> <P>谢谢楼上的给出主意,我再试试看。</P>
<P>我今天看了看。bt(btr.ModelSpace)在我的程序中是READONLY属性。请教大侠怎么才能将其也为非只读的。我想只要是非只读就不会有问题了。</P> 本帖最后由 作者 于 2006-8-24 21:34:19 编辑 <br /><br /> <P>解决了,是我将这个函数放到模块下导致的,我将其放入CLASS1下就好了。但这样我在别的窗体下没法调用了。请教各位高手如何调用?</P>
<P></P>
<P>是我太水了。呵……</P>
<P>这个问题彻底解决了。呵…… 是CAD焦点的问题。在我调用这段代码的时候CAD失去了焦点。唉!!!!</P> 如何设置焦点呢??
页:
[1]