Page 1 of 1

Curve.GetGeCurve throws "Operation is not valid due to the current state of the object"

Posted: Thu Jun 11, 2020 4:00 pm
by geza.szabo
Hi, I am trying to get the Curve3d of a Curve without success. Here is a simple command. If I select a curve and run the command I get System.InvalidOperationException.

How can I make this work?

Code: Select all

		public static void Execute()
		{
			var document = Application.DocumentManager.MdiActiveDocument;
			var database = document.Database;
			var selection = CommandHelper.GetOrAskSelection(document);
			var selectionSet = selection.Value;
			using (var transaction = database.TransactionManager.StartTransaction())
			{
				var curves = new List<Curve3d>();
				foreach (var id in selectionSet.GetObjectIds())
				{
					var entity = (Entity) transaction.GetObject(id, OpenMode.ForRead);

					if (entity is Curve curve)
					{
						curves.Add(curve.GetGeCurve()); <-- error here
					}
				}
			}
		}

Re: Curve.GetGeCurve throws "Operation is not valid due to the current state of the object"

Posted: Thu Jun 11, 2020 6:49 pm
by QuanNguyen
Hi

Just checked and I get the same exception if the curve is Line, Spline, Xline, or ray.

it works if the curve is Arc, circle, polyline, 3dpolyline, ellipse.

Code: Select all

                        var entity = (Entity)transaction.GetObject(id, OpenMode.ForRead);

                        if (entity is Line || entity is Spline || entity is Xline || entity is Ray)
                        {
                            // error
                        }
                        else if (entity is Curve curve)
                        {
                            curves.Add(curve.GetGeCurve());
                        }