明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1668|回复: 2

急需帮助@cad二次开发错误!

[复制链接]
发表于 2008-5-23 10:02:00 | 显示全部楼层 |阅读模式

我在cad命令行里加载dll,能够生成需要的图形.保存!问题出在我全部关闭cad时.cad 出现如图所示情况!.请大侠帮忙一下!谢谢!(虽然下次打开cad都没问题,但是每次都出现这样的对话框,感觉很烦人!希望高手能告知破解的方法!

不胜感激!

附上代码!(主要就是在当前cad 图形中加入圆,加入外部块,文字等)

using System;

using System.Collections.Generic;

using System.Text;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

using System.IO;

using Autodesk.AutoCAD.DatabaseServices;

namespace ClassLibrary2

{

    public class Class1

    {

 

        [CommandMethod("HelloWorld")]

        public void HelloWorld()

        {

            int kk;

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            string name1;

                ed.WriteMessage("Hello World");

 

 

                Circle circle; //这个是我们要加入到模型空间的圆

                BlockTableRecord btr;//要加入圆,我们必须打开模型空间

                BlockTable bt; //要打开模型空间,我们必须通过块表(BlockTable)来访问它

 

                //我们使用一个名为‘Transaction’的对象,把函数中有关数据库的操作封装起来

                Transaction trans;

                //使用TransactionManager的StartTransaction()成员来开始事务处理

                trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();

                //现在创建圆……请仔细看这些参数——注意创建Point3d对象的‘New’和Vector3d的静态成员ZAxis

                circle = new Circle(new Point3d(10, 10, 0), Vector3d.ZAxis, 2);

                circle.ColorIndex = 2;

                bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);

                //使用当前的空间Id来获取块表记录——注意我们是打开它用来写入

                btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);

                //现在使用btr对象来加入圆

                btr.AppendEntity(circle);

                trans.AddNewlyCreatedDBObject(circle, true); //并确定事务处理知道要加入圆!

 

                DBText mytext = new DBText();

                mytext.TextString = "B3-052-01-00";

                mytext.HorizontalMode = TextHorizontalMode.TextLeft;

                mytext.VerticalMode = TextVerticalMode.TextVerticalMid;

                mytext.AlignmentPoint = new Point3d(3.286, 88.7556, 0);

                mytext.Height = 12;

                mytext.WidthFactor = 2;

                   btr.AppendEntity(mytext);

                trans.AddNewlyCreatedDBObject(mytext, true);

 

                Document doc = Application.DocumentManager.MdiActiveDocument;

                string fname = "c:\\123.dwg";// "C:\\12341.DWG";

                if (!File.Exists(fname))

                fname = HostApplicationServices.Current.FindFile(fname, doc.Database,

 

FindFileHint.Default);

            Database db = new Database(false, false);

          

                db.ReadDwgFile(fname, FileShare.Read, true, null);

                            ObjectId idBTR = doc.Database.Insert("test", db, false);

                BlockReference bref = new BlockReference(Point3d.Origin, idBTR);

 

                  btr.AppendEntity(bref);

                  trans.AddNewlyCreatedDBObject(bref, true);

                 

trans.Commit();

                trans.Dispose();

 

            }

 

            else

            {

                return;

            }

 

        }

    }

}

 

 

 楼主| 发表于 2008-5-23 10:11:00 | 显示全部楼层
忘了图1!
 楼主| 发表于 2008-5-23 10:22:00 | 显示全部楼层

错误如下"

unhandle access violation reading ox7ec262dc exception at 645860bdh

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 14:24 , Processed in 0.232786 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表