AutoCAD Map 3D Developer

AutoCAD Map 3D Developer

Reply
Contributor
matteo.conte
Posts: 21
Registered: ‎05-16-2006
Message 1 of 4 (426 Views)

Set FDO layer filter

426 Views, 3 Replies
07-13-2012 07:51 AM

Hi all,

   I need to set a fillter for all fdo layer in a map (as Query to filter data command).

To do this I wrote this code but the filter is not set. If I manualy run the "Query to filter data" command
If you launch the "Query to filter data" command manually  on a layer i find the filter set, and is applied only if I press the Ok or Apply button.I think that in my code is missing an instruction to apply the filter set.
Can you help me?

Dim objLayers As MgLayerCollection = objMap.GetLayers()
        For Each objLayer As MgLayerBase In objLayers
            Dim objLayerDefId As MgResourceIdentifier = objLayer.GetLayerDefinition()
            Dim objByteReader As MgByteReader = objResourceServ.GetResourceContent(objLayerDefId)
            Dim objXML As XmlDocument = New XmlDocument()
            Dim objSerializer As New XmlSerializer(GetType(LayerDefinition))
            Dim objLayerV As LayerDefinition = TryCast(objSerializer.Deserialize(New StringReader(objByteReader.ToString)), LayerDefinition)
            Dim objVectorLayerDef As VectorLayerDefinitionType = TryCast(objLayerV.Item, VectorLayerDefinitionType)
            objVectorLayerDef.Filter = strFilter
            Dim objXs As New XmlSerializer(objLayerV.[GetType]())
            Dim objWriter As New StringWriter()
            objXs.Serialize(objWriter, objLayerV)
            Dim objBuffer As Byte() = StringToBytes(objWriter.ToString())
            Dim objSource As New MgByteSource(objBuffer, objBuffer.Length)

            ' Update the resource in Map
            objResourceServ.SetResource(objLayer.LayerDefinition, objSource.GetReader(), Nothing)

            objLayer.ForceRefresh()

        Next

 

Regards

Matteo Conte

ADN Support Specialist
Daniel.Du
Posts: 276
Registered: ‎12-23-2008
Message 2 of 4 (367 Views)

Re: Set FDO layer filter

08-05-2012 08:15 PM in reply to: matteo.conte

Have you ever refered to the QueryAndLocate  and FeatureInspector sample in Map 3D SDK? 



Daniel Du
Developer Technical Services
Autodesk Developer Network

ADN Support Specialist
Partha.Sarkar
Posts: 543
Registered: ‎06-09-2009
Message 3 of 4 (365 Views)

Re: Set FDO layer filter

08-05-2012 09:39 PM in reply to: matteo.conte

Matteo had contacted DevTech / ADN team on this issue and I worked with him to resolve this; It's now resolved.

 

Once you update the XML LayerDefinition, you need to update the resource in Map and then call the layer.ForceRefresh(). Here is the relevant code snippet :

 

 

// Update the resource in Map

ResourceService.SetResource(layer.LayerDefinition, source.GetReader(), null);

 

// layer.ForceRefresh();

layer.ForceRefresh();

 

Thanks,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Active Contributor
dr5156
Posts: 38
Registered: ‎12-08-2010
Message 4 of 4 (271 Views)

Re: Set FDO layer filter

10-25-2012 06:13 AM in reply to: Partha.Sarkar

i am having same issue. but your solution is not working for me. could you please review my below code

 

//Select Entity on Map

Editor acEditor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

 

SelectionSetss = GetAcSelectionSetSingleGeom(acEditor);

 

ObjectIdCollection objIdColle = newObjectIdCollection(ss.GetObjectIds());

 

MgSelectionBase mgSe = AcMapFeatureEntityService.GetSelection(ss);

 

AcMapMap acMap = AcMapMap.GetCurrentMap();

 

MgLayerCollectionmgLayColl = acMap.GetLayers();

 

MgLayerBase parcelsLayer1 = mgLayColl.GetItem("EL_ADMIN_AREA");

 

stringfcName1 = parcelsLayer1.GetFeatureClassName();

 

intII = mgSe.GetSelectedFeaturesCount(parcelsLayer1, fcName1);

 

MgFeatureReader featureReader = mgSe.GetSelectedFeatures(parcelsLayer1, parcelsLayer1.FeatureClassName, true);

 

MgFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) asMgFeatureService;

 

if(featureReader.ReadNext())

{

stringgeometryName = parcelsLayer1.GetFeatureGeometryName();

 

MgByteReadergeometryData = featureReader.GetGeometry(geometryName);

 

MgAgfReaderWriter agfReaderWriter = newMgAgfReaderWriter();

 

MgGeometrygeometry = agfReaderWriter.Read(geometryData);

 

MgPolygon mgPoly = geometry asMgPolygon;

 

MgWktReaderWriter wktReaderWriter = newMgWktReaderWriter();

 

stringwkt = wktReaderWriter.Write(mgPoly);

wkt = wkt.Replace(

"POLYGON", "POLYGON XYZ ");

wkt = wkt.Replace(

",", " 0,");

wkt = wkt.Replace(

"))", " 0))");

 

string filter = "GEOM INSIDE GeomFromText('" + wkt + "')";

 

AcMapLayer layer1 = mgLayColl.GetItem("EL_CONDUCTOR") asAcMapLayer;

 

MgResourceIdentifierlayerDefId = layer1.GetLayerDefinition();

 

MgResourceService rs = AcMapServiceFactory.GetService(MgServiceType.ResourceService) asMgResourceService;

 

MgByteReaderlayerReader = rs.GetResourceContent(layerDefId);

 

XmlDocument objXML = newXmlDocument();

 

XmlSerializer objSerializer = newXmlSerializer(typeof(LayerDefinition));

 

LayerDefinition objLayerDef = objSerializer.Deserialize(newStringReader(layerReader.ToString())) asLayerDefinition;

 

VectorLayerDefinitionType objVectorLayerDef = objLayerDef.Item asVectorLayerDefinitionType;

objVectorLayerDef.Filter = filter;

using (StringWriter objWriter = newStringWriter())

{

XmlSerializer objXs = newXmlSerializer(typeof(LayerDefinition));

objXs.Serialize(objWriter, objLayerDef);

byte[] unicodeBytes = Encoding.Unicode.GetBytes(objWriter.ToString());

 

byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, unicodeBytes);

 

MgByteSource objSource = newMgByteSource(utf8Bytes, utf8Bytes.Length);

rs.SetResource(layer1.LayerDefinition, objSource.GetReader(),

null);

 

layer1.ForceRefresh();

//layer1.NeedsRefresh();

}

 

}

if (featureReader != null)

featureReader.Close();

}

Regards,
Dayalan
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.