Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open DWG files and manipulate them #48

Open
Bregolas3 opened this issue Oct 29, 2023 · 3 comments
Open

Open DWG files and manipulate them #48

Bregolas3 opened this issue Oct 29, 2023 · 3 comments

Comments

@Bregolas3
Copy link

I am trying to figure out if it is possible to open multiple already existing dwg files through pyautocad and manipulate them to create a single dwg file. Basically, I am trying to figure out if I can take various drawings of different length walls and manipulate those walls to create a single room. I am trying to automate this process as each wall is already drawn and it is tedious to pull in each wall every time I go to draw a room. Does pyautocad support something like this? I was unable to find anything in the documentation on opening and manipulating previously created DWG files.

@CEXT-Dan
Copy link

Sure, you need a CAD platform like AutoCAD,
with pyautocad you can use AutoCAD's ActiveX API to insert each sub drawing into a main drawing with
InsertBlock, you can then manipulate each item in the block, or explode all the blocks into modelspace

@Bregolas3
Copy link
Author

Bregolas3 commented Oct 29, 2023

Would you mind possibly walking me through how I could take four walls and manipulate them in a way where I rotate the walls to create a room in this capacity? If I have each wall drawn and I just need to insert them into the drawing, I would need to make each wall a block right? And then pyautocad lets me rotate each wall and place it in a manner where they line up so it creates the room right? Would a previously existing subdrawing be able to be placed in this manner? And then, say I wanted to automate the process of creating the end product and creating the file(s) that would be returned to me as a full drawing, is that something that pyautocad can also do? And if so what would I need to call for that?

@CEXT-Dan
Copy link

CEXT-Dan commented Oct 29, 2023

Inserting blocks is a fundamental operation you should probably understand before you begin writing code.

it’s also a good idea to become somewhat familiar with the API pyautocad accesses
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-A809CD71-4655-44E2-B674-1FE200B9FE30

insertBlock imports the drawing and creates the block(s) for you
The insert block has insertion point, scale and rotation arguments
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-17F86FDD-B7FC-4F43-9F16-B4958F73A66D

`pseudo code
from pyautocad import Autocad,APoint
acad = Autocad(create_if_not_exists = True)

#one for each wall
point = APoint(0,0)
wallX = acad.model.InsertBlock(point, “wallpath.dwg”, scaleX, ScaleY, scaleZ, Rotation)

doc = acad.ActiveDocument

doc.SaveAs("C: \room.dwg")
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants