0

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

Artichoke
  • 1
  • 2
  • 1
    Stack Overflow is not a free code writing service. You are expected to try to write the code yourself. After doing [more research](http://meta.stackoverflow.com/questions/261592) if you have a problem you can post what you've tried with a clear explanation of what isn't working and providing a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). I suggest reading [How to Ask a good question](https://stackoverflow.com/questions/how-to-ask). Also, be sure to [take the tour](https://stackoverflow.com/tour). – bfris Jan 30 '22 at 17:46
  • 2
    I haven't use pyautocad, but the [docs are here](https://pyautocad.readthedocs.io/en/latest/index.html) and [this page](https://pyautocad.readthedocs.io/en/latest/usage.html) seems like a good place to start. – bfris Jan 30 '22 at 17:48

1 Answers1

1

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 to activate the command.