使用ezdxf更改图层名称

时间:2019-08-09 02:38:08

标签: python-3.x autocad dxf

关于使用ezdxf更改图层名称,当您更改图层名称时,您想要更改图层名称,以便它是附加到现有图层名称上的数字的延续。

赞。 AutoCAD图层名称列表:

    ABC1
    ABC2
    ABC3
    DEF
    GHI

更改后的层名称列表:

    ABC1
    ABC2
    ABC3
    ABC4
    ABC5

我尝试编写代码,但出现错误。

old = '\w+'  ##DEF,GHI
a='\w+'+'\d'  ##Defining an existing layer name → ABC1,ABC2,ABC3
l=1
for layer in dwg.layers:
    s=layer.dxf.name
    old_ = re.search(old,s)
    if old_:
        old_=old_.group()
    else:
        pass

    b=re.search(a,s)
    if b:
        b=b.group()
        c=b[-1]   ##Get last number of layer name
        new_ = 'ABC'+str(int(c)+l)  ##Defining a new layer name
        l+=1
    else:
        pass

#Changing the layer name
#When there is no corresponding layer name:{}not found                
    try:
        layer = dwg.layers.get(old_)
    except ValueError:
        print('Layer {} not found.'.format(old_))
    else:
        layer.dxf.name = new_ #DEF→ABC4,GHI→ABC5

 File …, 
    layer = dwg.layers.get(old_)

 File …, 
    key = self.key(name)

File …,
    entity = entity.dxf.name

AttributeError: 'NoneType' object has no attribute 'dxf'

我想让你告诉我解决方法。

0 个答案:

没有答案