Create image plane by drawing a rectangle?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Hologram
Posts: 201
Joined: Thu Nov 03, 2022 3:05 pm

Create image plane by drawing a rectangle?

Post by Hologram »

Hi,

Would it be possible to create a marco, which creates an image plane by drawing a rectangle? I often place images based on certain rectangle sizes, so being able to do this in FreeCAD would really help positioning and scaling an image.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Create image plane by drawing a rectangle?

Post by jfc4120 »

Hologram
Posts: 201
Joined: Thu Nov 03, 2022 3:05 pm

Re: Create image plane by drawing a rectangle?

Post by Hologram »

Earlier, I didn't find any related thread on this. I did find this one now: https://forum.freecadweb.org/viewtopic.php?t=4588.
Also, I assumed this to be pretty clear question, but I can see why it might not be. So I have added the context below:

I would like to add an image plane by drawing a 2pt rectangle like so:
See gif: https://gifyu.com/image/Sm4x3
E: Image was too large for the forum and couldn't embed it.

The reason is that I also use other CAD software, which does not have a parametric sketcher. I might have to model something that is not at the origin, so i is aligned correctly. The workflow is as follows: I export a 2D line drawing, which blocks out the position of objects. I then go to the draft workbench or the sketcher, which I want to use to trace over an image. I look for the rectangle that I need the image to conform to (usually, these would be correctly scaled based on the image size*). Then create whatever I need to create in FreeCAD, export it and import the file in my software of choice. My FreeCAD model will be aligned with the rest of the external model, thanks to the alignment rectangle.
Now, if I where to add an image to the origin by creating an image plane. I would have to scale it, look up the dimensions and then move the image plane, whereas placing it by a 2 pt rectangle is both easier and less error prone (it does scaling and positioning at once, plus it does not require looking up dimensions).

With the 2pt rectangle and a texture map, the tree view shows me a rectangle, which is less obvious to find later on than an image listing (also consider I might hide it in view temporarily).
rectangle image.png
rectangle image.png (11.96 KiB) Viewed 1009 times
* For instance, when I need to create a series of buildings, I would export a satellite image from Qgis and would also export the extents of the image as a DXF. I import the DXF and place the image based on the rectangle size in the DXF.
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Create image plane by drawing a rectangle?

Post by jfc4120 »

Would techdraw work for you.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Create image plane by drawing a rectangle?

Post by chrisb »

So you want something like this?
Take a plane and import an image - I took it frm the showcases here.
SnipScreenshot-903166.png
SnipScreenshot-903166.png (61.47 KiB) Viewed 941 times
Set X- and YSize of ImagePlane to that of the Rectangle with the expressions

Code: Select all

Rectangle.Length
Rectangle.Width
Attach it to the rectangle
SnipScreenshot-907f33.png
SnipScreenshot-907f33.png (34.1 KiB) Viewed 941 times

Move it by half of the image size i.e. by XSize and YSize. Now the image follows the rectangle parametrically
SnipScreenshot-1c252e.png
SnipScreenshot-1c252e.png (32.84 KiB) Viewed 941 times
Beyond that: Your workflow seems rather bizarre. I wonder what other CAD package you use, that cannot export a 3D object in any of the formats readable by FreeCAD. That would be way easier and way more precise.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Hologram
Posts: 201
Joined: Thu Nov 03, 2022 3:05 pm

Re: Create image plane by drawing a rectangle?

Post by Hologram »

I would need to check how this works with the code, can this all be turned into a macro where I select the image and then select the rectangle > align the two, for instance? Lots of people in architecture use image planes from 2pt. rectangles, so it would ease the workflow of many people.
chrisb wrote: Sun Jan 29, 2023 8:14 am Beyond that: Your workflow seems rather bizarre. I wonder what other CAD package you use, that cannot export a 3D object in any of the formats readable by FreeCAD. That would be way easier and way more precise.
Sure, they can all export whatever I need. I want to use FreeCAD in the conceptual phase, so I will be converting digital sketches (with digital brushes) to linework. The point is, to trace the sketches, I also need to do clean-up to the way it is drawn, for that, constraints are ideal to iterate. I already have the importing and exporting set up from earlier phases of work, so it's not as bizarre as it seems.

As for the software remark: Revit is just plain cumbersome with its hotkeys, not to mention, it can only do dimensional constraints, can't split splines, constrain splines and the list goes on. Fusion 360 image (canvas) functionality was only really made for use with an origin. It cannot relink images either (design 01 > design 02, etc.) so that's a no go. Perhaps it could be scripted for Fusion, but that's out of my abilities. For Rhino and Autocad, I don't like pressing spacebar for each and every input, not to mention, Rhino just put its parametric constraints on hold, whereas Autocad's block based constraints are, well... rather involved and slow to use for the simple purpose of tracing. That's why I decided to try FreeCAD (also as non cloud-based, non Autodesk alterative :mrgreen:).
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Create image plane by drawing a rectangle?

Post by chrisb »

Hologram wrote: Sun Jan 29, 2023 9:22 am I would need to check how this works with the code, can this all be turned into a macro where I select the image and then select the rectangle > align the two, for instance?
Yes, this can be done in Python, which you can call with an icon. You will have to do a bit of research how to do the attachment from Python, the rest is straight forward.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Hologram
Posts: 201
Joined: Thu Nov 03, 2022 3:05 pm

Re: Create image plane by drawing a rectangle?

Post by Hologram »

chrisb wrote: Sun Jan 29, 2023 9:51 am
Hologram wrote: Sun Jan 29, 2023 9:22 am I would need to check how this works with the code, can this all be turned into a macro where I select the image and then select the rectangle > align the two, for instance?
Yes, this can be done in Python, which you can call with an icon. You will have to do a bit of research how to do the attachment from Python, the rest is straight forward.
Ah, okay. Sounds pretty difficult, because I don't know where to start (I also need to learn python from scratch :? ). If anyone could create the macro for me, that would be much appreciated.
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Create image plane by drawing a rectangle?

Post by chrisb »

Hologram wrote: Sun Jan 29, 2023 2:21 pm I don't know where to start (I also need to learn python from scratch)
There is nothing wrong with that.

Start by watching the Python console.
Send objects to the console. Type "obj." and see the list of properties they have.
Look at other macros, how they do the selection.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Create image plane by drawing a rectangle?

Post by heda »

Post Reply