Reputation: 1
i'm not a professional coder and i'm so sorry for my english :) i hope you understand.
I'm trying to automate part of my job. i have to create dwg; every layer for me is a sheet (like A4 paper), for that reason i have to change layer and import specific dwg/dxf from my repository symbol.
For example i have to: (start new project) open newproject.dwg (paste dwg) import C:\repository_cad\symbol1.dwg in layer n°3 with coordinate X 100 Y 200. (write text in the middle of symbol) write "SYMBOL_1" layer n°3 coordinate X 150 Y200 alignment center. (insert logo image) import C:\repository_cad\image1.jpg in coordinate X 10 Y 20
i'm trying to use pyautocad, but i cant find a command for import dxf, and i dont find information about changing layer. i find out only the command for draw the line, circle ecc, but if i have to re-draw all my repository by python i need to much time, i hope is possible copy draw from another dwg and paste it in my new dwg.
can someone give to me a little help with these 3 command? maybe is not possible making this stuff on pyautocad? is there other library for python?
i read the docs but i dont see info about some import function. so, i tried:
from pyautocad import Autocad, APoint
acad = Autocad(create_if_not_exists=False)
acad.prompt("Hello, Autocad from Python\n")
print (acad.doc.Name)
and it's works, on autocad terminal i can see "Hello, Autocad from Python" in the Docs i find out how write a autocad-command from python. The function is: prompt() i tried:
acad.prompt('-INSERT') #-INSERT is the autocad command for import dxf or dwg
acad.prompt('C:\SPAC\Librerie\Elettr\02-15-04.dwg')#this is the path of the cad
acad.prompt('-15 -15') #coord X Y of the point where i want to paste
acad.prompt('1') # 1 is the scale factor in X
acad.prompt('1') # 1 is the scale factor in Y (autocad askt first in X and after in Y
acad.prompt('0') #degree of rotation
at this point i havent error on python and no error on autocad terminal, but the draw not appear on cad
thanks Max
Upvotes: 0
Views: 3633
Reputation: 31
acad.prompt()
will just echo the string to the command line. What you are looking for is acad.doc.SendCommand()
, e.g.
acad.doc.SendCommand('-INSERT ')
Notice there is a blank space after the autocad command, that stands for <enter>
to activate the command.
Upvotes: 3
Reputation: 1
go through the Object Model (ActiveX) of autocad website which will help you to code/use more objects/tools of the pyautocad
https://help.autodesk.com/view/OARX/2022/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30 for further information you may take the course "Learn Automation of AutoCAD using python" from udemy
Upvotes: 0