djitit 发表于 2010-9-6 10:52:00

创建块后无法预览

我在代码里通过选择集创建一个块,创建后在窗体中预览这个块,但是无法预览,而调用cad自带的block命令创建块后就可以预览,why?<br/>下面是我创建块的代码<br/>&nbsp; &nbsp;Public Shared Function CreateBlock1(ByVal blackName As String)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Dim db As Database = HostApplicationServices.WorkingDatabase<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Dim blockImg As Drawing.Bitmap = Nothing '需要返回的Img对象<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Dim lock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Using lock<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Dim blockId As ObjectId = ObjectId.Null&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;'用于返回所创建的块的对象Id<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Dim record As BlockTableRecord = New BlockTableRecord()&nbsp;&nbsp;'创建一个BlockTableRecord类的对象,表示所要创建的块<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;record.Name = blackName&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; '设置块名&nbsp;&nbsp;<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;record.Origin = New Point3d(0, 0, 0)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'设置块的基点<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Dim trans As Transaction = db.TransactionManager.StartTransaction()<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Using trans<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; If bt.Has(record.Name) = False Then<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Dim res As PromptSelectionResult = ed.GetSelection() '选择对象<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;If res.Status = PromptStatus.OK Then<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;'&nbsp;&nbsp;foreach (ObjectId id in res.Value.GetObjectIds())<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Dim id As ObjectId = ObjectId.Null<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;For Each id In res.Value.GetObjectIds()<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Dim ent As Entity = trans.GetObject(id, OpenMode.ForWrite)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Dim NewEnt As Entity = ent.Clone()<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; record.AppendEntity(NewEnt)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Next<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;bt.Add(record)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'在块表中加入块<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;trans.AddNewlyCreatedDBObject(record, True) '通知事务处理<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;blockImg = BlockThumbnailHelper.GetBlockThumbanail(record.ObjectId)<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;End If<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; End If<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; trans.Commit()<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;End Using<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;End Using<br/>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Return Nothing<br/>

notigerking 发表于 2011-9-27 22:47:39

是不是你插入的太小了看不到啊。有这个可能
页: [1]
查看完整版本: 创建块后无法预览