Regular Cycles LLC +1 (651) 424-8555
Custom carbon fiber bicycle parts made in Minnesota
Fast toggling the visibility of non-datum constraints in FreeCAD 1.0
Inspired by this Reddit post on the topic, in FreeCAD 1.0 it would be pretty nice if a person could swiftly hide (and show) all non-datum constraints -- just the geometrical stuff is of interest here.
So I wrote a little Python macro that does, which took more time to document than it took time to write. You can bind it to a custom macro and subsequent hotkey of your choosing.
Here's what you should approximately expect to see once you have added the macro to your system:
Here's the Python code, you'll have to select it in the conventional way as there is no JS on this page:
import FreeCAD,Part import FreeCADGui as Gui from PySide import QtGui # clear the report view # you can remove the hash comment symbols from the 5 lines following this line if you want the Report View to clear out upon running this macro #clear_console = True # or False #if (clear_console == True): # mw=Gui.getMainWindow() # r=mw.findChild(QtGui.QTextEdit, "Report view") # r.clear() doc = Gui.ActiveDocument editing_view = doc.getInEdit() if editing_view == None: print("oh dang, there is not an active Sketch edit in view - switch to editing a Sketch before running ToggleAllNonDatumConstraintsToOtherWorkspace.py") pass else: obj = editing_view.Object if obj.TypeId == "Sketcher::SketchObject": constraints = obj.Constraints non_datum_constraints = [] #print(constraints) for index, this_con in enumerate(constraints): #print(this_con.Type) if this_con.Type == "Coincident": #print("no op on Coincident type Constraints") pass elif this_con.Type in ["PointOnObject", "Horizontal", "Vertical", "Tangent", "Parallel", "Perpendicular", "Equal", "Symmetric", "Block"]: #print(this_con.Type, "is a non-datum constraint") non_datum_constraints.append([this_con, index]) else: if this_con.Name != "": #print(this_con.Type, "is a datum constraint maybe <-------------- named '", this_con.Name, "'") pass else: #print(this_con.Type, "is a datum constraint maybe <--------------") pass #print(non_datum_constraints) constraint_indexes = [] already_in_virtual_space = [] for index, this_con in enumerate(non_datum_constraints): constraint_indexes.append(this_con) con_object = this_con[0] if con_object.InVirtualSpace == True: #print("in virtual space", index) already_in_virtual_space.append(this_con) print(len(non_datum_constraints), " non-datum sketch constraints matched") if len(non_datum_constraints) == len(already_in_virtual_space): set_all_to_virtual_space = False print("all non-datum constraints are already in the virtual space, switching them back to main space") else: set_all_to_virtual_space = True print("zero or some non-datum constraints have not yet made it to the virtual space, putting them there") for this_con in constraint_indexes: con_object = this_con[0] con_index_within_all_constraints = this_con[1] #print("setVirtualSpace", con_index_within_all_constraints, set_all_to_virtual_space) obj.setVirtualSpace(con_index_within_all_constraints, set_all_to_virtual_space)
If you are interested in the future of stepless gearbox technology and would like to follow along for follow updates, here is my Patreon link. You don't have to donate to subscribe.
Hope to hear from you.
Phone: +1 (651) 424-8555
Email: