湖面之舟 发表于 2006-11-10 23:09:00

学习VB.net二次开发例程

<P>&nbsp; &lt;CommandMethod("GetCircle")&gt; Public Sub GetCircle()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '创建一个选择实体的选择集选项,并限制为只能选择圆(使用了AddAllowedClass函数)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim entitySelectionOpts As PromptEntityOptions = New PromptEntityOptions("\nSelect Circle")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entitySelectionOpts.SetRejectMessage("\nOnly Circles may be selected.")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; entitySelectionOpts.AddAllowedClass(GetType(Circle), True)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '开始选择圆的过程 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim entitySelectionResult As PromptEntityResult = ed.GetEntity(entitySelectionOpts)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '如果成功选择了一个圆,就在命令行显示圆的半径 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If entitySelectionResult.Status = PromptStatus.OK Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT color=#ff0000>DispalyCircleRadius(entitySelectionResult.ObjectId)</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; End Sub</P>
<P><BR>&nbsp;&nbsp;&nbsp; Private Sub DispalyCircleRadius(ByVal circleId As ObjectId)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim trans As Transaction<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT color=#ff0000>trans = ed.Document.TransactionManager.StartTransaction<BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim selectedCircle As Circle = CType(trans.GetObject(circleId, OpenMode.ForRead), Circle)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.ShowAlertDialog("选择的园半径为:" + selectedCircle.Radius.ToString)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trans.Commit()<BR>&nbsp;&nbsp;&nbsp; End Sub</P>
<P>编译的时候,红色标示部分总是提示类型不能转换,请问大家遇到过吗?该怎么解决呢?</P>

湖面之舟 发表于 2006-11-10 23:14:00

<P>已经解决,呵呵</P>
<P>是由于同一个解决方案中其它项目加载了2005的库文件</P>

rdhhb 发表于 2006-12-4 06:58:00

楼上的朋友。请问你是如何设置。NET环境的?能否教教我?谢谢
页: [1]
查看完整版本: 学习VB.net二次开发例程