wuqiu1986 发表于 2014-3-26 16:51:36

求教关于向块中添加实体的问题

找到该块的块表记录,然后利用AppendEntity,向块表记录中添加Entity对象,这个思路不对吗,运行的时候提示错误
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
Autodesk.AutoCAD.Runtime.Exception: eAlreadyInDb
   在 Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.AppendEntity(Entity entity)
   在 向块中添加物体.Class1.BlockAddEnt() 位置 F:\VB\vb.net-cad\向块中添加物体\向块中添加物体\Class1.vb:行号 29
   在 Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   在 Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   在 Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   在 Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()


************** 已加载的程序集 **************
mscorlib
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18444 built by: FX451RTMGDR
    基本代码:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
AdApplicationFrame
    程序集版本:0.0.0.0
    Win32 版本:3.2.23.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AdApplicationFrame.DLL
----------------------------------------
msvcm90
    程序集版本:9.0.30729.6161
    Win32 版本:9.00.30729.6161
    基本代码:file:///C:/Windows/WinSxS/x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57/msvcm90.dll
----------------------------------------
Acdbmgd
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcdbMgd.DLL
----------------------------------------
System
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
AdWindows
    程序集版本:3.2.23.0
    Win32 版本:3.2.23.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AdWindows.DLL
----------------------------------------
PresentationFramework
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll
----------------------------------------
WindowsBase
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
PresentationCore
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_32/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll
----------------------------------------
System.Xaml
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll
----------------------------------------
AdWindows.resources
    程序集版本:3.2.23.0
    Win32 版本:3.2.23.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/zh-CN/AdWindows.resources.DLL
----------------------------------------
System.Xml
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PresentationFramework.Aero
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll
----------------------------------------
System.Drawing
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
PresentationCore.resources
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationCore.resources/v4.0_4.0.0.0_zh-Hans_31bf3856ad364e35/PresentationCore.resources.dll
----------------------------------------
Acmgd
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/Acmgd.DLL
----------------------------------------
System.Core
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Configuration
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
AcWindows
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcWindows.DLL
----------------------------------------
PresentationFramework.resources
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.resources/v4.0_4.0.0.0_zh-Hans_31bf3856ad364e35/PresentationFramework.resources.dll
----------------------------------------
AcCui
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcCui.DLL
----------------------------------------
PresentationFramework-SystemXml
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXml/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXml.dll
----------------------------------------
WindowsFormsIntegration
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsFormsIntegration/v4.0_4.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll
----------------------------------------
AcWindows.resources
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/zh-CN/AcWindows.resources.DLL
----------------------------------------
ContextualTabSelectorRules
    程序集版本:0.0.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcWindows.dll
----------------------------------------
System.Windows.Forms
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
ManagedMC3
    程序集版本:5.8.0.0
    Win32 版本:5.8.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/ManagedMC3.DLL
----------------------------------------
PresentationFramework-SystemCore
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemCore/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemCore.dll
----------------------------------------
UIAutomationTypes
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
AcLayer
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcLayer.DLL
----------------------------------------
AcLayer.resources
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/zh-CN/AcLayer.resources.DLL
----------------------------------------
AcButterflyExt
    程序集版本:1.0.0.23
    Win32 版本:1.0.0.23
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcButterflyExt.DLL
----------------------------------------
AcButterflyExt.resources
    程序集版本:1.0.0.23
    Win32 版本:1.0.0.23
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/zh-CN/AcButterflyExt.resources.DLL
----------------------------------------
System.resources
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.resources.dll
----------------------------------------
PresentationFramework.Luna
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Luna/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Luna.dll
----------------------------------------
mscorlib.resources
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Xaml.resources
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Xaml.resources.dll
----------------------------------------
AcMrUi
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcMrUI.DLL
----------------------------------------
AcMrUi.resources
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/zh-CN/AcMrUi.resources.DLL
----------------------------------------
AcMr
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcMr.DLL
----------------------------------------
System.Runtime.Serialization
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
AcDialogToolTips
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/AcDialogToolTips.DLL
----------------------------------------
AcDialogTooltips.resources
    程序集版本:18.2.0.0
    Win32 版本:18.2.51.0.0
    基本代码:file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20Simplified%20Chinese/zh-CN/AcDialogToolTips.resources.DLL
----------------------------------------
UIAutomationProvider
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
向块中添加物体
    程序集版本:1.0.0.0
    Win32 版本:1.0.0.0
    基本代码:file:///F:/360%E4%BA%91%E7%9B%98/VB/vb.net-cad/%E5%90%91%E5%9D%97%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%89%A9%E4%BD%93/%E5%90%91%E5%9D%97%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%89%A9%E4%BD%93/obj/Debug/%E5%90%91%E5%9D%97%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%89%A9%E4%BD%93.dll
----------------------------------------
System.Windows.Forms.resources
    程序集版本:4.0.0.0
    Win32 版本:4.0.30319.18408 built by: FX451RTMGREL
    基本代码:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_zh-Hans_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何未经处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。

sieben 发表于 2014-3-27 08:31:00

你重复添加了
把你的代码贴出来

wuqiu1986 发表于 2014-3-28 20:55:52

sieben 发表于 2014-3-27 08:31 static/image/common/back.gif
你重复添加了
把你的代码贴出来

    <CommandMethod("BlockAddEnt")> Public Sub BlockAddEnt()
      Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
      Dim acCurDb As Database = acDoc.Database
      Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction
            Dim acEntOpts As PromptEntityOptions = New PromptEntityOptions("")
            acEntOpts.Message = vbLf & "选择块"
            acEntOpts.AllowNone = False
            Dim acEntRsl As PromptEntityResult = acDoc.Editor.GetEntity(acEntOpts)
            acEntOpts.Message = vbLf & "选择要添加的物体"
            Dim acEntFromRsl As PromptEntityResult = acDoc.Editor.GetEntity(acEntOpts)
            If acEntRsl.Status = PromptStatus.OK And acEntFromRsl.Status = PromptStatus.OK Then
                Dim acBlkTbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
                Dim acBlkRef As BlockReference = acTrans.GetObject(acEntRsl.ObjectId, OpenMode.ForWrite)
                Dim acBlkRec As BlockTableRecord = acTrans.GetObject(acBlkRef.BlockTableRecord, OpenMode.ForWrite)

                Dim acMat As Matrix3d
                acMat = acBlkRef.BlockTransform
                Dim acEntFrom As Entity = acTrans.GetObject(acEntFromRsl.ObjectId, OpenMode.ForWrite)
                acEntFrom.TransformBy(acMat.Inverse)

                acBlkRec.AppendEntity(acEntFrom)
                acTrans.Commit()
            End If
      End Using
    End Sub

sieben 发表于 2014-3-29 08:52:41

acBlkRec.AppendEntity(acEntFrom)
这一句多余的
一个实体生成后(能被选择了),肯定就已经属于某个图块,你不能再加到另外个图块
你想换实体所属的图块,可以更改实体的blockrecordId属性即可,属性具体拼写我不确定,差不多吧
页: [1]
查看完整版本: 求教关于向块中添加实体的问题