.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

My button commands not work?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
h.sezenn
600 Views, 3 Replies

My button commands not work?

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Colors

Public Class Container3


    <CommandMethod("CreateAndAssignALayer")> _
    Public Sub CreateAndAssignALayer()
        '' Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

            '' Open the Layer table for read
            Dim acLyrTbl As LayerTable
            acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
                                         OpenMode.ForRead)

            Dim sLayerName As String = "Center"

            If acLyrTbl.Has(sLayerName) = False Then
                Dim acLyrTblRec As LayerTableRecord = New LayerTableRecord()

                '' Assign the layer the ACI color 1 and a name
                acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 1)
                acLyrTblRec.Name = sLayerName

                '' Upgrade the Layer table for write
                acLyrTbl.UpgradeOpen()

                '' Append the new layer to the Layer table and the transaction
                acLyrTbl.Add(acLyrTblRec)
                acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
            End If

            '' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
                                         OpenMode.ForRead)

            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

            '' Create a circle object
            Dim acCirc As Circle = New Circle()
            acCirc.Center = New Point3d(2, 2, 0)
            acCirc.Radius = 1
            acCirc.Layer = sLayerName

            acBlkTblRec.AppendEntity(acCirc)
            acTrans.AddNewlyCreatedDBObject(acCirc, True)

            '' Save the changes and dispose of the transaction
            acTrans.Commit()
        End Using
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cls As Container3
        cls = New Container3()
        cls.CreateAndAssignALayer()
    End Sub
End Class

 I have like this code.

if I use the <CommandMethod("CreateAndAssignALayer")> _

this code. my circle was drawn.as you see at picture1

31-03-13-q3-1.png

 

but when I try to click button1

my code has an error.

31-03-13-q3-2.png

also it it detials.

Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
Autodesk.AutoCAD.Runtime.Exception: eLockViolation
   at Autodesk.AutoCAD.DatabaseServices.Transaction.GetObject(ObjectId id, OpenMode mode)
   at menu_container_treeview.Container3.CreateAndAssignALayer() in D:\menu_container_treeview\Container3.vb:line 49
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
AdApplicationFrame
    Assembly Version: 0.0.0.0
    Win32 Version: 3.2.23.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AdApplicationFrame.DLL
----------------------------------------
Acdbmgd
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcdbMgd.DLL
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
msvcm90
    Assembly Version: 9.0.30729.6161
    Win32 Version: 9.00.30729.6161
    CodeBase: file:///C:/Windows/WinSxS/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251/msvcm90.dll
----------------------------------------
AdWindows
    Assembly Version: 3.2.23.0
    Win32 Version: 3.2.23.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AdWindows.DLL
----------------------------------------
PresentationFramework
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll
----------------------------------------
WindowsBase
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
PresentationCore
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_64/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll
----------------------------------------
System.Xaml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PresentationFramework.Aero
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Acmgd
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/Acmgd.DLL
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
AcWindows
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcWindows.DLL
----------------------------------------
AcCui
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcCui.DLL
----------------------------------------
PresentationFramework-SystemXml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemXml/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemXml.dll
----------------------------------------
WindowsFormsIntegration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsFormsIntegration/v4.0_4.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll
----------------------------------------
AcWindows.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcWindows.resources.DLL
----------------------------------------
ContextualTabSelectorRules
    Assembly Version: 0.0.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcWindows.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
ManagedMC3
    Assembly Version: 5.8.0.0
    Win32 Version: 5.8.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/ManagedMC3.DLL
----------------------------------------
PresentationFramework-SystemCore
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework-SystemCore/v4.0_4.0.0.0__b77a5c561934e089/PresentationFramework-SystemCore.dll
----------------------------------------
UIAutomationTypes
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
AcTaskDialogs
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcTaskDialogs.DLL
----------------------------------------
AcTaskDialogs.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcTaskDialogs.resources.DLL
----------------------------------------
AcLayer
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcLayer.DLL
----------------------------------------
AcLayer.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcLayer.resources.DLL
----------------------------------------
AcButterflyExt
    Assembly Version: 1.0.0.23
    Win32 Version: 1.0.0.23
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcButterflyExt.DLL
----------------------------------------
AcButterflyExt.resources
    Assembly Version: 1.0.0.23
    Win32 Version: 1.0.0.23
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcButterflyExt.resources.DLL
----------------------------------------
PresentationFramework.Luna
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Luna/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Luna.dll
----------------------------------------
AcMrUi
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcMrUI.DLL
----------------------------------------
AcMrUi.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcMrUi.resources.DLL
----------------------------------------
AcMr
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcMr.DLL
----------------------------------------
System.Runtime.Serialization
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
System.resources
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.resources/v4.0_4.0.0.0_tr_b77a5c561934e089/System.resources.dll
----------------------------------------
AcDialogToolTips
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcDialogToolTips.DLL
----------------------------------------
AcDialogToolTips.resources
    Assembly Version: 18.2.0.0
    Win32 Version: 18.2.51.0.0
    CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcDialogToolTips.resources.DLL
----------------------------------------
UIAutomationProvider
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
huseyin_menu_container_treeview
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/AUTOCAD/HAZIR%20PROGRAMLAR/huseyin_menu_container_treeview/huseyin_menu_container_treeview/bin/Release/huseyin_menu_container_treeview.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 11.0.50709.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
mscorlib.resources
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_tr_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------

************** JIT Debugging **************
Application does not support Windows Forms just-in-time (JIT)
debugging. Contact the application author for more
information.


 

           

line 48 ___Dim acBlkTblRec AsBlockTableRecord

line 49____acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _

line 50____OpenMode.ForWrite)

 

 

 I want to add my circle with button. but I dont know how I do this?

Help me !

 

_____________________________________________________________________________________
Everything For Duct
3 REPLIES 3
Message 2 of 4
Alfred.NESWADBA
in reply to: h.sezenn

Hi,

 

try to lock the document before you start the transaction (and .Dispose afterwards to free the document or Using ... End Using).

 

   Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
   Using acDocLock As DocumentLock = acDoc.LockDocument
      'do you changes

   End Using

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4
h.sezenn
in reply to: Alfred.NESWADBA

Thank you your answer. it is works 🙂

 

_____________________________________________________________________________________
Everything For Duct
Message 4 of 4
Alfred.NESWADBA
in reply to: h.sezenn

You are welcome, glad to know it solved your problem,, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost