Author Topic: Update an Object Data Table field  (Read 3372 times)

0 Members and 1 Guest are viewing this topic.

arnolds

  • Guest
Update an Object Data Table field
« on: July 28, 2008, 05:54:35 PM »
I have a quick and dirty VBA that I am trying to complete and it's driving me crazy because it should be simple. I have an Object Data table with 6 fields. The table is attached to an entity and I want to change the value of one of the fields in the attached table but I can't seem to figure it out.

I already have the code to get the entity, the string, the table name, etc, I just can't seem to update the field I want. And, I can put all the data into a new version of the table and attach the table if there currently isn't one, I just can't seem to update an individual field. Any help/advice/direction would be greatly appreciated!

Swift

  • Swamp Rat
  • Posts: 596
Re: Update an Object Data Table field
« Reply #1 on: July 29, 2008, 09:01:52 AM »
Can we perhaps get a peak at the relevant code?

How are you selecting the entity? the string? the table name? How are you trying to update the field?

What version of AutoCad?

arnolds

  • Guest
Re: Update an Object Data Table field
« Reply #2 on: July 29, 2008, 01:53:16 PM »
Thanks for the quick reply. So, let's see if I can answer all those. Here's the gist of it (a very common issue)... I have a sanitary sewer network and each pipe is labelled with a string in the format: size material slope (space delimiter). I have an object data table attached to each line that has a unique ID as the first field (0 in the array) and a field for each of the 3 other data elements.

Here's how it works (like I said, quick and dirty):
Select the string and split it into the parts of the array:
  sset1.SelectOnScreen
  strPipeString = sset1.Item(0).TextString
  strPipeValues() = Split(strPipeString, , -1)

Select the line with the object data table attached:
  sset2.SelectOnScreen

Try to fill out the fields (this  is where I'm having the problems):
  Set odTable = amap.Projects(ThisDrawing).ODTables.Item(strODTable)
  'strODTable is set earlier in the routine with the name of the table, in this case "SAN-LIN"
  Set ODRCs = odTable.GetODRecords
  For Each acadObj In sset2
     ODRCs.Record.Item(1).Value = strPipeValues(0)
     ODRC.Item(2).Value = strPipeValues(1)
     ODRC.Item(3).Value = strPipeValues(2)
  Next

There's obviously something wrong in that part and I'm not sure if I need to make calls to .init or .update to complete it. It seems it should be easy but I'm missing something obvious.

Swift

  • Swamp Rat
  • Posts: 596
Re: Update an Object Data Table field
« Reply #3 on: July 29, 2008, 07:14:28 PM »
I'm traveling right now, but could you wblock out and post a  few entities for me to play with?

arnolds

  • Guest
Re: Update an Object Data Table field
« Reply #4 on: July 29, 2008, 07:29:56 PM »
You bet. See attached Sanitary.dwg. I've been working on it in 09 but it's still an 07 format so you should be able to look at it with an older version.

Object data table should be attached to the linework and each line is labelled with relevant information as well as dwg numbers (that's why I have the selection set for the text string, so I can grab the dwg number at the same time).

Thanks very much for the help.

Swift

  • Swamp Rat
  • Posts: 596
Re: Update an Object Data Table field
« Reply #5 on: July 29, 2008, 07:54:28 PM »
I've not helped yet, but I'll give it a peek when I get home in a bit.

Swift

  • Swamp Rat
  • Posts: 596
Re: Update an Object Data Table field
« Reply #6 on: August 06, 2008, 10:57:17 AM »
I've still not helped, I tried but I couldn't ever get any results. Have you made any headway?

arnolds

  • Guest
Re: Update an Object Data Table field
« Reply #7 on: August 06, 2008, 11:39:45 AM »
I've tried a few other things, more just hit and miss to see if it would work or not but I still can't seem to get it to work. I'm sure it's simple and I'm just missing something because I can attach a new table and fill out the values. I just can't edit values in an already attached table.

I'm going to try to get ahold of one or two of the 'deskers this week and see if I can get some assistance. If/when I can get an answer and have this thing figured out, I'll put my "rough" version up somewhere on here so someone else can polish it up or use it if needed.

Thanks

Swift

  • Swamp Rat
  • Posts: 596
Re: Update an Object Data Table field
« Reply #8 on: August 06, 2008, 11:45:43 AM »
just to clarify something... what version of AutoCAD are you using? Vertical app?

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Update an Object Data Table field
« Reply #9 on: August 06, 2008, 12:30:00 PM »
I assume, seeing as you're referring to OD Tables, that you're using Map. In the Sample folder under the root install of Map, there is a VBA folder.
In this folder you will find MapSample.dvb and MapSampleReadme.txt.

Having just read through the readme, there appears to be a macro in the above dvb file that does exactly what you're trying to do...have you looked at it?
Me

arnolds

  • Guest
Re: Update an Object Data Table field
« Reply #10 on: August 06, 2008, 12:41:20 PM »
just to clarify something... what version of AutoCAD are you using? Vertical app?

I'm using Map 2009.

Quote
Having just read through the readme, there appears to be a macro in the above dvb file that does exactly what you're trying to do...have you looked at it?

Yes, I did have a look at it and no, it doesn't do what I'm trying to do. The macro there attaches a new table and fills out the data in the table. I can do that without any problems. The issue I'm having is editing a field in the table after it's attached. I'm not sure why it would be different but it seems to be, it's very odd.

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Update an Object Data Table field
« Reply #11 on: August 06, 2008, 12:46:39 PM »
From the readme:

Code: [Select]
CREATE OBJECT DATA creates an object data table and attaches an
object data record to each new entity. This record includes the name,
layer, color, and handle of the entity. Then the macro changes the
color field in each record. NOTE: Before running CREATE OBJECT DATA,
create some new entities in the project drawing. Create them on dif-
ferent layers and with different colors.

It says it creates, attaches then modifies - isn't that what you described in your first post?
Me

arnolds

  • Guest
Re: Update an Object Data Table field
« Reply #12 on: August 06, 2008, 01:33:09 PM »
From the readme:

Code: [Select]
CREATE OBJECT DATA creates an object data table and attaches an
object data record to each new entity. This record includes the name,
layer, color, and handle of the entity. Then the macro changes the
color field in each record. NOTE: Before running CREATE OBJECT DATA,
create some new entities in the project drawing. Create them on dif-
ferent layers and with different colors.

It says it creates, attaches then modifies - isn't that what you described in your first post?

No, my first post was...
Quote
The table is attached to an entity and I want to change the value of one of the fields in the attached table...

I'd prefer to do it that was because if I attach a new one, then I have to retrieve all the values of the old one, update the new one, and attach it. Seems like too much effort just to change one field.
I also had a look at the .Init Method in the Records example and my function is very similar and according to the example it should work. It just doesn't.

arnolds

  • Guest
Re: Update an Object Data Table field
« Reply #13 on: August 06, 2008, 02:27:35 PM »
OK, I think I finally figured this one out. I do need to get the ODRecord collection from the ODRecords, edit it, then update the ODRecords. It appears I can't update field values in ODRecords directly.
I have to say, the example in the Help files for the .Init method shows something similar but it is REALLY bad and probably wouldn't work "as is".