2017-01-31 2 views
-1

Je suis nouveau sur python. Je veux convertir le fichier dwg en fichier de formes. J'ai trouvé du code. Quand je cours le code j'obtiens une erreur. Comment puis-je résoudre ce problème? Ici, l'erreurPython convertir le fichier dwg en fichier shapefile

Traceback (most recent call last): File "C:\Users\Merve\Desktop\dwgtoshp\dwg2shp.py", line 91, in arcpy.IterateDatasets_mb(dwg_dosyalari, "", "", "NOT_RECURSIVE") AttributeError: 'module' object has no attribute 'IterateDatasets_mb'

# -*- coding: utf-8 -*- 
# --------------------------------------------------------------------------- 
# dwg2shp.py 
# Created on: 2017-01-30 13:59:57.00000 
# (generated by ArcGIS/ModelBuilder) 
# Usage: dwg2shp <pro_id> <pro_tip> <dwg_dosyalari> <Name> <Cikti_yeri> <line_merge_shp> <anno_merge_shp> 
# Description: 
# --------------------------------------------------------------------------- 

# Import arcpy module 
import arcpy 

# Load required toolboxes 
arcpy.ImportToolbox("C:\Users\Merve\Desktop\dwg\dwg2shp.tbx") 

# Script arguments 
pro_id = arcpy.GetParameterAsText(0) 
if pro_id == '#' or not pro_id: 
    pro_id = "1000888" # provide a default value if unspecified 

pro_tip = arcpy.GetParameterAsText(1) 
if pro_tip == '#' or not pro_tip: 
    pro_tip = "33" # provide a default value if unspecified 

dwg_dosyalari = arcpy.GetParameterAsText(2) 
if dwg_dosyalari == '#' or not dwg_dosyalari: 
    dwg_dosyalari = "F:\\proje\\gelen" # provide a default value if unspecified 

Name = arcpy.GetParameterAsText(3) 
if Name == '#' or not Name: 
    Name = "Dataset" # provide a default value if unspecified 

Cikti_yeri = arcpy.GetParameterAsText(4) 
if Cikti_yeri == '#' or not Cikti_yeri: 
    Cikti_yeri = "C:\Users\Merve\Desktop\dwgtoshp\yenidwgdosyaları" # provide a default value if unspecified 

line_merge_shp = arcpy.GetParameterAsText(5) 
if line_merge_shp == '#' or not line_merge_shp: 
    line_merge_shp = "C:\Users\Merve\Desktop\dwgtoshp\yenidwgdosyaları" # provide a default value if unspecified 

anno_merge_shp = arcpy.GetParameterAsText(6) 
if anno_merge_shp == '#' or not anno_merge_shp: 
    anno_merge_shp = "C:\Users\Merve\Desktop\dwgtoshp\yenidwgdosyaları" # provide a default value if unspecified 

# Local variables: 
Dataset = "C:\Users\Merve\Desktop\dwgtoshp\dwgdosyaları" 
Annotation = Dataset 
Polyline = Dataset 
v1_shp__5_ = Polyline 
dosya_line = "1.shp" 
kat_3_bodrum_3_line_shp = v1_shp__5_ 
New_Field___4_ = kat_3_bodrum_3_line_shp 
pro_id_field = "pro_id" 
long = "LONG" 
New_Field___5_ = New_Field___4_ 
pro_tip_field = "pro_tip" 
Field_Type__6_ = "LONG" 
New_Field___6_ = New_Field___5_ 
plan_adi_field = "plan_adi" 
text = "TEXT" 
v1_shp__2_ = New_Field___6_ 
v1_shp__6_ = v1_shp__2_ 
v1_shp__4_ = v1_shp__6_ 
Output_Values = v1_shp__4_ 
kat_3_bodrum_3_line_Merge__2_ = line_merge_shp 
bodrum_3_anno_shp__2_ = Annotation 
sil__3_ = "C:\Users\Merve\Desktop\dwgtoshp\yenidwgdosyaları" 
dosya_anno = "1.shp" 
kat_0_zemin_anno_shp__2_ = bodrum_3_anno_shp__2_ 
New_Field_ = kat_0_zemin_anno_shp__2_ 
New_Field___3_ = New_Field_ 
New_Field___2_ = New_Field___3_ 
v1_shp = New_Field___2_ 
v1_shp__3_ = v1_shp 
kat_0_zemin_anno_shp = v1_shp__3_ 
Output_Values__2_ = kat_0_zemin_anno_shp 
merge_shp__2_ = anno_merge_shp 

# Set Geoprocessing environments 
arcpy.env.MTolerance = "" 
arcpy.env.outputCoordinateSystem = "PROJCS['ITRF_1996_UTM_Zone_35N',GEOGCS['GCS_ITRF_1996',DATUM['D_ITRF_1996',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',30.0],PARAMETER['Scale_Factor',1.0],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]" 
arcpy.env.outputZFlag = "Disabled" 
arcpy.env.outputZValue = "" 
arcpy.env.outputMFlag = "Disabled" 
arcpy.env.geographicTransformations = "" 
arcpy.env.ZResolution = "" 
arcpy.env.MResolution = "" 
arcpy.env.ZTolerance = "" 

# Process: Iterate Datasets 
arcpy.IterateDatasets_mb(dwg_dosyalari, "", "", "NOT_RECURSIVE") 

# Process: Select Data (2) 
arcpy.SelectData_management(Dataset, "Polyline") 

# Process: Calculate Value (3) 
arcpy.CalculateValue_management("\"%Name%\"+\"_line\"", "", "String") 

# Process: Feature Class to Feature Class (2) 
arcpy.FeatureClassToFeatureClass_conversion(Polyline, Cikti_yeri, dosya_line, "", "", "DocName") 

# Process: Delete Field (2) 
arcpy.DeleteField_management(v1_shp__5_, "Entity;Handle;LyrFrzn;LyrLock;LyrOn;LyrVPFrzn;LyrHandle;EntColor;LyrColor;BlkColor;Linetype;EntLinetyp;LyrLnType;BlkLinetyp;Elevation;Thickness;LineWt;EntLineWt;LyrLineWt;BlkLineWt;RefName;LTScale;ExtX;ExtY;ExtZ;DocName;DocPath;DocType;DocVer;Owner;ScaleX;ScaleY;ScaleZ;FontID;Height;TxtAngle;TxtWidth;TxtOblique;TxtGenType;TxtJust;VertAlign;TxtFont;TxtBoxHt;TxtBoxWd;TxtRefWd;TxtAttach;TxtDir;LnSpace;SpaceFct;TxtMemo;EntLinetype;BlkLinetype") 

# Process: Add Field (4) 
arcpy.AddField_management(kat_3_bodrum_3_line_shp, pro_id_field, long, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") 

# Process: Add Field (5) 
arcpy.AddField_management(New_Field___4_, pro_tip_field, Field_Type__6_, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") 

# Process: Add Field (6) 
arcpy.AddField_management(New_Field___5_, plan_adi_field, text, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") 

# Process: Calculate Field (4) 
arcpy.CalculateField_management(New_Field___6_, "pro_id", pro_id, "VB", "") 

# Process: Calculate Field (5) 
arcpy.CalculateField_management(v1_shp__2_, "pro_tip", pro_tip, "VB", "") 

# Process: Calculate Field (6) 
arcpy.CalculateField_management(v1_shp__6_, "plan_adi", "\"%Name%\"", "VB", "") 

# Process: Collect Values 
arcpy.CollectValues_mb("F:\\gis_workspace\\sil\\1.shp") 

# Process: Merge 
tempEnvironment0 = arcpy.env.scratchWorkspace 
arcpy.env.scratchWorkspace = "C:\Users\Merve\Documents\ArcGIS\Default.gdb" 
arcpy.Merge_management(Output_Values, line_merge_shp, "pro_id \"pro_id\" true true false 0 Long 0 0 ,First,#,F:\\gis_workspace\\sil\\1.shp,pro_id,-1,-1;pro_tip \"pro_tip\" true true false 0 Long 0 0 ,First,#,F:\\gis_workspace\\sil\\1.shp,pro_tip,-1,-1;plan_adi \"plan_adi\" true true false 0 Text 0 0 ,First,#,F:\\gis_workspace\\sil\\1.shp,plan_adi,-1,-1") 
arcpy.env.scratchWorkspace = tempEnvironment0 

# Process: Repair Geometry 
arcpy.RepairGeometry_management(line_merge_shp, "DELETE_NULL") 

# Process: Select Data 
arcpy.SelectData_management(Dataset, "Annotation") 

# Process: Calculate Value (2) 
arcpy.CalculateValue_management("\"%Name%\"+\"_anno\"", "", "String") 

# Process: Feature Class to Feature Class 
arcpy.FeatureClassToFeatureClass_conversion(Annotation, sil__3_, dosya_anno, "", "", "DocName") 

# Process: Delete Field 
arcpy.DeleteField_management(bodrum_3_anno_shp__2_, "Entity;Handle;Owner;LyrFrzn;LyrLock;LyrOn;LyrVPFrzn;LyrHandle;EntColor;LyrColor;BlkColor;Linetype;EntLinetyp;LyrLnType;BlkLinetyp;Elevation;Thickness;LineWt;EntLineWt;LyrLineWt;BlkLineWt;RefName;LTScale;ExtX;ExtY;ExtZ;DocName;DocPath;DocType;DocVer;ScaleX;ScaleY;ScaleZ;FontID;Height;TxtAngle;TxtWidth;TxtOblique;TxtGenType;TxtJust;VertAlign;TxtFont;TxtBoxHt;TxtBoxWd;TxtRefWd;TxtAttach;TxtDir;LnSpace;SpaceFct;TxtMemo;EntLinetype;BlkLinetype") 

# Process: Add Field 
arcpy.AddField_management(kat_0_zemin_anno_shp__2_, pro_id_field, long, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") 

# Process: Add Field (3) 
arcpy.AddField_management(New_Field_, pro_tip_field, Field_Type__6_, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") 

# Process: Add Field (2) 
arcpy.AddField_management(New_Field___3_, plan_adi_field, text, "", "", "", "", "NULLABLE", "NON_REQUIRED", "") 

# Process: Calculate Field 
arcpy.CalculateField_management(New_Field___2_, "pro_id", pro_id, "VB", "") 

# Process: Calculate Field (2) 
arcpy.CalculateField_management(v1_shp, "pro_tip", pro_tip, "VB", "") 

# Process: Calculate Field (3) 
arcpy.CalculateField_management(v1_shp__3_, "plan_adi", "\"%Name%\"", "VB", "") 

# Process: Collect Values (2) 
arcpy.CollectValues_mb("C:\Users\Merve\Desktop\dwgtoshp\yenidwgdosyaları") 

# Process: Merge (2) 
arcpy.Merge_management(Output_Values__2_, anno_merge_shp, "pro_id \"pro_id\" true true false 0 Long 0 0 ,First,#,F:\\gis_workspace\\sil\\1.shp,pro_id,-1,-1;pro_tip \"pro_tip\" true true false 0 Long 0 0 ,First,#,F:\\gis_workspace\\sil\\1.shp,pro_tip,-1,-1;plan_adi \"plan_adi\" true true false 0 Text 0 0 ,First,#,F:\\gis_workspace\\sil\\1.shp,plan_adi,-1,-1") 

# Process: Repair Geometry (2) 
arcpy.RepairGeometry_management(anno_merge_shp, "DELETE_NULL") 

Répondre

0

IterateDatasets est un outil designed for use only in ModelBuilder.

Pour effectuer la même chose dans un script Python, vous devez créer une liste d'ensembles de données (arcpy.ListDatasets), puis parcourir la procédure avec une boucle standard, par ex.

arcpy.env.workspace = dwg_dosyalari # sets workspace to use 
datasets = arcpy.ListDatasets() 
for dataset in datasets: 
    # do things