.NET

Reply
Member
wojciech.janik
Posts: 5
Registered: ‎01-09-2013
Message 1 of 2 (155 Views)
Accepted Solution

C# AddToModelSpace

155 Views, 1 Replies
03-02-2014 12:03 PM

Hi,

 

I have some experience in vb.net, now i'm learning c#. I tried to translate my vb.net code to c# but I get an error:

 

 Cannot convert method group 'StartTransaction' to non-delegate type 'Autodesk.AutoCAD.DatabaseServices.Transaction'. Did you intend to invoke the method?

 

What am I doing wrong? Here is a code:

 

 

        public ObjectId AddToModelSpace(Database DBIn, Entity EntityIn)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            using (DocumentLock acLckDoc = doc.LockDocument())
            {

                using (Transaction myTrans = DBIn.TransactionManager.StartTransaction)
                {
                    BlockTable myBT = DBIn.BlockTableId.GetObject(OpenMode.ForRead);
                    BlockTableRecord myModelSpace = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite);
                    myModelSpace.AppendEntity(EntityIn);
                    myTrans.AddNewlyCreatedDBObject(EntityIn, true);
                    myTrans.Commit();
                    return EntityIn.ObjectId;

                }
            }
        }

 

Hi,

 

With C#, when you call a method without argument, you must explicitly write the empty argument list: ()

 

Transaction myTrans = DBIn.TransactionManager.StartTransaction()

 

This clearly differentiates calling to methods without argument and calling to properties. I also differentiates a calling to a function (to get the returned value) and the using of a delegate (passig the function name).

*Expert Elite*
_gile
Posts: 2,086
Registered: ‎04-29-2006
Message 2 of 2 (108 Views)

Re : C# AddToModelSpace

03-02-2014 11:15 PM in reply to: wojciech.janik

Hi,

 

With C#, when you call a method without argument, you must explicitly write the empty argument list: ()

 

Transaction myTrans = DBIn.TransactionManager.StartTransaction()

 

This clearly differentiates calling to methods without argument and calling to properties. I also differentiates a calling to a function (to get the returned value) and the using of a delegate (passig the function name).

Gilles Chanteau
Announcements
Autodesk Alert | We are currently working on restoring Previous Version License request access in the Autodesk Subscription Center. If you are a subscription customer and would like to request a Previous Version License, please use this link as a temporary workaround. We apologize for the inconvenience and thank you for your patience.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.