Offsetting sketch to global planes.

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Offsetting sketch to global planes.

Post by drmacro »

edwilliams16 wrote: Thu Dec 01, 2022 6:11 pm So using the existing code I see a couple of workarounds to create offset sketches.
  • Drag your current model into an outer Part container and attach your new sketch to its coordinate system.
  • Create a Part 'reference cube', select the face on the desired plane and create your sketch with the default FlatFace attachment.
Either way, you are then free to offset the sketch from your chosen global plane.

In this forum we typically advocate attaching sketches to offset global planes to avoid TNP, but I don't think we explain that in Part workbench this is not as straightforward as it might seem. We also chide people for unnecessarily wrapping their models in Part Containers, when on occasion this might be appropriate even if no assembly operations are anticipated.
The Attachment to base planes, in PD, is attaching to the LCS (the Origin object) of the Body. It in turn is "attached" to the global. The Origin object in a Body is static, thus attaching to it is what is advocated.

In the case of a Sketch outside a Body, the Placement is referenced to the global axis. The global axis is static.

When the sketch is create (outside a Body) with the planes offered in the creation dialog and the user selects other than XY, then there is a cognitive issue when the user needs to move the sketch normal to the sketch local Z axis.

Obviously there are uses for the Std_Part. I think most of the "chiding" is making it clear the Std_Part is not a prerequisite for a Body or anything else.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Offsetting sketch to global planes.

Post by edwilliams16 »

drmacro wrote: Thu Dec 01, 2022 7:14 pm
When the sketch is create (outside a Body) with the planes offered in the creation dialog and the user selects other than XY, then there is a cognitive issue when the user needs to move the sketch normal to the sketch local Z axis.
Agreed. And as Chrisb and I have pointed out, the cognitive issue gets more severe if the Attachment Offset is more complicated than a translation along an axis. That motivated the OP.
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Offsetting sketch to global planes.

Post by heron »

edwilliams16 wrote: Thu Dec 01, 2022 1:00 am I have work-arounds, but is there really no direct way to attach a sketch to the global coordinate system? This has been bugging me for a while.
Hello, sorry for the late reply, but I also found this problem and my workaround is to add a LCS:

Code: Select all

App.ActiveDocument.addObject("PartDesign::CoordinateSystem", "Zero")
This way I already have my "GCS" to attach my sketch.
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Offsetting sketch to global planes.

Post by edwilliams16 »

heron wrote: Wed Dec 07, 2022 5:16 pm

Code: Select all

App.ActiveDocument.addObject("PartDesign::CoordinateSystem", "Zero")
This way I already have my "GCS" to attach my sketch.
Good idea.
Via the Gui, apparently one is forced to put the LCS in a Body, then pull it out and delete the Body . It would be much nicer, if creating a Part Design| LCS gave the option of not putting it in a body.
Screen Shot 2022-12-07 at 8.14.18 AM.png
Screen Shot 2022-12-07 at 8.14.18 AM.png (48.87 KiB) Viewed 723 times
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Offsetting sketch to global planes.

Post by edwilliams16 »

Which gave me an idea that works in the Gui.
Create a default Lattice2|Lattice Placement|Single Custom Placement. It can be used as a global LCS to which sketches can be attached, in the same way as an LCS created in the python console
Screen Shot 2022-12-07 at 8.28.53 AM.png
Screen Shot 2022-12-07 at 8.28.53 AM.png (48.55 KiB) Viewed 711 times
Screen Shot 2022-12-07 at 8.28.33 AM.png
Screen Shot 2022-12-07 at 8.28.33 AM.png (12.42 KiB) Viewed 711 times
Attachments
globaloffset.FCStd
(7.67 KiB) Downloaded 6 times
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Offsetting sketch to global planes.

Post by heron »

edwilliams16 wrote: Wed Dec 07, 2022 6:31 pm Which gave me an idea that works in the Gui.
Oh, if you need to do it in the Gui, this LCS tool is in Manipulator WB
Captura.PNG
Captura.PNG (24.84 KiB) Viewed 704 times
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Offsetting sketch to global planes.

Post by chrisb »

Here are macros to create DatumGeometry and LCS globally: https://forum.freecadweb.org/viewtopic. ... 40#p304740
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Offsetting sketch to global planes.

Post by drmacro »

I'm actually amazed how little known these macros are:

https://github.com/sebasg84/planeFromFace

They allow the creation of sketches on any face, but with attachment offsets.

Select a face, run the macro and the sketch is attached to the base plane with the attachment offset of the selected face.

And repairing after the model has been updated.

Select the new face and the sketch, run the macro and it repairs the offset.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Offsetting sketch to global planes.

Post by edwilliams16 »

Some handy stuff there, including one-liners for the console:

Code: Select all

App.ActiveDocument.addObject('PartDesign::CoordinateSystem')
App.ActiveDocument.addObject('PartDesign::Point')
App.ActiveDocument.addObject('PartDesign::Line')
App.ActiveDocument.addObject('PartDesign::Plane')
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Offsetting sketch to global planes.

Post by edwilliams16 »

I wasn't totally satisfied with the solutions provided, so I wrote a Macro and put it in my Part toolbar. It will create a Sketch attached to a global (XY, YZ, XZ) plane that can then be offset.
Screenshot 2022-12-11 at 2.25.03 PM.png
Screenshot 2022-12-11 at 2.25.03 PM.png (68.03 KiB) Viewed 450 times
Screenshot 2022-12-11 at 2.26.00 PM.png
Screenshot 2022-12-11 at 2.26.00 PM.png (82.75 KiB) Viewed 450 times

Code: Select all

''' Macro to create a sketch attached to a global plane in the root coordinate system
    V0.1  12/11/22 edwilliams16'''

from PySide.QtGui import QWidget, QVBoxLayout, QComboBox, QPushButton, QLabel
from PySide import QtCore

class PlaneChooseWindow(QWidget):
    def __init__(self):
        super(PlaneChooseWindow, self).__init__()

        layout = QVBoxLayout()
        label = QLabel('Attach Plane')
        layout.addWidget(label)

        self.dg = QComboBox()
        self.dg.addItems(['XY', 'YZ', 'XZ'])
        layout.addWidget(self.dg)

        self.ok = QPushButton("OK", self)
        layout.addWidget(self.ok)
        QtCore.QObject.connect(self.ok, QtCore.SIGNAL("pressed()"), self.ok_clicked)
  
        self.cancel = QPushButton("Cancel", self)
        layout.addWidget(self.cancel)
        QtCore.QObject.connect(self.cancel, QtCore.SIGNAL("pressed()"), self.cancel_clicked)
        
        self.setLayout(layout)
        self.show()

    def ok_clicked(self):
        #print("OK Clicked")
        doc = FreeCAD.ActiveDocument
        mapto = self.dg.currentText()
        lcs = doc.addObject('PartDesign::CoordinateSystem')
        lcs.Visibility = False
        sketch = doc.addObject('Sketcher::SketchObject', 'Sketch')
        sketch.MapMode = 'Object' + mapto
        sketch.Support = lcs
        doc.recompute()
        self.close()
    
    def cancel_clicked(self):
        self.close()

mywin = PlaneChooseWindow()




Post Reply