DeleteRows in Table

Hi everyone.
I want towork with some existing tables.
Everything is working pretty well so far, but sometimes i have to delete rows in the table especially when i want to update the table.
My Problem…there is no Node ootb.

Is here someone who can create me one with python? i haven’t learned it yet.:slight_smile:

IN[0] → Table
IN[1] → Rownumbers
OUT[0] → Table

At least, mention the Database type, there are lots of types.

Look in arkance and civil toolkit libraries.

1 Like

If you want to create an AutoCAD table you can use the Arkance Systems library. Read the table into a series of rows, delete some rows (basic list edit) and generate a new table.

1 Like

I’m sure that this is exactly what i want and it seems extremly easy, but i can’t write python yet. :sweat_smile:

I want to delete the marked rows:

And i think to read the data of the table, to delete the lists and create a new table isn’t an option, because it don’t understand the integrated blockreferences in the other rows.

Ah yes, that doesn’t work. I’ll put it on the wishlist.

Sorry I’m trying to use the Table.DeleteRows Method but my system is breaking and I don’t understand how to select a table in python or use the method on a table. I don’t see anywhere to use db.Table.DeleteRows(int, int). If the table object is a variable named table, would it be table.db.Table.DeleteRows(int, int)? I don’t see any way to pass the table object in as a variable into the function…

I do see that Kean has some example code for working with a table on his blog: Creating an AutoCAD table using .NET - Through the Interface

Here’s a simple example.

import clr


from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *

tbl = IN[0]
startRow = IN[1]
numRows = IN[2]

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            acTbl = tbl.InternalDBObject
            acTbl.DeleteRows(startRow, numRows)
OUT = tbl

Thanks so much Zachri, I kept crashing autoCAD and was getting frustrated so I really appreciate your help. It works great. Here is a .dyn for anyone that needs reference. Cool that we can select tables with @Anton_Huizinga’s Arkance nodes too.
DeleteTableRows.dyn (31.5 KB)

Can you please help me make sure I understand correctly? I don’t see a “.InternalDBObject” in the methods for the table class, nor do I see it in the documentation anywhere for that matter. How would someone know this method exists? I see in the class hierarchy, the table class is also an “Entity” and a “DBObject”. Since it doesn’t mention “Internal” I would expect the method to be “.DBObject” instead. Do we always have to make sure the object is in the form of a “DBObject” rather than the subclass to work on it?

So UpgradeOpen() is used when we aren’t using db.TransactionManager.StartTransaction().getObject("____", OpenMode.ForWrite), since we don’t have a function that is opening the object for write?

Also, we don’t use db.Table.“certain function”, we use “a table in the form of a database object”.“certain function”? Guessing that is pretty consistent.

One quick correction: it’s a property, not a method. I’m being pedantic, but the terms do matter in this case. With that said, the InternalDBObject and InternalObjectId properties are not properties of AutoCAD objects, but rather the Dynamo objects that encapsulate them. You won’t find anything related to Dynamo in the AutoCAD or Civil .NET API docs. For that matter, there is basically no developer documentation for the Civil 3D implementation of Dynamo. That doesn’t mean that it’s a total black box, however. You can still browse the DLLs and look at all the members to start understanding the class hierarchy. I use Visual Studio for all of that. So to the last part of your question, you wouldn’t know that it exists without (a) someone telling you, (b) digging through the DLLs to find it, or (c) using the Python dir() function.

The first answer should clarify some of this. It has “internal” in the name because the Dynamo wrapper class encapsulates the internal AutoCAD object, so it’s just a convention to put “internal” in the property name so it’s descriptive. And then the answer to the question above is no, it would actually be somewhat counterproductive to cast a derived class (e.g. Table) to a base class (e.g. DBObject) because then you would not be able to access any of the members specific to the derived class.

You can only use the UpgradeOpen() and DowngradeOpen() methods to change the open mode of an object that has previously been opened. So if it applies, then it’s just a little cleaner to write. If all you have is an Object ID, then you need to use Transaction.GetObject in order to retrieve the object from the database. And to be completely correct, the use of DowngradeOpen() is technically not needed in this case because the object’s open state will be cleaned up when the transaction is disposed. I just wrote it out of habit.

No, db.Table will throw an exception because a Database object has no property called “Table”. The correct way to write what you’re trying to say is…




where Table is an instance of a Table object.

A few more notes. If you’re planning to start digging more into this, I highly recommend using a real IDE such as PyCharm or Visual Studio for development and transitioning away from using the Python node in Dynamo. It’s going to be a lot easier to learn by taking advantage of tools for code completion, object browsing, refactoring, etc. Code Completion/IntelliSense alone will save you hours of time trying to figure out which members are valid for a given object. Some might argue otherwise, but that’s my recommendation.


Okay I think I understand. It makes more sense that it’s a property and not a method. Yes, please be pedantic as I need to learn and understand, it’s much appreciated. So that’s why I didn’t see it in the autoCAD documentation. Guess I’ll be looking in DLLs in Visual Studio from now on as an additional resource. Makes me feel a bit better knowing that I was struggling because of a black box and I’m not totally inept at looking through documentation! hah! (I’ve just started trying to use the dir() function and it is a big help).

Okay, so .InternalDBObject is a property that is actually encapsulating the internal AutoCAD object for dynamo use, it’s not changing the class of the AutoCAD object up the hierarchy to a more rudimentary Type. That makes more sense because otherwise we, like you say, wouldn’t have what you call the “members” of the class available to us such as the “.deleteRows” method. I assume that members is a term that refers to both Properties and Methods. Makes sense, thanks! Just a bit confusing since I saw “DBObject” in both contexts.

Thanks for clarifying. I didn’t realize that we had to of opened an object prior and that the transaction being disposed handles UpgradeClose(). I think that if it’s usable, the UpgradeOpen() method seems great because sometimes I feel confused trying to find an objectID. But thanks to your comment I now know that I can use InternalObjectId so maybe it won’t be as difficult now.

Awesome. I’ll have to try to use a different IDE. I do find the python node to be difficult to use. Anything I do in a jupyter notebook feels so much easier and I feel way more comfortable in it. I’m assuming I just have to somehow import the .dll files to be used by an IDE like jupyter notebook or pycharm. I’ve never done that though. I’ve only ever just imported modules.

Thanks so much for your time in typing up the reply. It’s a HUGE help!

Your Node works perfect.

Thank you for that :slight_smile:

You could write a book and publish it :wink:

I would advice to do it anyway, I had issues with that one day when I executed a script a second time, object was already open. Can’t reproduce since I was not testing that particular issue, saw it in the crash log.

It’s all thanks to Zachri, not me! I’m just learning :slight_smile:


Can you provide any more information regarding how you’re using an external IDE? Possibly an image of some example code? From what I see online I need to use the “ctypes” to import the .dll’s?

I think that would be better in a different thread and probably under the Developers category.

1 Like