Hi, welcome back in this video, we will drew a D building plan with Python.
The outputs exactly will be this one in here.
So that's a PNG image generated by running the script.
It's a simple one room plan.
So these are the walls of these is supposed to be the window small walls, and this is apparently the
door.
Normally, it has more details, but I wanted to keep it simple not to get the low sense of details
into civil engineering detail so you can expand this if you want.
You can even make this a batch process so you can create.
You can generate multiple multiple P and G screenshots of different dimensions.
And you can also drew all the figures not only in the field of of civil engineering, but you can do
other things because the techniques we will be using are general techniques.
So we'll be using two libraries to implement this.
The first one is point all to gooey, and I covered PI out of the previous section.
So it is used to control the moles so the cursor can be controlled by Python.
It can draw things you can go and double click on a file.
It can copy text and paste it.
You can move the cursor to wherever you want via your Python script.
So in this video particularly, we'll be controlling the cursor to draw on a canvas.
So this is a program.
And this is an online web app, its own as paint dot app.
You can access it on that website and you can draw by hand.
You can get the pencil.
Make sure it's it's a black color and you can draw things.
But we will be doing this drawing of via Python.
And then we will be using a second library to produce the PNG image that a library is assessed and it's
used to capture screenshots.
So will be screenshots in the area where the drawing is, as you can see in the output here.
MSRs was also covered in the previous section.
So with that sets, let's get started.
I have an empty file here where I'll be writing my Python script and here on the side, you should have
an app that allows you to sketch.
So I'll suggest if you don't have any app, I would suggest you go to this free painting app just being
that app and keep it on the health of your screen.
So on one hand, if you have Python, on the other hand, if you have this program or at least just
keep it when you were on the script.
So let's import PI altogether, and let's import from A.S. import.
And assess and tools, these are all the third party functions that we need.
And then we want to know why starting points of the drawing, so maybe it's somewhere in here.
And of course, we want to know what pixels on my screen.
This position has.
So we want to know how many pixels from here to here and how many pixels from there.
To hear someone here.
So that's the ex ambassador, why we can get those using all go that position.
So that's a method that will give us a position.
You can print out the position and now to get the current position of a cursor, the cursor needs to
stay at the position which coordinates you want to know.
So if you put the cursor there and then you should find a way to execute the scripts using keyboard
shortcuts.
You don't want to move a cursor there because it will give us the coordinates for that point.
So I'm going to keep the cursor here and switch to PI charm and then use shift control or in your case,
could be a different shortcuts, depending on your I.D. the shortcut to run your script.
So for me, it was, as you can see here, control or shift commands are as it is in here.
So those are the positions that for now, I can move the cursor.
Using PI automatically does move to.
I can move the cursor to those coordinates.
That's the X and three five five is the Y the duration.
One second is going to be the time that the cursor moves from the current position to that position.
So see now if I execute the scripts using this button, the cursor will move to that position.
So it's important now not to move the windows.
So this window, the drawing area should be staying here, so don't expand it or minimize it.
All you can do is if you are sure that you take, it's about the same position as it is now.
So once we've moved the cursor there, then we want to start drawing, so let's say we want to go down
here.
For that, I'm going to use pie altogether.
First, I want to click with the malls and then pejoratively to drag, so I want to drag zero to hundreds.
You can use whatever dimension you like outside just to just keep my dimensions.
Not to get confused with numbers.
So what that will do is this cursor moves there and then, oops, it's supposed to go down here.
But it isn't because I forgot.
The bottom arguments, which is left, so the left button of the mouse should be pressed.
That's how you draw things in this canvas.
You press the left button and then you drag the mouse.
So that's what this method is doing.
And let's also add the duration of zero point three.
I think it's good, and let's try again.
Yeah.
So now we have a line that we want to go, writes, he writes.
Sixty pixels.
So pilots agree.
So let me orient you a bit by adding some comments, maybe just here.
Down.
It's 100.
Pixels and the next one is drag.
60.
So we're talking about ex going to the right 60 and the zero will not be moving because it's just a
horizontal line.
So 60 zero duration is equal to zero point three.
Button is again left.
And let's see.
Down, left, sorry, right down and write six pixels of an we want to draw the window, so we want
to go up maybe three pixels.
So let me on do that.
And so this was right.
Six pixels and then we want to go.
Down so zero x down would be three.
If you go down or you can also go up and go like that.
So let's go up.
If you want to go up, it would be minus three.
Because the ex or the origin is here and it's up here.
So when you go down, it's plus when you go up, it's minus.
So that's a beat up three pixels, and let's see.
So we go down right up and then after that, we want to go.
Maybe, right?
But we could also go down six pixels, so three four, that's on another three.
And we see.
So zero, six four going down.
Zero point three.
Bottom is left again, so that would be done six pixels.
It's not a problem that you're right, you're going at the same line.
You are over drawing that same line there.
If you prefer, you could also use the move methods to skip the drawing.
But I wouldn't worry about that because we're not having any drawing problems, so I'll just use the
track again.
So down 60 and then once we're here, then we want to go, All right.
So the dimension of the door will be 60.
So let's see point also green.
They'll drag 60 to the right and zero duration 0.3 button is left.
So we're here.
We go in this direction and then we go up six pixels.
So let's do that as well duplicating this.
So up six pixels, that means minus six for going up.
So we should be here and then we should close that by going back here.
So I'm going to duplicate this again and say for going back 60.
Zero.
So let's rise.
We go down up.
Don't go there.
And we close it, so we added three new lines.
Right.
Six the pixels up, six pixels and left.
Six pixels.
So currently, the cursor is here, so we want to go back six the pixels.
And then we want to go down 160 pixels so you can use drag again.
Well, if you prefer, you can also use move.
So with Move, you want to do six a pixel to the right.
Duration zero point three.
It doesn't need to have a bottom argument because it's a move methods.
It's not throwing anything.
It's just going to the right.
And then we go with move, we go down three.
So we are here, we go right and then done three.
Yes.
So zero three four.
Going down duration zero point three.
And yeah, that's it.
That's.
Back.
Sixty pixels.
Don, thank.
Three pixels.
So right back, let's see.
Let's check it with Gordon right up, down, right up, left right, and then we go to the middle of
the window.
So now we want to go right again.
Let's copy one of these.
Copy that pasted in here.
So we want to go right.
I want to go right.
A hundred pixels.
So then.
So that's right.
And pixels, then I want to go up.
So up 120 pixels, so that's a B minus one, 20, so that is up.
One or two pixels?
So that should take us.
In throws, the window goes back and throws the wall and throws the wall up to where, then we have
a window.
So the wind, sorry, a door the door shouldn't have a line should be empty so we can use again ploy
altogether to move up.
Minus 14.
So zero, minus 40.
Skip, 40.
Pixels up, so to say, after we drove door, we want to draw one more line, so we are here, we want
to draw one more line in here, which according to my calculations, it is about 40 pixels, so we go
up 40 pixels.
So this is a drag duration, zero point three, but and we press the left button and let's see.
You go there and then we ready to go back from here to here.
That is.
220 so that some of these is 220.
Therefore, I want to copy this.
And it's here, it's a drag minus 220.
So we go to the left zero virtually, and that's it.
So let's add the comments of this was up 40 pixels and this is left 220 pixels.
And that's about it.
That now should complete all drawing.
Now we were ready to capture the shots of this area before I do that, I would like to change the duration
so you can do that.
If you are in charm, you could use refactoring tools so I can click over this.
All right, click and go to refactor and go to introduce variable.
And to replace all 14th occurrences.
And then I can write down the variable such as do.
So now doer is created here as a variable, and I can just change this to zero point zero zero one,
for example.
And that means all the drag operations will have a duration of zero point one.
No.
So the drawing would be much faster.
Yeah.
So let's go to the screen shots.
Step out for that, we'll use you.
I am as as.
And we did use this previously in the section before this.
So with emphasis, this is the exact code that we use there as screen parts of the screen will be a
dictionary.
It has a top key with its value, which are the rights in just a second.
It has a left key, also with its own value and then its sense of width.
That's also has a value, and finally, the hides.
So these will define the rectangle area where the screenshot will be captured.
So what is top?
But top is the pixels from the opera border over the full screen to where you want to store the screenshot.
So the number of pixels in this direction.
So that means we're looking at the why of this point.
So the starting point here has a why the number of pixels from there to there.
Therefore, we want to put that in here of the why of that was three fifty five.
So you can see three fifty five or you could say three forty five.
Because this is three, fifty five and up to somewhere in the air, but not reaching the point yet as
of both three forty five, so we want to have some area around the screenshots.
About ten pixels.
So that's why I'm saying three, four five here and four left would be the X.
So that's the area from here to here and there to be the X 12 a scene.
So let's say 12 eight to have that's 10 pixel border and the width is well, the width is.
This year, plus 10 pixels, plus 10 pixels, so that plus 20 pixels, the width of that is, as I calculated,
it is to 20.
So that would be 240, adding that's 220 pixels, and then the heights was 200.
And we want to say 220.
Let's make some space.
So those are the borders of the screenshots.
So let's get the image with screen grab.
Part is the argument for this, and then finally, tools that Pete to PNG image and the RG Beam property
to give us the bytes of that image objects.
So we write the points given the size of that area and given an ultimate's file of path output dot,
let's say to that PNG to distinguish it from that's existing PNG file.
So I'm going to run this.
That's a drawing.
And we've got a profile, so that is the final all.
You can see the pencil here is visible, so we can fix that simply by moving the cursor using the move
methods.
We can move.
It's 50 pixels to the left and 50 pixels up.
So the pencil is here.
We can move it here.
So that's it is outside of the screenshot area and saron it again.
Drawing and then the screen shots will replace with override the existing foil.
So that's the final outputs.
Finally, we did it.
I hope you did too, and thank you for following this and I'll talk to you later.
See you.