AutoCAD二次开发初级入门教程.docx_第1页
AutoCAD二次开发初级入门教程.docx_第2页
AutoCAD二次开发初级入门教程.docx_第3页
AutoCAD二次开发初级入门教程.docx_第4页
AutoCAD二次开发初级入门教程.docx_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1. Components of the AutoCAD .NET APIDllAcDbMgd.dll. Use when working with objects in a drawing file. AcMgd.dll. Use when working with the AutoCAD application.AcCui.dll. Use when working with customization files.Before classes, structures, methods, and events found in one of the AutoCAD .NET API related DLLs can be used, you must reference the DLL to a project. After a DLL is referenced to a project, you can utilize the namespaces and the components in the DLL file in your project. Once a AutoCAD .NET API DLL is referenced, you must set the Copy Local property 局部性质of the referenced DLL to False.Reason:The Copy Local property determines if Microsoft Visual Studio creates a copy of the referenced DLL file and places it in the same directory as the assembly file of the project when it is built. Since the referenced files already ship with AutoCAD, creating copies of referenced DLL files can cause unexpected results when you load your assembly file in AutoCAD. 2. To reference an AutoCAD .NET API DLL In Microsoft Visual Studio, click View menu Solution Explorer to display the Solution Explorer if it is not already displayed. In the Solution Explorer, on the toolbar along the top, click Show All Files. Right-click the References node and click Add Reference. In the Add Reference dialog box, Browse tab, select the DLL file that contains the library you want to use and click OK. In the Solution Explorer, click the plus sign to the left the References node to expand it. Select the referenced library from the References node. Right-click over the selected reference and click Properties.In the Properties window, click the Copy Local field and select False from the drop-down list.3. 合适网站终于找到了/ACD/2010/ENU/AutoCAD%20.NET%20Developers%20Guide/帮助/adsk/servlet/index?siteID=123112&id=770215#vbatonetSDK /developautocaddiscussion groups////autocad-net-developers-guide4. 移植思路添加dotnet的应用Autocad2010 type library(类型库)Com autodesk.autocad.dllCmon.dllAcmgd.dllAcadmgd.dll5. Thisdrawing的获得方法Private readonly property thisdrawing() as acaddocumentGet Return autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.acaddocumentEnd getEnd propertyVbdotnet必须指明其数据类型。Cint,cstring6. 基本定义Public sub starthere()Dim c as object Set c = new class1c.showmessage”模块运行中”end sub7. autocad对象层次Transaction :事务,由用户和应用程序执行的一个动作或一系列动作Housed:封装subsequent step:后续步骤database access:数据库存取Symbol Tables:符号集Object References:参照对象Encapsulate:封装Delineate:描述database-resident:数据库驻留8. 具体代码 Get the current document and database, and start a transactionDim acDocAs Document = Application.DocumentManager.MdiActiveDocumentDim acCurDb As Database = acDoc.Database详见lab3. E:net开发autocad_2010_dotnet_trainingVB.NET创建3个图形并分装在一个图块中。create an Employee object (1 circle, 1 ellipse and one MText object) which is housed by a Block Definition called EmployeeBlock which uses a layer called EmployeeLayer which is inserted into AutoCADs Model Space using a BlockReference type.如果想要在modelspace中画图,必须先将modelspace打开,而将其打开,必须打开块表blocktable.9. try-catch语句由一个 try 块后跟一个或多个 catch 子句构成,这些子句指定不同的异常处理程序。在同一个 try-catch 语句中可以使用一个以上的特定 catch 子句。这种情况下 catch 子句的顺序很重要,因为会按顺序检查 catch 子句。将先捕获特定程度较高的异常,而不是特定程度较小的异常。catch和finally一起使用的常见方式是:在try块中获取并使用资源,在catch块中处理异常情况,并在finally块中释放资源。10. usingusing关键字有两个主要用途:作为指令,用于为命名空间创建别名或导入其他命名空间中定义的类型。请参见using 指令。作为语句,用于定义一个范围,在此范围的末尾将释放对象。请参见using 语句。/zh-cn/library/sf0df423(v=VS.80).aspx11. 事务访问并可能更新数据库中各种数据项的一个程序执行单元(unit)。事务由事务开始(begin transaction)和事务结束(end transaction)之间执行的全体操作组成。在关系数据库中,一个事务可以是一条SQL语句,一组SQL语句或整个程序。事务是恢复和并发控制的基本单位。事务应该具有4个属性:原子性、一致性、隔离性、持续性。这四个属性通常称为ACID特性。原子性(atomicity)。一个事务是一个不可分割的工作单位,事务中包括的诸操作要么都做,要么都不做。一致性(consistency)。事务必须是使数据库从一个一致性状态变到另一个一致性状态。一致性与原子性是密切相关的。隔离性(isolation)。一个事务的执行不能被其他事务干扰。即一个事务内部的操作及使用的数据对并发的其他事务是隔离的,并发执行的各个事务之间不能互相干扰。持久性(durability)。持续性也称永久性(permanence),指一个事务一旦提交,它对数据库中数据的改变就应该是永久性的。接下来的其他操作或故障不应该对其有任何影响。事务(Transaction)是并发控制的基本单位。所谓事务,它是一个操作序列,这些操作要么都执行,要么都不执行,它是一个不可分割的工作单位。例如,银行转帐工作:从一个帐号扣款并使另一个帐号增款,这两个操作要么都执行,要么都不执行。所以,应该把他们看成一个事务。事务是数据库维护数据一致性的单位,在每个事务结束时,都能保持数据一致性。ROLLBACK表示要撤消(Undo)该事务已做的一切操作,回退到事务开始的状态。COMMIT表示提交事务中的一切操作,使得对数据库的改变生效。12. 自动加载.net详细参见.net开发书籍15.3。13. 解锁文档Document newDoc = Application.DocumentManager.Add(); newDoc.LockDocument();/ 锁定 HostApplicationServices.WorkingDatabase = newDoc.Database; Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction() BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = btBlockTableRecord.ModelSpace.GetObject(OpenMode.ForWrite) as BlockTableRecord;当你要修改一个不是当前文档的数据库时,或者你要阻止别的执行文本来修改该数据库时,你需要锁定文档。如果是以只读方式打开某个对象是不用锁定文档的,但是以写方式打开对象时,最好锁定文档。當你要修改文檔內容或資料庫時需要以寫入的方式打開,需要先進行圖檔的鎖定Dim documentLock As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument().documentLock.Dispose()若只是讀取圖檔的圖檔資訊,就不需要鎖定圖檔14. 文件的打开与读写方式按照访问模式,共分为三种。顺序文件、随机文件和二进制文件顺序文件的访问规则是读写数据时按照“顺序”依次进行访问,不能跳过前面而直接读取后面的部分。顺序访问模式是专门用来处理15. 遍历数据库Dim oCnn As New ADODB.Connection Dim rs As New ADODB.RecordsetoCnn.ConnectionString = Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initia

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论