求助
各位高手,本人有个问题,在网上找了好久也没有答案,在这提出来,希望高人指点;vbnet在cad中建立了一个选择集
代码 Dim mode As Integer
Dim conerP1(0 To 2) As Double, conerP2(0 To 2) As Double
mode = Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetCrossing
conerP1(0) = insertPnt(0) + Ra + 2 : conerP1(1) = insertPnt(1) + Ra + 2 : conerP1(2) = insertPnt(2)
conerP2(0) = insertPnt(0) - Ra - 2 : conerP2(1) = insertPnt(1) - Ra - 2 : conerP2(2) = insertPnt(2)
ss1.select(mode, conerP1, conerP2, , )
ss1.highlight(True)
问题是 如何将选择集中的图元一起转化为一个块,然后再其他图形中插入该块。在此先谢谢了。
希望明天来查看的时候有答案。
为什么没有人回答,没有人会吗?不可能啊 未处理 System.IO.FileNotFoundException
Message="找不到指定的模块。 (异常来自 HRESULT:0x8007007E)"
Source="catenary"
StackTrace:
在 WindowsApplication1.Form1.btnGearHT_Click(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(ApplicationContext context)
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
在 WindowsApplication1.My.MyApplication.Main(String[] Args) 位置 17d14f5c-a337-4978-8281-53493378c1071.vb:行号 81
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
什么原因啊???[/color] Public Function CreateBlock() As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase
'用于返回所创建的块的对象Id
Dim blockId As ObjectId = ObjectId.Null
'创建一个BlockTableRecord类的对象,表示所要创建的块
Dim record As New BlockTableRecord()
'设置块名
record.Name = "Room"
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim points As New Point3dCollection() '用于表示组成块的多段线的顶点
points.Add(New Point3d(-18.0, -6.0, 0.0))
points.Add(New Point3d(18.0, -6.0, 0.0))
points.Add(New Point3d(18.0, 6.0, 0.0))
points.Add(New Point3d(-18.0, 6.0, 0.0))
'创建组成块的多段线
Dim pline As New Polyline2d(Poly2dType.SimplePoly, points, 0.0, True, 0.0, 0.0, Nothing)
record.Origin = points(3) '设置块的基点
record.AppendEntity(pline) '将多段线加入到新建的BlockTableRecord对象
'以写的方式打开块表
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
If bt.Has("Room") = False Then '判断是否存在名为"Room"的块
blockId = bt.Add(record) '在块表中加入"Room"块
trans.AddNewlyCreatedDBObject(record, True) '通知事务处理
trans.Commit() '提交事务
End If
End Using
Return blockId '返回创建的块的对象Id
End Function Public Sub InsertBlockRef(ByVal blockName As String, ByVal point As Point3d, ByVal scale As Scale3d, ByVal rotateAngle As Double)
Dim db As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = db.TransactionManager.StartTransaction
'以读的方式打开块表
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
'如果没有blockName表示的块,则程序返回
If (bt.Has(blockName) = False) Then
Return
End If
'以读的方式打开blockName表示的块
Dim block As BlockTableRecord = trans.GetObject(bt(blockName), OpenMode.ForRead)
'创建一个块参照并设置插入点
Dim blockref As BlockReference = New BlockReference(point, bt(blockName))
blockref.ScaleFactors = scale '设置块参照的缩放比例
blockref.Rotation = rotateAngle '设置块参照的旋转角度
'以写的方式打开当前空间(模型空间或图纸空间)
Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
btr.AppendEntity(blockref) '在当前空间加入创建的块参照
'通知事务处理加入创建的块参照
trans.AddNewlyCreatedDBObject(blockref, True)
trans.Commit() '提交事务处理以实现块参照的真实加入
End Using
End Sub 谢谢 ,可是会提示
未处理 System.IO.FileNotFoundException
Message="找不到指定的模块。 (异常来自 HRESULT:0x8007007E)"
Source="catenary"
StackTrace:
在 WindowsApplication1.Form1.btnGearHT_Click(Object sender, EventArgs e)
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(ApplicationContext context)
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
在 WindowsApplication1.My.MyApplication.Main(String[] Args) 位置 17d14f5c-a337-4978-8281-53493378c1071.vb:行号 81
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim docLock As DocumentLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim blockId As ObjectId = ObjectId.Null
Dim record As BlockTableRecord = New BlockTableRecord()
record.Name = "Blockobj"
record.Origin = New Point3d(insertPnt(0), insertPnt(1), insertPnt(2))
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
For Each id As ObjectId In ss1.Value.GetObjectIds()
Dim ent As Entity = trans.GetObject(id, OpenMode.ForWrite)
Dim NewEnt As Entity = ent.Clone()
record.AppendEntity(NewEnt)
blockId = bt.Add(record)
trans.AddNewlyCreatedDBObject(record, True)
Next
trans.Commit()
End Using record.AppendEntity(NewEnt)
blockId = bt.Add(record)
trans.AddNewlyCreatedDBObject(record, True)
Next
trans.Commit()
这段代码,
在实体clone()完毕后,还没有通过事务提交到数据库。
就已经试图要把这个实体添加到块里面了。
试着改变一下代码。
先吧clone()后的实体添加到数据库,
返回这个实体的ObjectId,
然后再把这个实体添加到块表里试试?
呃~~vb我是业余的,
但希望会对你有帮助。
System.IO.FileNotFoundException应该是你的.NET方面出了点问题,你看看对文件的操作是不是有不合理的地方? 已解决,谢谢大家
页:
[1]
2