Add features to Map

Add features to Map

Anonymous
Not applicable
2,142 Views
3 Replies
Message 1 of 4

Add features to Map

Anonymous
Not applicable

Hello again,

 

I have another problem with my DLL for AutoCad.

In my previous post (here) I wanted to connect to a FDO source.

 

Now I have connected and queried the FDO and got a response in form of a FeatureReader.

but how can I add the features in the reader to the map?

 

My Code is as follows: 

 

Dim document As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim database As Database = document.Database
Dim TM As Autodesk.AutoCAD.DatabaseServices.TransactionManager = document.Database.TransactionManager

Dim connManager As OSGeo.FDO.IConnectionManager = OSGeo.FDO.ClientServices.FeatureAccessManager.GetConnectionManager()
Dim conn As OSGeo.FDO.Connections.IConnection = connManager.CreateConnection("Autodesk.Oracle.3.9")
conn.ConnectionString = "Service=SRID;Username=USERNAME;Password=PASSWORD;Datastore=SCHEMA"
conn.Open()

Dim Transaction Autodesk.AutoCAD.DatabaseServices.Transaction = TM.StartTransaction
Dim LayerTable As Autodesk.AutoCAD.DatabaseServices.LayerTable = CType(TM.GetObject(database.LayerTableId, OpenMode.ForRead, True, True), LayerTable)
Dim btr As BlockTableRecord = Transaction.GetObject(database.CurrentSpaceId, OpenMode.ForWrite)


Dim selCmd As OSGeo.FDO.Commands.Feature.ISelect = conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select)
selCmd.FeatureClassName = New OSGeo.FDO.Expression.Identifier("VIEWNAME")
Dim ftrRdr As OSGeo.FDO.Commands.Feature.IFeatureReader = selCmd.Execute()

While ftrRdr.ReadNext()
       Dim geometryBytes As Byte() = ftrRdr.GetGeometry("SHAPE")
       Dim geometryFactory As New OSGeo.FDO.Geometry.FgfGeometryFactory()
       Dim geometry As OSGeo.FDO.Geometry.IGeometry = geometryFactory.CreateGeometryFromFgf(geometryBytes)
'What to do here? End While Transaction.Commit() conn.Close()

//Per

0 Likes
Accepted solutions (1)
2,143 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hi Per,

 

 

Map SDK comes with lots of samples :

 

\Map ObjectARX SDK 2013\Map Samples\Platform

 

ADN has also published API introduction for Map - one example is here:

 

http://adndevblog.typepad.com/files/chapter-1.pdf

 

Rob

0 Likes
Message 3 of 4

Anonymous
Not applicable
0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

I realize now in hindsight that I wrote map when I should have written drawing. 

Either way I found a way to add features from an FDO to a drawing. 

Here is the code for inserting a linestring:

Dim document As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim database As Database = document.Database
Dim TM As Autodesk.AutoCAD.DatabaseServices.TransactionManager = document.Database.TransactionManager

Dim connManager As OSGeo.FDO.IConnectionManager = OSGeo.FDO.ClientServices.FeatureAccessManager.GetConnectionManager()
Dim conn As OSGeo.FDO.Connections.IConnection = connManager.CreateConnection("Autodesk.Oracle.3.9")
conn.ConnectionString = "Service=SRID;Username=USERNAME;Password=PASSWORD;Datastore=SCHEMA"
conn.Open()

Dim Transaction Autodesk.AutoCAD.DatabaseServices.Transaction = TM.StartTransaction
Dim LayerTable As Autodesk.AutoCAD.DatabaseServices.LayerTable = CType(TM.GetObject(database.LayerTableId, OpenMode.ForRead, True, True), LayerTable)
Dim btr As BlockTableRecord = Transaction.GetObject(database.CurrentSpaceId, OpenMode.ForWrite)


Dim selCmd As OSGeo.FDO.Commands.Feature.ISelect = conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select)
selCmd.FeatureClassName = New OSGeo.FDO.Expression.Identifier("VIEWNAME")
Dim ftrRdr As OSGeo.FDO.Commands.Feature.IFeatureReader = selCmd.Execute()

While ftrRdr.ReadNext()
       Dim geometryBytes As Byte() = ftrRdr.GetGeometry("SHAPE")
       Dim geometryFactory As New OSGeo.FDO.Geometry.FgfGeometryFactory()
       Dim linestring As OSGeo.FDO.Geometry.ILineString = CType(geometryFactory.CreateGeometryFromFgf(geometryBytes), OSGeo.FDO.Geometry.ILineString)
Dim PosCool As OSGeo.FDO.Geometry.DirectPositionCollection = linestring.Positions
Dim polyline As New Polyline()

For index As Integer = 0 To PosCool.Count - 1
Dim pos1 As OSGeo.FDO.Geometry.IDirectPosition = PosCool.Item(index)
polyline.AddVertexAt(index, New Point2d(pos1.X, pos1.Y), 0, 0, 0)
Next

Dim btr As BlockTableRecord = CType(Transaction.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
dim objectid as ObjectId= btr.AppendEntity(polyline)
Using document.LockDocument
Transaction.AddNewlyCreatedDBObject(polyline, True)
End Using End While Transaction.Commit() conn.Close()    

 Hope it helps someone.

0 Likes