reclosedev / pyautocad

AutoCAD Automation for Python ⛺
http://pypi.python.org/pypi/pyautocad/
BSD 2-Clause "Simplified" License
506 stars 143 forks source link

Plot automation #42

Open Eligio-Cazo opened 2 years ago

Eligio-Cazo commented 2 years ago

I'm working on a project of plan plotting automation with python, I was able to do it with pywin32 but I couldn't do it with pyautocad. The problem itself is that I need a point of only 2 coordinates for the plotting window, APoint uses three dimensions, is there any alternative to solve this problem?

acad.ActiveDocument.ActiveLayout.SetWindowToPlot(Point1, Point2) Point1 and Point 2 must be only x , y coordinates.

zangdol commented 1 year ago

Umm. Im using SendCommand

Direction = "Portrait"
command_template = ("-Plot\n" "Yes\n" "Model\n" "\n" "\n" "\n" f"{Direction}\n" "No\n" "Window\n" "<P1.X>,<P1.Y>\n"
"<P2.X>,<P2.Y>\n" "Fit\n" "Center\n" "Yes\n" "\n" "Yes\n" "\n" "No\n" "Y\n" "Y\n") ................................ sset = acad.get_selection() # select plot blocks
for block in acad.iter_objects('blockreference', sset): if block.name == title: block_box = block.GetBoundingBox() Lcorner = block_box[0] Hcorner = block_box[1] MinPoint = Lcorner[:2] MaxPoint = Hcorner[:2]

                    #
                    command = command_template.replace("<P1.X>", str(MinPoint[0]))
                    command = command.replace("<P1.Y>", str(MinPoint[1]))
                    command = command.replace("<P2.X>", str(MaxPoint[0]))
                    command = command.replace("<P2.Y>", str(MaxPoint[1]))

                    # 프린터 설정 확인
                    if printer != "없음":     
                        myDoc.SendCommand(command)

Eligio-Cazo commented 1 year ago

That code is probably fine for your needs. I actually needed this to work for an automation of plotting drawings, when selecting the frame that plots what is inside the frame, in this case the frame is a polyline, sometimes I have more than 50 drawings to print. But CAD files are generated by other software that does not use paper mode or layouts, and it is frustrating when printing them. But I already made it work with pwin32.