AutoCAD绘图批量打印,土木狗可以有

查看 142|回复 11
作者:易一辅助   
[table][tr][td]Talk is cheap , show you my code:
本主搜集了大量的土木图纸,寄希望有一天AI可以炼化,解放土狗的悲催一生。
[Asm] 纯文本查看 复制代码from pyautocad import Autocad
import win32com.client
import win32print
import pythoncom
import time
# 创建AutoCAD对象
acad = win32com.client.Dispatch("AutoCAD.Application.23")
# 获取活动文档和模型空间
acaddoc = acad.ActiveDocument
acadmod = acaddoc.ModelSpace
layout = acaddoc.layouts.item('Model')
plot = acaddoc.Plot
# 获取默认打印机
_PRINTER = win32print.GetDefaultPrinter()
_HPRINTER = win32print.OpenPrinter(_PRINTER)
# 打印样式设置函数
def PrinterStyleSetting():
    acaddoc.SetVariable('BACKGROUNDPLOT', 0)
    layout.ConfigName = 'RICOH MP C2011'
    layout.StyleSheet = 'monochrome.ctb'
    layout.PlotWithLineweights = False
    layout.CanonicalMediaName = 'A3'
    layout.PlotRotation = 1
    layout.CenterPlot = True
    layout.PlotWithPlotStyles = True
    layout.PlotHidden = False
    print(layout.GetPlotStyleTableNames()[-1])
    layout.PlotType = 4
# 默认起始位置和绘图尺寸
DEFAULT_START_POSITION = (3, 3)
DRAWING_SIZE = (598, 422)
DRAWING_INTEND = 700
# 后台打印类
class BackPrint(object):
    _instance = None
    def __new__(cls, *args, **kw):
        if cls._instance is None:
            cls._instance = super(BackPrint, cls).__new__(cls)
        return cls._instance
    def __init__(self, PositionX, PositionY):
        self.x = PositionX
        self.y = PositionY
    @staticmethod
    def APoint(x, y):
        return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, (x, y))
    def run(self, Scale=1.0):
        po1 = self.APoint(self.x * Scale - 1, self.y * Scale)
        po2 = self.APoint(self.x * Scale - 1 + DRAWING_SIZE[0], self.y * Scale + DRAWING_SIZE[1])
        layout.SetWindowToPlot(po1, po2)
        PrinterStyleSetting()
        plot.PlotToDevice()
# 打印任务类
class PrintTask:
    def __init__(self, maxPrintPositionArray, startPosition=(DEFAULT_START_POSITION[0], DEFAULT_START_POSITION[1])):
        self._PrinterStatus = 'Waiting'
        self.maxPrintPositionArray = maxPrintPositionArray
        self.printBasePointArray = []
        self.taskPoint = startPosition
        self.PrintingTaskNumber = 0
    def runtask(self):
        if not self.printBasePointArray:
            self.printBasePointArray = self.generalPrintBasePointArray(self.maxPrintPositionArray)
        for position in self.printBasePointArray:
            self.taskPoint = position
            current_task = BackPrint(*position)
            current_task.run()
            self.PrintingTaskNumber = len(win32print.EnumJobs(_HPRINTER, 0, -1, 1))
            while self.PrintingTaskNumber >= 5:
                time.sleep(1)
                self.PrintingTaskNumber = len(win32print.EnumJobs(_HPRINTER, 0, -1, 1))
            time.sleep(1)
    def ResumeTask(self):
        pass
    def generalPrintBasePointArray(self, maxPrintPositionArray):
        printBasePointArray = []
        next_drawing_xORy_intend = DRAWING_INTEND
        current_x = int((self.taskPoint[0] - 4) / DRAWING_INTEND) * DRAWING_INTEND + DEFAULT_START_POSITION[0]
        current_y = int((self.taskPoint[1] - 4) / DRAWING_INTEND) * DRAWING_INTEND + DEFAULT_START_POSITION[1]
        for position in maxPrintPositionArray:
            while current_x

土木, 批量

Apollo   

请问作者,第8行中“AutoCAD.Application.23”指的是发布年“2023版”?还是release number “R23版”?
或者说,这个脚本只能用于特定版本的CAD对吧?
gxj139   

感谢分享
能实现后台批量打印 就已经能解放好多土木狗的双手了
AI炼化实现了 就真的会"伤狗了"
HHJ200318   

感谢分享
huixin2017520   

AI到来,土木末日也就不远了
limzuo   

请教这个代码如何使用?
fengzt   

虽然不知道怎么用,但是还是谢谢
jun269   

等到AI真的到来,那基本上所有人的末日也就到了
yinlin   

就给这个?你把我这土木狗想得太厉害了
gy137   

不明觉厉
您需要登录后才可以回帖 登录 | 立即注册

返回顶部