Sketch visual location tool

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
drmacro
Veteran
Posts: 9010
Joined: Sun Mar 02, 2014 4:35 pm

Sketch visual location tool

Post by drmacro »

When the mouse hovers over features in the tree view or over edges in the Sketcher Element tile, the objects under the cursor highlight in the 3D view.

Would it be possible to do that from Python and display a plane in 3D view when the cursor is over a sketch?

The plane would be translucent and represent the placement of the sketch. While the Python code was running it would allow a quick look at where the sketch is. Much like Datum shows when not hidden. But, I'm thinking something more dynamic and transient.

I know the have been several forum threads about some visual indication of where a sketch is, but most of those have been talking about a visual LCS.

Is this even possible from Python? Or am I letting an idle mind wander. :mrgreen:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
edwilliams16
Veteran
Posts: 3194
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Sketch visual location tool

Post by edwilliams16 »

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("Sketch001")
gpl = obj.getGlobalPlacement()
plane = Part.Plane()
plane.Position = gpl.Base
plane.Axis = gpl.Rotation.multVec(App.Vector(0,0,1))
Part.show(plane.toShape())
Trickier if we have links involved...
Attachments
sketchplane.FCStd
(8.67 KiB) Downloaded 7 times
Screen Shot 2022-06-08 at 12.39.13 PM.png
Screen Shot 2022-06-08 at 12.39.13 PM.png (12.72 KiB) Viewed 570 times
edwilliams16
Veteran
Posts: 3194
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Sketch visual location tool

Post by edwilliams16 »

Good to show the origin and axes, too.

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("Sketch001")
gpl = obj.getGlobalPlacement()
plane = Part.Plane()
plane.Position = gpl.Base
plane.Axis = gpl.Rotation.multVec(App.Vector(0,0,1))
Part.show(plane.toShape(), obj.Name + '_Plane')
line_x = Part.Line()
line_y = Part.Line()
line_x.Location = gpl.Base
line_y.Location = gpl.Base
line_x.Direction = gpl.Rotation.multVec(App.Vector(1,0,0))
line_y.Direction = gpl.Rotation.multVec(App.Vector(0,1,0))
Part.show(line_x.toShape(), obj.Name + '_X')
Part.show(line_y.toShape(), obj.Name + '_Y')
Inside a body need to make Datum Lines and Planes instead.
Screen Shot 2022-06-08 at 5.54.11 PM.png
Screen Shot 2022-06-08 at 5.54.11 PM.png (16.52 KiB) Viewed 515 times
freedman
Veteran
Posts: 3478
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Sketch visual location tool

Post by freedman »

I made this macro long time ago, it should work. When you click on a tree sketch it hides everything and highlights the sketch elements for 1 second.
I suppose the origins could be turned on also. Maybe this will help.

I have never tried to get selections by hovering in the tree. I thought that only worked in the 3D.
Attachments
Sketcher_flasher.FCMacro
(5.79 KiB) Downloaded 11 times
drmacro
Veteran
Posts: 9010
Joined: Sun Mar 02, 2014 4:35 pm

Re: Sketch visual location tool

Post by drmacro »

I'll take a look at these later (on a tablet ATM).

But, I was thinking of when the script was running it would be more like a role over in the tree would pop up the sketch. Move the mouse to another sketch in the tree and that location would replace the last.

Maybe these do that, I'll have a look in a bit.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Post Reply