Jump to content

Object Data to Attribute Data to perfection


cris2fur

Recommended Posts

I'm working in AutoCAD Map 3D 2008 and Autocad Civil 3D 2009.

 

The General Task:

I want to convert the object data to attribute data so that I can export it to an Excel file, add another column of data, and then import that new data as attribute data.

 

The Specific Task:

I have thousands of campus water meter locations (a block with a small icon, attribute data, and object data) that belong to two different systems, domestic water and lake water. Each of these blocks has object data item (a barcode tag) that I want to show as a label next to the block.

 

However, before I do that, I want to export that barcode data to an excel file so I add a column (eventually a new piece of attribute data) that says whether or not that specific water meter is radio read or manually read. I want to then import that radio read/manual read excel file back into autocad and have an X appear on the block icon if it is radio read. I also want the barcode information to show up as a label.

 

My problem:

I can't get the barcode object data to export with the locations in one easy excel sheet that I can simply import after I have made my changes.

 

My solution (but I'm open to new ideas):

Find some person on here who knows how to convert object data to attribute data.

 

Thanks for your help!

 

-Chris the intern

Link to comment
Share on other sites

Congrats on your first post, and welcome to the forums!

 

I use object data (OD) from GIS Shapefiles to extract drainage basin data frequently. I'd be happy to help you with this.

 

I'd suggest Object Data -> Attribute Value, and skip the spreadsheet all together, unless you absolutely need the resultant excel spreadsheet.

 

In order to better help you, would you post a sample drawing that contains one of your blocks (which contains OD, and Attributes) for me to analyze? Also, please describe any formatting that you'll need, etc.

 

Edit: Forum moderator, please feel free to move this thread to the LISP programming forum, as I will be using ActiveX to assist with the OP's request. Thanks.

Link to comment
Share on other sites

Thanks!

 

I think I do need the spreadsheet process included because I need to add the data (which was given to me as an excel sheet keyed to the barcode label) to the drawing file.

 

Image summarizing what I have and what I need:

Meters help.jpg

 

Unfortunately I can't get the file size down enough to upload it here. I uploaded it to some free hosting site...(sketchy, sorry). If you can wait 30 seconds you can download it w/o entering personal information.

 

Water meter .dwg:

http://www.filefactory.com/file/b3f744a/n/Water_Meter_DWG.dwg

 

Radio Read .xlsx:

http://www.filefactory.com/file/b3f746c/n/Radio_Read_and_LD_Num.xlsx

Link to comment
Share on other sites

Hmmm. the mods don't seem to want to post my reply...

 

But yes, I'd love to get some help. The problem is I can't get the sample files down to a size postable here.

 

email?

Link to comment
Share on other sites

Hmmm. the mods don't seem to want to post my reply...

 

But yes, I'd love to get some help. The problem is I can't get the sample files down to a size postable here.

 

email?

 

 

That is probably due to your being new to the forums. I have some pretty tight Inbox restrictions, so you'll have to FTP if you cannot post a sample here. Also, to keep file size down, simply block out one object which has the data/attributes you need... I don't need an entire drawing of these objects.

 

Edit:

Please save the drawing back to 2007 file format.

Link to comment
Share on other sites

Okay, this should get you started:

 

(defun c:FOO  (/ ss)
 (vl-load-com)
 (if (setq ss (ssget "_x" '((0 . "INSERT") (2 . "WD_METR") (66 . 1))))
   ((lambda (i / e s od r v n d tag)
      (while (setq e (ssname ss (setq i (1+ i))))

        ;; Extract object data
        (setq b (ade_odgetfield e (setq od (car (ade_odgettables e))) "BARCODE" 0))
        (setq s (strcase (ade_odgetfield e od "STATUS" 0)))

        ;; Populate attributes
        (if (and (setq n (vla-get-effectivename
                           (setq v (vlax-ename->vla-object e))))
                 (setq d (vla-item (vla-get-blocks
                                     (vla-get-activedocument
                                       (vlax-get-acad-object)))
                                   n)))
          (foreach attrib (vlax-invoke v 'getattributes)
            (vlax-for item d
              (if (= (vla-get-objectname item) "AcDbAttributeDefinition")
                (if (= (vla-get-tagstring attrib)
                         (vla-get-tagstring item))
                  (cond
                    ((= "BARCODE" (setq tag (vla-get-tagstring item)))
                     (vla-put-textstring attrib b))
                    ((= "STATUS" tag)
                     (cond
                       ((= "MANUAL" s)
                        (vla-put-textstring attrib "M"))
                       ((= "RADIO" s)
                        (vla-put-textstring attrib "X"))
                       ((vla-put-textstring attrib "?"))))))))))

        [color=seagreen];; Write data to excel[/color]

        ))         
     -1))
 (princ))

 

 

I revised your block a bit (hope you don't mind), so that instead of using Text at the center of the block, you now have an Attribute, which changes between "M" (Manual), "X" (Radio), and "?" (Others). I used the "Status" field for populating this attribute.

 

Next, I'm working on a segment of code which will insert the new block at the old block's location, and add the Object Data from the old to the new, then delete the old block. This should only be required to be run once per drawing.

 

Please start the "write to excel" part, so we can combine them.

WD_METR.dwg

  • Like 1
Link to comment
Share on other sites

Weird that my posts aren't posting...

 

Thanks a bunch! Unfortunately I'm not much of a code kid (just scratched the surface of AFRAlisp) when it comes to writing my own routines. However, I am quite proficient at using others' code :D.

 

I've been using ATTOUT to write attribute data to excel, changing it there, and then ATTIN to reimport the new data. So as long as that awesome bit of code takes the Object Data BARCODE and makes it attribute data, I'm set.

 

I am running into an error when I run the lisp on my full file. It updates some of the blocks, but then throws this error in the command line.

 

Command: OD2AD

; error: bad argument type: stringp nil

 

the logfile says this:

Invalid argument list.

Invalid argument list.

 

 

 

Now, I think (but of course not sure) what's happening is that not all the meters have a value in the object data barcode field.

 

What I want to happen in that case is for the code to place a ? (or just leave it blank) as the barcode.

 

 

Part II of this:

 

I have a block called WS_METR. Same format and everything, just a different layer.

 

If I just change all references to WD_METR to WS_METR, will everything still tick?

Link to comment
Share on other sites

  • 1 year later...

Hello RenderMan, I would really like to know more about how to convert my Object Data fields to Attributes values...you mentioned Object Data -> Attribute Value as a possibility. please explain really slowly lol.

 

Also, I have already created several Object Data fields and I need to rename some; however, the Table only allows me to make new ones or delete...whats the deal with that?

Thanks for your help.

Link to comment
Share on other sites

I'm pretty busy at the moment, but will try and get back to you shortly.

 

I'm about to head out for the day so no rush 8)

 

thanks!

 

Wow... I can't believe that I forgot to get back to this (in a year)... Total failure on my part, cris2fur. :facepalm: :oops:

 

Hello RenderMan, I would really like to know more about how to convert my Object Data fields to Attributes values...you mentioned Object Data -> Attribute Value as a possibility. please explain really slowly lol.

 

Hi SureCAD, and welcome to CADTutor!

 

I'll need more information to help you with the specifics of your Object Data fields, and placing those into Block Attributes as values. Perhaps you can post a sample drawing that includes the Object Data Source, and an instance of the desired Attributed Block.

 

As you may already know, Object Data (OD) is Attribute Data that has been attached to a drawing object (or entity) and is stored in the drawing file. GIS shape files, etc. are one common source of this Object Data being incorporated into our drawings, and drawing objects by definition.

 

What I suggested earlier in this thread is to use code (in this case Visual LISP) to access and extract the Object Data from applicable drawing objects, and to modify the Value of an Attribute that is part of a Block object.

 

Does this make sense?

 

Also, I have already created several Object Data fields and I need to rename some; however, the Table only allows me to make new ones or delete...whats the deal with that?

Thanks for your help.

 

I have Civil 3D 2012 installed on my work laptop, but have worked with it very little to date. My employer's authorized production platform is actually Civil 3D 2011 (which we're still transitioning to), and I also work with Microstation. Admittedly, I've not yet attempted anything like this since Civil 3D 2012 has been installed, but I will try to make some time this week to check it out. Perhaps I can use your sample drawing to troubleshoot. :wink:

 

Hope this helps (HTH)!

Link to comment
Share on other sites

Wow... I can't believe that I forgot to get back to this (in a year)... Total failure on my part, cris2fur. :facepalm: :oops:

 

Hah, you're forgiven. Figured it out anyway. Turns out an antique coworker had a LISP that that did it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...