Sorry for the weird
I'm writing a plug-in for AutoCAD 2014 using C# and the .NET platform. I extended Autodesk's Table class like so
public class OpeningDataTable : Autodesk.AutoCAD.DatabaseServices.Table
The idea is that I want to pull a table already drawn on an AutoCAD drawing out of the drawing as an instance of OpeningDataTable so I can manipulate the data with methods I've written. I am doing that like so
OpeningDataTable myTable = checkForExistingTable(true); public Autodesk.AutoCAD.DatabaseServices.Table checkForExistingTable(bool isWindow) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; //Current drawing Transaction tr = doc.TransactionManager.StartTransaction(); DocumentLock docLock = doc.LockDocument(); TypedValue[] tableItem = new TypedValue[] { new TypedValue(0, "ACAD_TABLE") }; SelectionFilter tableSelecFilter = new SelectionFilter(tableItem); Editor ed = doc.Editor; //Editor object to ask user where table goes, subclass of Document using (tr) { PromptSelectionResult selectResult = ed.SelectAll(tableSelecFilter); if (selectResult.Status == PromptStatus.OK) { SelectionSet tableSelSet = selectResult.Value; for (int i = 0; i < tableSelSet.Count; i++) { Autodesk.AutoCAD.DatabaseServices.Table tableToCheck = (Autodesk.AutoCAD.DatabaseServices.Table)tr.GetObject(tableSelSet[i].ObjectId, OpenMode.ForRead); String tableTitle = tableToCheck.Cells[0, 0].Value.ToString(); if(tableTitle.Equals("Window Schedule") && isWindow == true) return (OpeningDataTable)tableToCheck; if (tableTitle.Equals("Door Schedule") && isWindow == false) return (OpeningDataTable)tableToCheck; } } return null; } }
However I get an error saying that I cannot convert a Table object (the parent class) to an OpeningDataTable object (the child class). I'm looking for a simple workaround to this issue
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
Your checkForExistingTable() method returns an Autodesk.AutoCAD.DatabaseServices.Table instance, not an OpeningDataTable one.
If you want to implicitly (or explicitly) cast a Table instance into an OpeningDataTable one, you have to implement (implicit or explicit) conversion operators in the OpeningDataTable class definition.