明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 608|回复: 2

[【PyCAD】] pycad 横向,竖向复制文本,直接粘贴到excel

[复制链接]
发表于 2022-4-12 16:16 | 显示全部楼层 |阅读模式
本帖最后由 枫叶棋语 于 2022-4-12 16:22 编辑

# -*- coding: utf-8 -*
from pycad.system import *
from pycad.runtime import *
import clr, System
clr.ImportExtensions(System.Linq)
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import Clipboard
@command()
def wq(doc):
    #竖向复制文字
    with dbtrans(doc) as tr:
        str=""
        i= 0
        ss=edx.ssget(mode=':A',filters=(0,'*text'))
        if (not ss.ok)and(len(ss.value)):return
        texts=(
            ss.Cast[acdb.ObjectId]()
            .Select(lambda i: tr.getobject(i))
            .OrderBy(lambda t: t.Position.X))
        strlen=len(list(texts))
        for text in  texts:
            i=1+i
            if i !=strlen :
                str=str+text.TextString+"\n"
            else:str=str+text.TextString
        Clipboard.Clear()
        Clipboard.SetText(str)
@command()
def we(doc):
    #横向复制文字
    with dbtrans(doc) as tr:
        str=""
        i= 0
        ss=edx.ssget(mode=':A',filters=(0,'*text'))
        if (not ss.ok)and(len(ss.value)):return
        texts=(
            ss.Cast[acdb.ObjectId]()
            .Select(lambda i: tr.getobject(i))
            .OrderBy(lambda t: t.Position.Y))
        list1=list(texts)
        list1.reverse()
        strlen=len(list1)
        for text in  list1:
            i=1+i
            if i !=strlen :
                str=str+text.TextString+"\n"
            else:str=str+text.TextString
        Clipboard.Clear()
        Clipboard.SetText(str)

发表于 2022-4-13 08:32 | 显示全部楼层
大神你这个是啥语言呀,如何用
 楼主| 发表于 2022-4-15 17:14 | 显示全部楼层
664571221 发表于 2022-4-13 08:32
大神你这个是啥语言呀,如何用

我刚学习,用的pycad,python
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-5 10:46 , Processed in 0.206319 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表