Jump to content

LW Poly custom attributes


AstroNout

Recommended Posts

Hi Guys

 

My question is similar to Ander's problem. I'm having some trouble using the custom properties from a SHP to polyline conversion.

 

I inserted the shape as polylines with extra attributes from the database of the shapefile. So far so good. But now I'ld like to put the polylines into different layers, depending on the attributes I just created.

 

The problem is that I can't seem to get an array or even a variant object of some kind from the custom attributes using VBA-coding. Is this even possible with LW Poly's? I'm using AutoCAD MAP 3D 2011.

 

I've got a code to start from:

 

Sub Layer()
   Dim Ent As AcadEntity
   Dim pLine As AcadLWPolyline
   Dim aAttributes As Variant
   Dim Attrib As Variant
   Dim Layer As AcadLayer
   Dim sText As String
   
   For Each Ent In ThisDrawing.ModelSpace
       If TypeOf Ent Is AcadLWPolyline Then
           Set pLine = Ent
           aAttributes = pLine.GetAttributes
           
           Select Case pLine.Layer
           Case "ggba"
               For Each Attrib In aAttributes
                   If Attrib.TagString = "TPC" Then
                       sText = Attrib.TextString
                       Set Layer = ThisDrawing.Application.ActiveDocument.Layers.Add("GBA" & sText)
                       pLine.Layer = Layer
                   End If
               Next Attrib
           End Select
       End If
   Next
End Sub

 

Obviously the .getattribute methode does not work on LW poly's.

 

Any help is much appreciated,

Thanks

Link to comment
Share on other sites

Thanks for the response, but that's not where I'ld like to get at. I know how to get the coordinates, that's a doddle :-)

 

I've been searching the web, and have found that the data that I need is inside the "Object Data". This, however, is a completely different story, since the data is stored inside tables, connected to the CAD-objects, much like it is inside GIS.

 

I can't seem to find a good example for cycling through the object data of an object using VBA. It is possible, but it remains to be a mystery to me.

Link to comment
Share on other sites

If you mean "Object Data" you can access the layer property (object.Layer) and set it directly to the layed you want the LW Polyline to be on. As you have demonstrated in your code.

 

If you mean data as stored in a GIS you can use XData to access it. We get DXF files exported from a GIS and all the data connected to an object is exported as XData. I have written a viewer to display all of the data connected to a selected object and it is not always insignificant, some objects have over 100 data items connected to them. Using Express Tools see if any of your LW Polylines have XData attached to them and if so amend your code to deal with XData and not attributes.

 

I'm not quite sure what you are trying to achieve with your code. As you rightly say a LW Polyline can't have attributes, therefore your variant variable aAttributes will always be empty and the code in the case loop will never be executed. In your code what is "TPC" if its not an attribute?

Link to comment
Share on other sites

Well, the government sends us shapefiles of entire cities to check for new features witch we survey. Since we use AutoCAD, its easier to convert the whole lot to a DWG. Only the adjustments need to be delivered.

 

The problem is that some of the lines in a shape signify different things. The shape buildings have all main and secundairy buildings in it. To make it practical we want to put the different types of buildings in different layers. When a shape is inported into AutoCAD, the attributes are inported as OD:ShapeName. I suspect this to be "Object Data" as referred in the help files. The attribute signifying main or secundairy building is "TPC ".

 

Hope this helps.

Link to comment
Share on other sites

What do you see in the properies pane when you click on a LW Polyline? For a block, if it has attributes they are listed right at the bottom of the properites pane together with their current values.

 

What do you see in the text window when you go to Express Tools Tab on the Ribbon > Tools Group > List Xdata button. You are prompted to select the object, then "Enter application name :" just press the enter key. If the object has Xdata it will be listed or if not you will get the message "No Xdata associated with Application Name(s)."

 

Can you post a small example?

Link to comment
Share on other sites

In the properties I get the data I need, all the way at the bottom.

 

Here's the list you asked:

* Registered Application Name: AcMap_E615D161-C9D7-11d3-839F-0060B0FB6B57
* Code 1071, 32-bit signed long integer: 2
* Code 1071, 32-bit signed long integer: 16
* Code 1071, 32-bit signed long integer: 1

Object has 16365 bytes of Xdata space available.

Link to comment
Share on other sites

OK the data you have here is XData from the text windows and not properties. Are you ALSO getting information in the 'Properties Pane'?

The number following the word 'Code' is a DXF code and DXF codes 1000 to 1071 inclusive are reserved for XData.

 

All but the code 1001 can be used many times in one set of XData. 1001 is the Application name and can only appear once.

Code 1003 is the layer associated with the XData, which might be of use to you.

 

There are two Methods associated with Data 'GetXData' and 'SetXData'.

 

You could retrieve the XData of your LW Polyline, then loop through the XData till you find the entry that you want and then set the LW Polyline's layer property accordingly.

Link to comment
Share on other sites

Try checking your MAP Help files for XData, MetaData, ObjectData, DataTables, etc.

 

There would appear to be plenty of information there on these subjects, which you were talking about in Post #3.

Link to comment
Share on other sites

Right, thanks. But it doesn't seem to work with the GetXData-function. I always get empty variant arrays, so, no help there.

 

So, now we're busy doing some work on DataTables and ObjectData, though, I just had a fatal crash of AutoCAD and a few seconds later the VBA Manager due to memory overflow, loosing all of my programming, when going through the DataTables in the drawing. Jolly!

 

I hear that manipulating the DataTables is a big problem in the AutoCAD customization process. Obviously not handled in the help-files... Does anyone have experience with this?

 

Here's one of the many files that have to be adjusted:

Test.dwg

 

Grtz

Astronout

 

UPDATE:

It crashes at this line:

Set OD = acad.Projects(ThisDrawing).ODTables.Item("ggba") 

 

Complete code:

Public Function Get_Attributes()

Dim acadOBJ As Object
Dim acad As AcadMap
Set acad = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application.5")
Dim boolVal As Boolean
Dim aLayer As AcadLayer
Dim sString As String
Dim TPC As Integer

Dim OD As ODTable ' variable to connect to PB table
Set OD = acad.Projects(ThisDrawing).ODTables.Item("ggba") ' setting up the table for use

Dim ODrcs As ODRecords
Set ODrcs = OD.GetODRecords ' get all records in the table

Dim acadOBJ_objectID() As Long 'store pillar objectID in an array

Dim ODtbs As ODTables
Dim iType As Integer

Set ODtbs = ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application").Projects(ThisDrawing).ODTables
'get the field names

For i = 0 To ODtbs.Item("ggba").ODFieldDefs.Count - 1
   'get the field index of "TYPE" field
       If ODtbs.Item("ggba").ODFieldDefs.Item(i).Name = "TPC" Then
           iType = i
       End If
Next i

For Each acadOBJ In ThisDrawing.ModelSpace
   boolVal = ODrcs.Init(acadOBJ, True, False)
       Do While ODrcs.IsDone = False
           If ODrcs.Record.ObjectID = acadOBJ.ObjectID Then
               TPC = ODrcs.Record.Item(iType).Value
           End If
         ODrcs.Next
       Loop
   sString = "GBA" & TPC
   Set aLayer = ThisDrawing.Layers.Add(sString)
   acadOBJ.Layer = aLayer
Next
End Function

Edited by AstroNout
Link to comment
Share on other sites

Hi Tyke

 

It doesn't seem to work, it keeps getting stuck at:

Set tODTable = amap.Projects(ThisDrawing).odTables(0) 'for ACAD Version 2008

Or

Set tODTable = amap.Projects(ThisDrawing).odTables(myTableName) 'for ACAD Version 2010

 

Thanks for the tip though!

Link to comment
Share on other sites

Hi Tyke

 

It doesn't seem to work, it keeps getting stuck at:

Set tODTable = amap.Projects(ThisDrawing).odTables(0) 'for ACAD Version 2008

Or

Set tODTable = amap.Projects(ThisDrawing).odTables(myTableName) 'for ACAD Version 2010

Thanks for the tip though!

 

I've never worked with Object Data in VB or VBA so I can't offer any specific help to you on the subject. I checked all of my reference books and either the subject is not mentioned or they say it is too advanced for their book and one should look elsewhere. But where?

 

Have a look at this link it looks as if the guy had a similar problem: http://forums.autodesk.com/t5/AutoCAD-Map-3D-Developer/Updating-an-entity-s-object-data-table-from-form/m-p/3519534#M3745

Link to comment
Share on other sites

I've never worked with Object Data in VB or VBA so I can't offer any specific help to you on the subject. I checked all of my reference books and either the subject is not mentioned or they say it is too advanced for their book and one should look elsewhere. But where?

 

The Map 3D ObjectARX SDK has three Object Data samples (C++, C#, and VB.NET) here :thumbsup::

 

ct_map.arx.sdk.od.sample.jpg

 

 

 

OBJECTDATA .Net API Sample ReadMe

 

© Copyright 2004-2009 by Autodesk, Inc.

 

 

By using this code, you are agreeing to the terms

and conditions of the License Agreement that appeared

and was accepted upon download or installation

(or in connection with the download or installation)

of the Autodesk software in which this code is included.

All permissions on use of this code are as set forth

in such License Agreement provided that the above copyright

notice appears in all authorized copies and that both that

copyright notice and the limited warranty and

restricted rights notice below appear in all supporting

documentation.

 

AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.

AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF

MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.

DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE

UNINTERRUPTED OR ERROR FREE.

 

Use, duplication, or disclosure by the U.S. Government is subject to

restrictions set forth in FAR 52.227-19 (Commercial Computer

Software - Restricted Rights) and DFAR 252.227-7013©(1)(ii)

(Rights in Technical Data and Computer Software), as applicable.

 

 

Trademarks

 

AutoCAD Map 3D is a registered trademark of Autodesk, Inc., in the

USA and/or other countries.

 

All other brand names, product names or trademarks belong to

their respective holders.

 

 

===============================================================================

Readme.txt for ObjectData .NET API sample for AutoCAD Map 3D 2008

===============================================================================

 

This sample demonstrates how to use some features of ObjectData.

 

Build steps

-------------------------------------------------------------------------------

 

1) Open the project with Microsoft Visual Studio 2008.

 

2) In the Solution Explorer->ObjectDataCS->References,

add References files: acdbmgd.dll, acmgd.dll and ManagedMapAPI.dll.

The default path is the directory where you installed Map 3D,

e.g., C:\Program Files\AutoCAD Map 3D 2010.

 

3) Build the sample application to obtain the ObjectDataCS.dll file.

 

Loading the sample application

-------------------------------------------------------------------------------

To load the sample application

1. Enter "NETLOAD" on the Command Line of AutoCAD Map 3D.

2. Choose ObjectDataCS.dll in the file browser.

 

Using the sample

-------------------------------------------------------------------------------

 

This sample demonstrates:

- How to define an ObjectData Table.

- How to add a record to an entity with ObjectData Table definition.

- How to show the contents of records associated with an entity.

- How to remove an ObjectData record from an entity.

- How to remove an ObjectData Table.

 

- Load this dll application in AutoCAD Map 3D.

 

- Open or Create a drawing with an entity.

 

- Run the command "CreateTable".

- It will define a table named "MyODTable" that contains four field

definitions:

Field Name Value Type

 

FIRST_FIELD Character

SECOND_FIELD Integer

THIRD_FIELD Real

LAST_FIELD Point

 

- Run the command "AddRecord".

- Select an entity to which add the new record.

 

- Repeat to add records to the entity as you wish.

 

- Run the command "ShowRecords".

- Select an entity which all records associated with will be listed.

 

- Run the command "DeleteRecord".

- Select an entity from which you want to remove a record.

- All records associated with the entity will be listed by index.

- Choose an index you want to remove.

 

- Run the command "RemoveTable".

- Remove the table defined in CreateTable command.

HTH
Link to comment
Share on other sites

Batman, sorry, RenderMan to the rescue. :notworthy: :beer:

 

:oops: That is kind of you to say, Tyke... I'm happy to help. :beer:

 

 

Also, as another example:

 

The Florida Department of Transportation (FDOT) has a Civil 3D 2012 State Kit which includes one of their custom applications named Entity Manager which uses similar (albeit much more complex) processes in order to attach Pay Item data to entities as Object Data.

 

The complexity comes from hosting a Windows Presentation Foundation (WPF) user control in an AutoCAD palette, populating a TreeView interface with XML data that is queried (the pay item database), etc.... Not exactly beginner topics, but definitely something to use as a learning resource using Reflection, or IlSpy to peek at the compiled assembly source-code. :thumbsup:

 

As Civil 3D is built on top of Map, which is built on top of AutoCAD, the former has access to all Map API's as well.

 

HTH

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...