当前位置:网站首页>ArcGIS Pro脚本工具(6)——修复CAD图层数据源
ArcGIS Pro脚本工具(6)——修复CAD图层数据源
2022-06-30 09:37:00 【学点GIS】
Pro对CAD文件的支持显而易见的优于ArcMap。虽然都是将CAD识别成点、线、面、多面体和注记5大类,但是当我们拖动其中一类到Pro中时,Pro自动将其分图层显示,并且图层的颜色与CAD一致。nice!

但是尴尬的是,一旦CAD文件移动了位置或者改了名字,就是一长列的红色惊叹号警告。有经验的使用者可能期望修复一个图层后,其他图层自动修复,但是很可惜这对这些CAD图层无效。
那我重新拖CAD进来不就成了?可能不太行,因为已经在Pro里改过一些图层的符号系统了,重新拖CAD进来就得重新做很多图层的符号系统,太麻烦了。
针对不同的情况,有不同的解决办法。
1、CAD文件位置改变,文件名不变
这种情况下,比较方便的办法是打开 目录视图-目录选项卡-数据源-工作空间,选择CAD图层组,新路径中填入CAD文件现在的位置,点击应用,完成。

2、CAD文件位置和文件名都已经改变
解决办法比上面多出一步,就是需要先更新CAD文件名。还是考虑使用脚本工具来实现。
Python脚本
import os
import arcpy
aprx = arcpy.mp.ArcGISProject(r"CURRENT")
m = aprx.activeMap
groupLayer = arcpy.GetParameterAsText(0)
lyrs = m.listLayers()
cad = arcpy.GetParameterAsText(1)
cad_name = os.path.basename(cad)
cad_path = os.path.dirname(cad)
cp = {'workspace_factory': 'Cad', 'connection_info': {'database': cad_path}}
for lyr in lyrs:
longName = lyr.longName
if longName.startswith(groupLayer) and lyr.isGroupLayer==False:
lyrCIM = lyr.getDefinition("V2")
dc = lyrCIM.featureTable.dataConnection
# Update the feature dataset with the new CAD file name
dc.featureDataset = cad_name
# Update layer CIM
lyr.setDefinition(lyrCIM)
lyr.updateConnectionProperties(lyr.connectionProperties, cp)
sym=lyr.symbology
color=sym.renderer.symbol.color
color['RGB'][3]=100
sym.renderer.symbol.color=color
lyr.symbology=sym
arcpy.AddMessage('已修复 '+lyr.name)
参数设置

运行演示

模型说明
除了修复CAD图层的数据源外,脚本工具也取消了所有CAD图层的面符号的透明度,方便在外观选项卡上统一调整。
边栏推荐
- Go -- maximum heap and minimum heap
- C语言实现扫雷游戏,附详解及完整代码
- G 代码解释|最重要的 G 代码命令列表
- Description of event object
- The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
- MySQL index, transaction and storage engine of database (3)
- unable to convert expression into double array
- MIT-6874-Deep Learning in the Life Sciences Week6
- The URL copied by the browser and pasted into the document is a hyperlink
- Description of event flow
猜你喜欢

Great Wall digital art digital collection platform releases the creation Badge

逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展

MySQL log management, backup and recovery of databases (1)

【C语言快速上手】带你了解C语言,零基础入门③

陈颢天 荣获第七届少儿模特明星盛典全国总决赛 全国总冠军

浏览器复制的网址粘贴到文档是超链接

Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect

C语言实现扫雷游戏,附详解及完整代码

2022第六季完美童模 合肥赛区 初赛圆满落幕

C語言實現掃雷遊戲,附詳解及完整代碼
随机推荐
[JVM] brief introduction to CMS
6.Redis新数据类型
MySQL log management, backup and recovery of databases (1)
Leetcode question brushing (I) -- double pointer (go Implementation)
ModuleNotFoundError: No module named ‘_ swigfaiss‘
Automated stock trading ensemble strategy based on Reinforcement Learning
Koreano essential creates a professional style
逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
著名画家史国良《丰收时节》数字藏品上线长城数艺
About the split and join operations of strings
采坑:Didn‘t receive robot state (joint angles) with recent timestamp within 1 seconds.
[C language quick start] let you know C language and get started with zero basics ③
Input limit input
What is the real performance of CK5, the king machine of CKB?
Tooltips in the era of touch
OSError: [Errno 28] No space left on device
Test memory read rate
train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
MIT-6874-Deep Learning in the Life Sciences Week6
Description of event object