Autodesk Sample Code doesn't even work

Autodesk Sample Code doesn't even work

Anonymous
Not applicable
321 Views
1 Reply
Message 1 of 2

Autodesk Sample Code doesn't even work

Anonymous
Not applicable
Tried this and it didn't work. There was a Compile Error: User-defined type not defined

Creating object data tablesStep By Step Sample Code
The following example creates a table of object data: the AutoCAD database entity name, the color, and the layer of the object. It builds object data records from the table and attaches them to objects in the drawing.



Sub tableproc()



Dim amap As AcadMap

Dim ODfdfs As ODFieldDefs

Dim ODfdf As ODFieldDef

Dim ODtb As ODTable

Dim ODrc As ODRecord



Set amap = ThisDrawing.Application. _

GetInterfaceObject("AutoCADMap.Application")



'Create OD Table Definition

Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs



' Add Column Headings and Defaults

Set ODfdf = ODfdfs.Add("Entity", "Entity name", "", 0)

Set ODfdf = ODfdfs.Add("Color", "Object color", acRed, 1)

Set ODfdf = ODfdfs.Add("Layer", "Object layer", "0", 2)



'Ensure Table Does Not Exist

If amap.Projects(ThisDrawing) _

.ODTables.Item("SampleOD") Is Nothing Then



'Register OD Table in the drawing

Set ODtb = amap.Projects(ThisDrawing) _

.ODTables.Add("SampleOD", "Sample Xdata", ODfdfs, True)



'Create OD Record with Defaults

Set ODrc = ODtb.CreateRecord



'Loop Through Entities in Model Space

For Each acadObj In ThisDrawing.ModelSpace



'Fill Records with Entity Data

ODrc.Item(0).Value = acadObj.EntityName

ODrc.Item(1).Value = acadObj.Color

ODrc.Item(2).Value = acadObj.Layer



'Attach Record to Entity

ODrc.AttachTo(acadObj.ObjectID)



Next



Else



'Table Already Exists

MsgBox "Unable to create " & "SampleOD", , _

"Object Data Table Error"

End If



End Sub
0 Likes
322 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Have you set reference to AcadMap/AcadMap200x type library (AmVbApi.tlb)?
You must run this code in AcadMap/Civil, not vanilla Acad. Also, with
different version of AcadMap, the this line of code

Set amap =
ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application")

could be

Set amap =
ThisDrawing.Application.GetInterfaceObject("AutoCADMap.Application.2") ''If
you use AcadMap2004


wrote in message news:5495156@discussion.autodesk.com...
Tried this and it didn't work. There was a Compile Error: User-defined
type not defined

Creating object data tablesStep By Step Sample Code
The following example creates a table of object data: the AutoCAD database
entity name, the color, and the layer of the object. It builds object data
records from the table and attaches them to objects in the drawing.



Sub tableproc()



Dim amap As AcadMap

Dim ODfdfs As ODFieldDefs

Dim ODfdf As ODFieldDef

Dim ODtb As ODTable

Dim ODrc As ODRecord



Set amap = ThisDrawing.Application. _

GetInterfaceObject("AutoCADMap.Application")



'Create OD Table Definition

Set ODfdfs = amap.Projects(ThisDrawing).MapUtil.NewODFieldDefs



' Add Column Headings and Defaults

Set ODfdf = ODfdfs.Add("Entity", "Entity name", "", 0)

Set ODfdf = ODfdfs.Add("Color", "Object color", acRed, 1)

Set ODfdf = ODfdfs.Add("Layer", "Object layer", "0", 2)



'Ensure Table Does Not Exist

If amap.Projects(ThisDrawing) _

.ODTables.Item("SampleOD") Is Nothing Then



'Register OD Table in the drawing

Set ODtb = amap.Projects(ThisDrawing) _

.ODTables.Add("SampleOD", "Sample Xdata", ODfdfs, True)



'Create OD Record with Defaults

Set ODrc = ODtb.CreateRecord



'Loop Through Entities in Model Space

For Each acadObj In ThisDrawing.ModelSpace



'Fill Records with Entity Data

ODrc.Item(0).Value = acadObj.EntityName

ODrc.Item(1).Value = acadObj.Color

ODrc.Item(2).Value = acadObj.Layer



'Attach Record to Entity

ODrc.AttachTo(acadObj.ObjectID)



Next



Else



'Table Already Exists

MsgBox "Unable to create " & "SampleOD", , _

"Object Data Table Error"

End If



End Sub
0 Likes