workspace for selected feature

851
6
08-13-2010 12:48 AM
shivagugila
New Contributor III
Hi All,

Is there any line of code in VBA to "set workspace of selected feature". i am working on code that will enable the snap environment of layer of selected feature from map.
Any sort of help is appreciated. Thanks in advance.

Shiva
0 Kudos
6 Replies
NeilClemmons
Regular Contributor III
I'm guessing you mean you want to know how to get a reference to the workspace that a feature comes from?  If so,

Dim objectClass As IObjectClass
Set objectClass = feature.Class
Dim dataset As IDataset
Set dataset = objectClass
Dim workspace As IWorkspace
Set workspace = dataset.Workspace
0 Kudos
shivagugila
New Contributor III
Thanks a lot Neil,

Inclusion of that lines worked well for my code.

Shiva
0 Kudos
shivagugila
New Contributor III
This post answered my question
0 Kudos
shivagugila
New Contributor III
Hi Neil,

The code for 'Addsnapagentfor selected feature' creates a duplicate layer to set a new snap agent, which i am unable to resolve. Can you please look into the code lines and give your comment. Screenshot for snapwindow is also attached.

'setting snapagent

    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pfworkspace.OpenFeatureClass(lay_name)
   
    Dim pSnapEnvironment As ISnapEnvironment
    Dim pFeatureSnapagent As IFeatureSnapAgent
    Set pSnapEnvironment = pEditor
    Set pFeatureSnapagent = New FeatureSnap
    Set pFeatureSnapagent.FeatureClass = pFeatureClass
    pFeatureSnapagent.HitType = esriGeometryPartVertex
   
   
   'pSnapEnvironment.ClearSnapAgents
    pSnapEnvironment.AddSnapAgent pFeatureSnapagent
    pSnapEnvironment.SnapToleranceUnits = esriSnapTolerancePixels
    pSnapEnvironment.SnapTolerance = 5

Thanks in advance,
Regards,
Shiva
0 Kudos
NeilClemmons
Regular Contributor III
Your code is creating a new snap agent and adding it to the snap environment.  If there is already a snap agent for the layer then you need to get that snap agent and modify it instead of adding a new snap agent.  You can do this by looping through the snap agents and checking the feature class and/or name until you find the one you're looking for.
0 Kudos
shivagugila
New Contributor III
can you please review the code and suggest
0 Kudos