Macro Express Placement: Difference between revisions
Screeneroner (talk | contribs) m (Removed unnecessary lines on top of the script) |
Screeneroner (talk | contribs) (Removed <nowiki> tag) |
||
Line 66: | Line 66: | ||
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-codeBlock"> |
<div class="mw-collapsible mw-collapsed" id="mw-customcollapsible-codeBlock"> |
||
{{MacroCode|code= |
{{MacroCode|code= |
||
<nowiki> |
|||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||
__Name__ = "Express Placement" |
__Name__ = "Express Placement" |
||
Line 81: | Line 80: | ||
__Requires__ = "FreeCAD >= 0.19" |
__Requires__ = "FreeCAD >= 0.19" |
||
__Communication__ = "https://forum.freecad.org/memberlist.php?mode=viewprofile&u=60629" |
__Communication__ = "https://forum.freecad.org/memberlist.php?mode=viewprofile&u=60629" |
||
#20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC) |
|||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|||
import FreeCADGui as Gui |
import FreeCADGui as Gui |
||
Line 298: | Line 297: | ||
# Create and display the table |
# Create and display the table |
||
create_table() |
create_table() |
||
</nowiki> |
|||
}} |
}} |
||
</div> |
</div> |
Revision as of 20:40, 23 September 2023
Description |
---|
Display and quickly edit selected object placement coordinates directly or via expressions. Macro version: 1.0 Last modified: 2023-08-01 FreeCAD version: created and tested in 0.21 Download: [1] Author: screeneroner |
Author |
screeneroner |
Download |
[2] |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.0 |
Date last modified |
2023-08-01 |
FreeCAD Version(s) |
created and tested in 0.21 |
Default shortcut |
None |
See also |
None |
Description
Express Placement is a FreeCAD GUI addon. It allows quick editing of the X, Y, Z placement coordinates for the currently selected object.
Difference and benefits
One double click to edit object placement instead of four sequential clicks - you may work 4 times faster!
Standard FreeCAD Placement (in red)
The standard FreeCAD built-in editor requires many additional mouse clicks before you actually start parameter editing, especially when using parametric expressions to position your object:
- Click on the Base/Placement item in the Property view to unfold the Placement tree.
- Click on the Position branch to unfold the X, Y, Z coordinates fields.
- Click on the desired coordinate to make the expression editing icon visible.
- Click the expression editing icon, which is so small that it may be a challenge to hit it.
Alternatively, press the "=" key on the keyboard. This may take even longer than clicking the icon.
You must repeat these clicks when you select another object. Again and again...
Express Placement (in green)
The Express Placement macro creates a special panel for you. You may dock this panel to any suitable place. It shows three rows with X, Y, Z coordinates. These coordinates contain values and expression fields. They are available for editing with just one double click.
Installation
Addon Manager
Find Express Placement in FreeCAD Addon Manager and install it.
Direct Launch of Express Placement
You may download and use Express Placement addon immediately in your FreeCAD:
- Download the express-placement.FCMacro file and place it in the User Macros folder inside your FreeCAD installation folder.
- Execute it directly from the FreeCAD main menu Macro / Macros / User Macros.
Installing Express Placement Toolbar Button
To have an ability to quickly switch on the Express Placement table, you may place a button to quickly execute this macro and bring up the Express Placement table:
- Download the Express Placement.FCMacro file and place it in the User Macros folder inside your FreeCAD installation folder.
- Select the Express Placement macro in the User Macros panel, invoked from the FreeCAD main menu Macro / Macros / User Macros.
- Press the Toolbar button and follow the Walkthrough dialog to place the Express Placement button in the desired location in the FreeCAD toolbars.
Usage
Just run the Express Placement macro directly or via the toolbar button, and you will see a new docked property window in your FreeCAD UI. You may drag it to any allowed place in the UI and close any time you won't need it. Next time when it will be required again - run the macro or press the toolbar button again to bring up the Express Placement window.
When you decide to change the placement of the selected object, just double-click on the desired cell in the Express Placement window and type a new value or edit the existing one. The new value will be directly written to your model.
If you find this add-on useful and feel it's worth treating me to a couple-triple coffee cups in recognition of my work, at any time you may do it via ☕ Buy me a coffee
Script
Click here to show/hide the Addon source code.
# -*- coding: utf-8 -*- __Name__ = "Express Placement" __Comment__ = "FreeCAD GUI addon that allow quick editing X,Y,Z coordinates of the selected object" __Author__ = "screeneroner" __Version__ = "1.0" __Date__ = "2023-08-01" __License__ = "GPL-3.0" __Web__ = "https://wiki.freecad.org/Macro_Express_Placement" __Wiki__ = "https://wiki.freecad.org/Macro_Express_Placement" __Icon__ = "https://wiki.freecad.org/images/8/8f/Std_AxisCross_example.svg" __Help__ = "Display and quickly edit selected object placement coordinates directly or via expressions" __Status__ = "Working" __Requires__ = "FreeCAD >= 0.19" __Communication__ = "https://forum.freecad.org/memberlist.php?mode=viewprofile&u=60629" #20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC)20:40, 23 September 2023 (UTC) import FreeCADGui as Gui import FreeCAD as App from PySide import QtGui, QtCore # Define a function to create and display a table def create_table(): # Function to update the table with the selected object's data def update_table_with_selected_object(): # Clear the table first clear_table() # Get the selected objects selection = Gui.Selection.getSelection() # If there's exactly one selected object if len(selection) == 1: selected_obj = selection[0] selected_object = selected_obj # Ensure the object isn't a spreadsheet if str(selected_obj.TypeId) != "Spreadsheet::Sheet": # Populate the table with the object's placement data populate_table_with_placement(selected_obj) # Store the selected object on the table widget table_widget.selected_object = selected_obj # Function to populate the table with an object's placement data def populate_table_with_placement(selected_obj): # Clear the table first clear_table() # Get the object's placement placement = selected_obj.Placement # Update each row of the table with the object's placement data for row in range(3): # Limit to 3 instead of row_count value_widget = QtGui.QTableWidgetItem() value_widget.setText(str(getattr(placement.Base, ["x", "y", "z"][row]))) table_widget.setItem(row, 0, value_widget) # Get the object's properties properties_list = selected_obj.ExpressionEngine # If the object has properties if properties_list is not None: # For each property that involves placement for prop in properties_list: if prop[0] in [".Placement.Base.x", ".Placement.Base.y", ".Placement.Base.z"]: # Get the attribute's name attribute = prop[0].split(".")[-1] # Set the corresponding cell's value expression_label = QtGui.QTableWidgetItem() expression_label.setText(prop[1]) table_widget.setItem(["x", "y", "z"].index(attribute), 1, expression_label) # Add the new row with the support data support_label_widget = QtGui.QLabel(" ") support_link_widget = QtGui.QLabel( u'\u2615' + ' <a href="https://www.buymeacoffee.com/screeneroner">Buy me a coffee</a> ') support_link_widget.setAlignment(QtCore.Qt.AlignRight