jaykappy

Add Layer

Discussion created by jaykappy on Apr 9, 2010
Latest reply on Apr 9, 2010 by jaykappy
I have some code that is asking the user for a file name.  It then takes a selected set and exports it to a shapefile. 
BUT what I want to do now is add the new shapefile to my project.

I am trying to pass the varaible to the second set of code that is opening the file OR combineing the two sets of code...
I am stuck here....

Can I call it like this and pass the varaible or something?

Call AddXYShapefileCreatedTable_Click (FileName As String)

Any thougths?

THanks


THIS IS THE CODE LEADING UP TO ASKING THE USER FOR THEFILE NAME, IT THEN DOES THE EXPORT

' Get Name For Output Feature Class
Dim strUserFileName As String
strUserFileName = InputBox("Please enter File Name", "File Name")
'MsgBox strUserFileName

' Test to make sure its not there
Dim sPath As String
     
    'Change your directory here
sPath = "C:\Temp\" & strUserFileName & ".shp"
     
     'Test if directory or file exists
If FileOrDirExists(sPath) Then
    MsgBox sPath & " exists! Existing Sub"
    Exit Sub
Else
    MsgBox sPath & " does not exist."
    
    'Define the output feature class name
    Set pFeatureClassName = New FeatureClassName
    Set pOutDatasetName = pFeatureClassName
    pOutDatasetName.Name = strUserFileName
    Set pWorkspaceName = New WorkspaceName
    pWorkspaceName.PathName = "c:\temp"
    pWorkspaceName.WorkspaceFactoryProgID = _
          "esriCore.shapefileworkspacefactory.1"
    Set pOutDatasetName.WorkspaceName = pWorkspaceName
    pFeatureClassName.FeatureType = esriFTSimple
    pFeatureClassName.ShapeType = esriGeometryAny
    pFeatureClassName.ShapeFieldName = "Shape"
    
    'Export
    Set pExportOp = New ExportOperation
    pExportOp.ExportFeatureClass pInDsName, Nothing, _
           pSelSet, Nothing, pOutDatasetName, 0

    
End If

Call AddXYShapefileCreatedTable_Click


End Sub



I TRIED TO CALL THIS CODE BUT I GET ERRORS BUT I CANT FIGURE OUT HOW TO PASS THE FIEL NAME SPECIFIED BY THE USER.  I HAVE "qweqwe" AS AN EXAMPLE, BUT I NEED TO MAK THIS A VARAIBLE!!!!
I ALSO TRIED TO PUT IT IN THE IF STATEMENT ABOVE BUT GET ERRORS...

How do I use a varaible in stead of the hardcoded file name?

Public Sub AddXYShapefileCreatedTable_Click()
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pworkspaceFactory As IWorkspaceFactory
Dim pfeatureWorkspace As IFeatureWorkspace
Dim pFeatureLayer As IFeatureLayer

'Create a new ShapefileWorkspaceFactory object and open a shapefile folder
    Set pworkspaceFactory = New ShapefileWorkspaceFactory
    Set pfeatureWorkspace = pworkspaceFactory.OpenFromFile("C:\Temp", 0)
'Create a new FeatureLayer and assign a shapefile to it
    Set pFeatureLayer = New FeatureLayer
    Set pFeatureLayer.FeatureClass = pfeatureWorkspace.OpenFeatureClass("qweqwe")
    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName
    'pfeaturelayer.ScaleSymbols
    'Add the FeatureLayer to the focus map
    Set pMxDocument = Application.Document
    Set pMap = pMxDocument.FocusMap
    pMap.AddLayer pFeatureLayer
End Sub
 

Outcomes