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

C# AddToModelSpace

1 REPLY 1
SOLVED
Reply
Message 1 of 2
wojciech_janik
690 Views, 1 Reply

C# AddToModelSpace

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;

                }
            }
        }

 

1 REPLY 1
Message 2 of 2
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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