### Install A2plus on Linux Source: https://github.com/kbwbe/a2plus/blob/master/README.md Use the command line to install A2plus on Linux. Ensure FreeCAD and necessary Python libraries are installed beforehand. Use git to easily update the workbench. ```bash $ sudo apt-get install git python-numpy python-pyside $ mkdir ~/.FreeCAD/Mod $ cd ~/.FreeCAD/Mod $ git clone https://github.com/kbwbe/A2plus.git ``` ```bash $ cd ~/.FreeCAD/Mod/A2plus $ git pull $ rm *.pyc ``` -------------------------------- ### Get Current Geometry Selection Source: https://context7.com/kbwbe/a2plus/llms.txt Retrieves the current geometry selection from the GUI, used for validating selections for constraints. ```python import FreeCAD import FreeCADGui import a2plib # Get current selection selection = FreeCADGui.Selection.getSelectionEx()[0] ``` -------------------------------- ### Compile Translations to QM Files Source: https://github.com/kbwbe/a2plus/blob/master/translations/README.md Execute this command in the `A2plus/translations/` directory to convert all `.ts` files into `.qm` files, which are used by the application. ```shell python3 update_ts.py -m ``` -------------------------------- ### Import Part from File Source: https://context7.com/kbwbe/a2plus/llms.txt Use importPartFromFile to load parts into an assembly. Supports importing entire files, specific shapes, and utilizes caching for performance. ```python import FreeCAD import a2p_importpart # Open or create an assembly document doc = FreeCAD.ActiveDocument # Import a complete part from an external FCStd file imported_part = a2p_importpart.importPartFromFile( doc, "/path/to/part.FCStd" ) # Import a specific shape from a multi-body file imported_shape = a2p_importpart.importPartFromFile( doc, "/path/to/multi_body_part.FCStd", extractSingleShape=True, desiredShapeLabel="Body001" ) # Import with caching for batch operations cached_part = a2p_importpart.importPartFromFile( doc, "/path/to/part.FCStd", importToCache=True, cacheKey="unique_cache_key" ) # Access imported part properties print(f"Part name: {imported_part.Name}") print(f"Source file: {imported_part.sourceFile}") print(f"Fixed position: {imported_part.fixedPosition}") print(f"A2plus version: {imported_part.a2p_Version}") ``` -------------------------------- ### Compile Single Language to QM File Source: https://github.com/kbwbe/a2plus/blob/master/translations/README.md Use this command to compile a specific language's `.ts` file into a `.qm` file. This is useful for translators to test their changes locally before submitting a pull request. ```shell lrelease A2plus_it.ts ``` -------------------------------- ### Create New Locale File Source: https://github.com/kbwbe/a2plus/blob/master/translations/README.md Execute this command in the `A2plus/translations/` directory to create a new `.ts` file for a missing locale, containing all translatable strings. ```shell python3 update_ts.py -c ``` -------------------------------- ### Control Transparency and Visualization Source: https://context7.com/kbwbe/a2plus/llms.txt Manage part transparency for visualization during constraint editing. These functions allow temporary transparency to highlight parts and restore original settings. ```python import FreeCAD import a2plib doc = FreeCAD.ActiveDocument # Make all parts transparent for constraint visualization a2plib.setTransparency() # Restore original transparency settings a2plib.restoreTransparency() # Check if transparency mode is active if a2plib.isTransparencyEnabled(): print("Transparency mode is active") # Toggle constraint view mode a2plib.setConstraintViewMode(True) if a2plib.getConstraintViewMode(): print("Constraint view mode is active") ``` -------------------------------- ### Clone A2plus on Windows Source: https://github.com/kbwbe/a2plus/blob/master/README.md If familiar with git, clone the A2plus repository directly into your FreeCAD Mod folder on Windows. Ensure FreeCAD version is 0.16 or higher. ```bash git clone https://github.com/kbwbe/A2plus.git ``` -------------------------------- ### Update All Language Files Source: https://github.com/kbwbe/a2plus/blob/master/translations/README.md Run this command from the `A2plus/translations/` directory to update all existing language `.ts` files based on the latest source code. ```shell python3 update_ts.py -u ``` -------------------------------- ### SolverSystem Class Usage Source: https://context7.com/kbwbe/a2plus/llms.txt Manages the constraint solving process with configurable accuracy. Load constraints, assign parentship, solve with accuracy steps, and access results like max error and status. ```python import FreeCAD import a2p_solversystem doc = FreeCAD.ActiveDocument # Create and configure solver system ss = a2p_solversystem.SolverSystem() # Load the constraint system from document ss.loadSystem(doc) # Assign parent-child relationships between rigids ss.assignParentship(doc) # Solve with accuracy steps (automatic multi-level solving) system_solved = ss.solveAccuracySteps(doc) # Access solver results print(f"Max position error: {ss.maxPosError}") print(f"Max axis error: {ss.maxAxisError}") print(f"Solver status: {ss.status}") # Get DOF information for debugging ss.DOF_info_to_console() # Generate HTML hierarchy visualization ss.visualizeHierarchy() # Creates _asm_hierarchy.html file ``` -------------------------------- ### Manage Assembly File Paths Source: https://context7.com/kbwbe/a2plus/llms.txt Handle file paths within A2plus assemblies, supporting both absolute and relative paths. These functions help locate source files and manage project directory structures. ```python import FreeCAD import a2plib doc = FreeCAD.ActiveDocument assembly_path = "/home/user/projects/assembly" # Find source file in project (handles relative paths) source_path = a2plib.findSourceFileInProject( "./parts/bracket.FCStd", assembly_path ) # Check if file is within project folder if a2plib.checkFileIsInProjectFolder("/home/user/projects/parts/bolt.FCStd"): print("File is in project folder") # Get project folder from preferences project_folder = a2plib.getProjectFolder() # Convert path to OS-specific format os_path = a2plib.pathToOS("./parts/bracket.FCStd") ``` -------------------------------- ### Part Import Functions Source: https://context7.com/kbwbe/a2plus/llms.txt Functions for importing parts from external FreeCAD files into an assembly, with options for caching and updating. ```APIDOC ## importPartFromFile ### Description Imports parts from external FreeCAD files into an assembly. Can handle complete files or single shapes, with optional caching. ### Method Python function call ### Endpoint N/A (Python function) ### Parameters - **doc** (Document) - Required - The FreeCAD document to import into. - **filePath** (string) - Required - The path to the external FreeCAD file. - **extractSingleShape** (bool) - Optional - If True, extracts a single shape from a multi-body file. - **desiredShapeLabel** (string) - Optional - The label of the shape to extract if `extractSingleShape` is True. - **importToCache** (bool) - Optional - If True, imports the part to a cache for potential reuse. - **cacheKey** (string) - Optional - A unique key for the cached part if `importToCache` is True. ### Request Example ```python import FreeCAD import a2p_importpart doc = FreeCAD.ActiveDocument # Import a complete part imported_part = a2p_importpart.importPartFromFile( doc, "/path/to/part.FCStd" ) # Import a specific shape from a multi-body file imported_shape = a2p_importpart.importPartFromFile( doc, "/path/to/multi_body_part.FCStd", extractSingleShape=True, desiredShapeLabel="Body001" ) # Import with caching cached_part = a2p_importpart.importPartFromFile( doc, "/path/to/part.FCStd", importToCache=True, cacheKey="unique_cache_key" ) ``` ### Response #### Success Response (Part Object) - **Name** (string) - The name of the imported part object in the FreeCAD document. - **sourceFile** (string) - The path to the original source file. - **fixedPosition** (bool) - Indicates if the part's position is fixed. - **a2p_Version** (string) - The version of A2plus used for import. #### Response Example ```json { "Name": "Part001", "sourceFile": "/path/to/part.FCStd", "fixedPosition": false, "a2p_Version": "1.0.0" } ``` ``` ```APIDOC ## updateImportedParts ### Description Updates imported parts in the assembly. Can update all parts or only selected ones if their source files have changed. ### Method Python function call ### Endpoint N/A (Python function) ### Parameters - **doc** (Document) - Required - The FreeCAD document containing the assembly. - **partial** (bool) - Optional - If True, only updates selected parts. Defaults to False (updates all). ### Request Example ```python import FreeCAD import FreeCADGui import a2p_importpart doc = FreeCAD.ActiveDocument # Update all imported parts a2p_importpart.updateImportedParts(doc) # Update only selected parts (ensure parts are selected in GUI first) a2p_importpart.updateImportedParts(doc, partial=True) ``` ### Response #### Success Response (None) This function does not return a value upon success. #### Response Example (No response body) ``` ```APIDOC ## duplicateImportedPart ### Description Creates a duplicate of an existing imported part within the same assembly. ### Method Python function call ### Endpoint N/A (Python function) ### Parameters - **original_part** (Part Object) - Required - The A2plus part object to duplicate. ### Request Example ```python import FreeCAD import a2p_importpart doc = FreeCAD.ActiveDocument # Get an existing imported part original_part = doc.getObject("Part001") # Create a duplicate duplicate = a2p_importpart.duplicateImportedPart(original_part) # Optionally modify the duplicate's placement duplicate.Placement.Base = FreeCAD.Vector(100, 0, 0) ``` ### Response #### Success Response (Part Object) - **Name** (string) - The name of the newly created duplicate part object. - **Placement** (Placement) - The placement of the duplicate part. #### Response Example ```json { "Name": "Part002", "Placement": { "Base": [100, 0, 0], "Rotation": [0, 0, 0, 1] } } ``` ``` -------------------------------- ### SolverSystem Class Source: https://context7.com/kbwbe/a2plus/llms.txt The core solver class that manages the constraint solving process with configurable accuracy levels. ```APIDOC ## SolverSystem Class ### Description The core solver class that manages the constraint solving process with configurable accuracy levels. ### Method ```python import FreeCAD import a2p_solversystem doc = FreeCAD.ActiveDocument # Create and configure solver system ss = a2p_solversystem.SolverSystem() # Load the constraint system from document ss.loadSystem(doc) # Assign parent-child relationships between rigids ss.assignParentship(doc) # Solve with accuracy steps (automatic multi-level solving) system_solved = ss.solveAccuracySteps(doc) # Access solver results print(f"Max position error: {ss.maxPosError}") print(f"Max axis error: {ss.maxAxisError}") print(f"Solver status: {ss.status}") # Get DOF information for debugging ss.DOF_info_to_console() # Generate HTML hierarchy visualization ss.visualizeHierarchy() # Creates _asm_hierarchy.html file ``` ``` -------------------------------- ### autoSolveConstraints Source: https://context7.com/kbwbe/a2plus/llms.txt Automatically solves constraints when auto-solve mode is enabled in preferences. ```APIDOC ## autoSolveConstraints ### Description Automatically solves constraints when auto-solve mode is enabled in preferences. ### Method ```python import FreeCAD import a2p_solversystem import a2plib doc = FreeCAD.ActiveDocument # Check if auto-solve is enabled if a2plib.getAutoSolveState(): print("Auto-solve is enabled") # Enable/disable auto-solve a2plib.setAutoSolve(True) # Trigger auto-solve after a constraint operation a2p_solversystem.autoSolveConstraints( doc, callingFuncName="myConstraintFunction" ) ``` ``` -------------------------------- ### Solve All Constraints in Document Source: https://context7.com/kbwbe/a2plus/llms.txt Solves all constraints in the active document using an iterative algorithm. Can be used with transactions for undo support, with a specific list of constraints, or to suppress failure messages. ```python import FreeCAD import a2p_solversystem doc = FreeCAD.ActiveDocument # Solve all constraints in the document result = a2p_solversystem.solveConstraints(doc) if result: print("Assembly solved successfully") else: print("Could not solve assembly - check for constraint conflicts") # Solve with transaction for undo support a2p_solversystem.solveConstraints(doc, useTransaction=True) # Solve specific constraints only (matelist) constraints = [doc.getObject("pointIdentity_001"), doc.getObject("plane_001")] a2p_solversystem.solveConstraints(doc, matelist=constraints) # Suppress failure message for automated solving a2p_solversystem.solveConstraints(doc, showFailMessage=False) ``` -------------------------------- ### Point Identity Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Create a point-to-point constraint between vertices, circle centers, or sphere centers. Requires a valid selection of two elements in the GUI. ```python import FreeCAD import FreeCADGui import a2p_constraints # Select two vertices/circles/spheres in the GUI first # Selection example: Part1.Vertex1 and Part2.Vertex3 selection = FreeCADGui.Selection.getSelectionEx() # Validate selection before creating constraint if a2p_constraints.PointIdentityConstraint.isValidSelection(selection): constraint = a2p_constraints.PointIdentityConstraint(selection) print(f"Created constraint: {constraint.constraintObject.Name}") print(f"Object1: {constraint.ob1Name}, SubElement: {constraint.sub1}") print(f"Object2: {constraint.ob2Name}, SubElement: {constraint.sub2}") ``` -------------------------------- ### Constraint System Source: https://context7.com/kbwbe/a2plus/llms.txt Functions for creating various geometric constraints between parts in an assembly. ```APIDOC ## Point Identity Constraint ### Description Constrains two points (vertices, circle centers, sphere centers) to be coincident. ### Method Python function call ### Endpoint N/A (Python function) ### Parameters - **selection** (list) - Required - A list containing the two selected geometric elements (e.g., vertices, circle centers). ### Request Example ```python import FreeCAD import FreeCADGui import a2p_constraints # Ensure two points are selected in the GUI selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.PointIdentityConstraint.isValidSelection(selection): constraint = a2p_constraints.PointIdentityConstraint(selection) print(f"Created constraint: {constraint.constraintObject.Name}") print(f"Object1: {constraint.ob1Name}, SubElement: {constraint.sub1}") print(f"Object2: {constraint.ob2Name}, SubElement: {constraint.sub2}") ``` ### Response #### Success Response (Constraint Object) - **constraintObject** (Object) - The underlying FreeCAD constraint object. - **ob1Name** (string) - Name of the first object involved in the constraint. - **sub1** (string) - Identifier of the sub-element on the first object. - **ob2Name** (string) - Name of the second object involved in the constraint. - **sub2** (string) - Identifier of the sub-element on the second object. #### Response Example ```json { "constraintObject": "PointConstraint_001", "ob1Name": "Part1", "sub1": "Vertex1", "ob2Name": "Part2", "sub2": "Vertex3" } ``` ``` ```APIDOC ## Plane Coincident Constraint ### Description Constrains two planar faces to be coplanar. An optional offset distance and direction can be specified. ### Method Python function call ### Endpoint N/A (Python function) ### Parameters - **selection** (list) - Required - A list containing the two selected planar faces. ### Request Example ```python import FreeCAD import FreeCADGui import a2p_constraints # Ensure two plane faces are selected in the GUI selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.PlaneConstraint.isValidSelection(selection): constraint = a2p_constraints.PlaneConstraint(selection) # Access and modify constraint properties c = constraint.constraintObject c.offset = 10.0 # Set a 10mm offset c.directionConstraint = "opposed" # Faces point in opposite directions ``` ### Response #### Success Response (Constraint Object) - **constraintObject** (Object) - The underlying FreeCAD constraint object. #### Response Example ```json { "constraintObject": "PlaneConstraint_001" } ``` ``` ```APIDOC ## Circular Edge Constraint ### Description Aligns two circular edges (e.g., holes, cylinders) to be concentric. An optional offset along the axis can be applied. ### Method Python function call ### Endpoint N/A (Python function) ### Parameters - **selection** (list) - Required - A list containing the two selected circular edges. ### Request Example ```python import FreeCAD import FreeCADGui import a2p_constraints # Ensure two circular edges are selected in the GUI selection = FreeCADGui.Selection.getSelectionEx() # Assuming a2p_constraints.CircularEdgeConstraint exists and has a isValidSelection method # if a2p_constraints.CircularEdgeConstraint.isValidSelection(selection): # constraint = a2p_constraints.CircularEdgeConstraint(selection) # print(f"Created circular edge constraint: {constraint.constraintObject.Name}") ``` ### Response #### Success Response (Constraint Object) - **constraintObject** (Object) - The underlying FreeCAD constraint object. #### Response Example ```json { "constraintObject": "CircularEdgeConstraint_001" } ``` ``` -------------------------------- ### Part Detection Functions Source: https://context7.com/kbwbe/a2plus/llms.txt Helper functions for identifying A2plus objects in a document. ```APIDOC ## Part Detection Functions ### Description Helper functions for identifying A2plus objects in a document. ### Method ```python import FreeCAD import a2plib doc = FreeCAD.ActiveDocument # Check if an object is an A2plus imported part obj = doc.getObject("Part001") if a2plib.isA2pPart(obj): print(f"{obj.Label} is an A2plus part") # Check if object is an A2plus constraint constraint = doc.getObject("pointIdentity_001") if a2plib.isA2pConstraint(constraint): print(f"{constraint.Label} is a constraint") # Check if part is editable (has source file) if a2plib.isEditableA2pPart(obj): print(f"Source file: {obj.sourceFile}") # Check if part has constraints attached if a2plib.isConstrainedPart(doc, obj): print(f"{obj.Label} is constrained") # Filter objects with shapes (exclude spreadsheets, etc.) shaped_objects = a2plib.filterShapeObs(doc.Objects) ``` ``` -------------------------------- ### Geometry Selection Helpers Source: https://context7.com/kbwbe/a2plus/llms.txt Functions for validating geometry selections for constraints. ```APIDOC ## Geometry Selection Helpers ### Description Functions for validating geometry selections for constraints. ### Method ```python import FreeCAD import FreeCADGui import a2plib # Get current selection selection = FreeCADGui.Selection.getSelectionEx()[0] ``` ``` -------------------------------- ### solveConstraints Source: https://context7.com/kbwbe/a2plus/llms.txt The main solver function that resolves all constraints in an assembly using an iterative physics-inspired algorithm. ```APIDOC ## solveConstraints ### Description The main solver function that resolves all constraints in an assembly using an iterative physics-inspired algorithm. ### Method ```python import FreeCAD import a2p_solversystem doc = FreeCAD.ActiveDocument # Solve all constraints in the document result = a2p_solversystem.solveConstraints(doc) if result: print("Assembly solved successfully") else: print("Could not solve assembly - check for constraint conflicts") # Solve with transaction for undo support a2p_solversystem.solveConstraints(doc, useTransaction=True) # Solve specific constraints only (matelist) constraints = [doc.getObject("pointIdentity_001"), doc.getObject("plane_001")] a2p_solversystem.solveConstraints(doc, matelist=constraints) # Suppress failure message for automated solving a2p_solversystem.solveConstraints(doc, showFailMessage=False) ``` ``` -------------------------------- ### Auto-Solve Constraints Source: https://context7.com/kbwbe/a2plus/llms.txt Manages and triggers automatic constraint solving. Check the current auto-solve state, enable/disable it, or trigger it after a constraint operation. ```python import FreeCAD import a2p_solversystem import a2plib doc = FreeCAD.ActiveDocument # Check if auto-solve is enabled if a2plib.getAutoSolveState(): print("Auto-solve is enabled") # Enable/disable auto-solve a2plib.setAutoSolve(True) # Trigger auto-solve after a constraint operation a2p_solversystem.autoSolveConstraints( doc, callingFuncName="myConstraintFunction" ) ``` -------------------------------- ### Generate Bill of Materials Source: https://context7.com/kbwbe/a2plus/llms.txt A2plus provides functionality to generate Bills of Materials (BOM) for assemblies using the a2p_BoM module. This is typically accessed via GUI commands. ```python import FreeCAD import a2p_BoM doc = FreeCAD.ActiveDocument # The BoM functionality is accessed via GUI commands: # - a2p_CreatePartlist: Creates a spreadsheet with part information # - a2p_CreateCutListOptimizerPartlist: Creates optimized cut list ``` -------------------------------- ### Duplicate Imported Part Source: https://context7.com/kbwbe/a2plus/llms.txt Create a duplicate of an existing imported part using duplicateImportedPart. The duplicate shares the source file but has its own placement. ```python import FreeCAD import a2p_importpart doc = FreeCAD.ActiveDocument # Get an existing imported part original_part = doc.getObject("Part001") # Create a duplicate duplicate = a2p_importpart.duplicateImportedPart(original_part) # The duplicate has its own placement but shares source file reference duplicate.Placement.Base = FreeCAD.Vector(100, 0, 0) ``` -------------------------------- ### Generate Translation File with pylupdate6 Source: https://github.com/kbwbe/a2plus/blob/master/translations/README.md Use this command to generate or update a `.ts` translation file for a specific locale, scanning Python source files. Ensure you are in the `A2plus/translations/` directory. ```shell pylupdate6 --verbose ../*.py --ts A2plus_it.ts ``` -------------------------------- ### Create Angled Planes Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Constrains two planes to meet at a specified angle. Requires selection of two plane faces. ```python import FreeCAD import FreeCADGui import a2p_constraints # Select two plane faces selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.AngledPlanesConstraint.isValidSelection(selection): constraint = a2p_constraints.AngledPlanesConstraint(selection) c = constraint.constraintObject c.angle = 45.0 # Set 45 degree angle between planes ``` -------------------------------- ### Check Selection Type for Constraint Validity Source: https://context7.com/kbwbe/a2plus/llms.txt Use these functions to determine the type of element selected in the FreeCAD model, which is crucial for validating constraint applicability. ```python if a2plib.vertexSelected(selection): print("Vertex selected") ``` ```python if a2plib.planeSelected(selection): print("Plane face selected") ``` ```python if a2plib.CircularEdgeSelected(selection): print("Circular edge selected") ``` ```python if a2plib.LinearEdgeSelected(selection): print("Linear edge selected") ``` ```python if a2plib.cylindricalFaceSelected(selection): print("Cylindrical face selected") ``` ```python if a2plib.sphericalSurfaceSelected(selection): print("Spherical surface selected") ``` -------------------------------- ### Create Circular Edge Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Use this to create a constraint between two circular edges. Configure offset, direction, and rotation lock. ```python import FreeCAD import FreeCADGui import a2p_constraints selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.CircularEdgeConstraint.isValidSelection(selection): constraint = a2p_constraints.CircularEdgeConstraint(selection) # Configure constraint properties c = constraint.constraintObject c.offset = 5.0 # Offset along the axis c.directionConstraint = "aligned" # Axes point same direction c.lockRotation = True # Lock rotation around the axis ``` -------------------------------- ### Create Simple Assembly Shape Source: https://context7.com/kbwbe/a2plus/llms.txt Generate a single fused shape from all parts in an A2plus assembly. This is useful for export or visualization purposes and is typically invoked via a GUI command. ```python import FreeCAD import FreeCADGui doc = FreeCAD.ActiveDocument # Use GUI command to create simple assembly shape # Command: a2p_SimpleAssemblyShapeCommand # This creates a single Part::Feature named "SimpleAssemblyShape" ``` -------------------------------- ### Extract Position and Axis from Sub-elements Source: https://context7.com/kbwbe/a2plus/llms.txt Extract geometric information such as position and axis direction from selected FreeCAD sub-elements. Ensure the FreeCAD document and object are properly loaded. ```python import FreeCAD import a2plib doc = FreeCAD.ActiveDocument obj = doc.getObject("Part001") # Get position from a subelement pos = a2plib.getPos(obj, "Face1") print(f"Face center: {pos}") pos = a2plib.getPos(obj, "Edge5") print(f"Edge reference point: {pos}") pos = a2plib.getPos(obj, "Vertex2") print(f"Vertex position: {pos}") # Get axis direction from a subelement axis = a2plib.getAxis(obj, "Face1") # Plane normal print(f"Face normal: {axis}") axis = a2plib.getAxis(obj, "Edge3") # Edge direction or circle axis print(f"Edge axis: {axis}") ``` -------------------------------- ### Check A2plus Part Type Source: https://context7.com/kbwbe/a2plus/llms.txt Helper functions to identify A2plus objects in a document. Check if an object is an A2plus part, constraint, editable part, or a constrained part. ```python import FreeCAD import a2plib doc = FreeCAD.ActiveDocument # Check if an object is an A2plus imported part obj = doc.getObject("Part001") if a2plib.isA2pPart(obj): print(f"{obj.Label} is an A2plus part") # Check if object is an A2plus constraint constraint = doc.getObject("pointIdentity_001") if a2plib.isA2pConstraint(constraint): print(f"{constraint.Label} is a constraint") # Check if part is editable (has source file) if a2plib.isEditableA2pPart(obj): print(f"Source file: {obj.sourceFile}") # Check if part has constraints attached if a2plib.isConstrainedPart(doc, obj): print(f"{obj.Label} is constrained") # Filter objects with shapes (exclude spreadsheets, etc.) shaped_objects = a2plib.filterShapeObs(doc.Objects) ``` -------------------------------- ### Update Imported Parts Source: https://context7.com/kbwbe/a2plus/llms.txt Use updateImportedParts to refresh parts in the assembly if their source files have changed. Can update all parts or only selected ones. ```python import FreeCAD import FreeCADGui import a2p_importpart doc = FreeCAD.ActiveDocument # Update all imported parts in the assembly a2p_importpart.updateImportedParts(doc) # Update only selected parts # First select parts in the GUI, then: a2p_importpart.updateImportedParts(doc, partial=True) ``` -------------------------------- ### Plane Coincident Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Constrain two planar faces to be coplanar, with an optional offset and direction. Requires selecting two plane faces in the GUI. ```python import FreeCAD import FreeCADGui import a2p_constraints # Select two plane faces in the GUI selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.PlaneConstraint.isValidSelection(selection): constraint = a2p_constraints.PlaneConstraint(selection) # Access constraint object to modify offset c = constraint.constraintObject c.offset = 10.0 # Set 10mm offset between planes c.directionConstraint = "opposed" # Faces point in opposite directions ``` -------------------------------- ### Flip Constraint Direction Source: https://context7.com/kbwbe/a2plus/llms.txt Toggle the direction of directional constraints in A2plus assemblies. This can be done by flipping the last created constraint or by manually modifying the constraint's direction property. ```python import FreeCAD import a2p_importpart # Flip direction of the last created constraint a2p_importpart.a2p_FlipConstraintDirection() # Or manually access constraint direction doc = FreeCAD.ActiveDocument constraint = doc.getObject("plane_001") if hasattr(constraint, "directionConstraint"): if constraint.directionConstraint == "aligned": constraint.directionConstraint = "opposed" else: constraint.directionConstraint = "aligned" ``` -------------------------------- ### Remove Assembly Constraints Source: https://context7.com/kbwbe/a2plus/llms.txt Functions for removing constraints from A2plus assemblies. This includes removing specific constraints, cleaning up constraints of deleted objects, and repairing the assembly's tree view. ```python import FreeCAD import a2plib doc = FreeCAD.ActiveDocument # Remove a specific constraint constraint = doc.getObject("pointIdentity_001") a2plib.removeConstraint(constraint) # Clean up constraints of deleted objects a2plib.deleteConstraintsOfDeletedObjects() # Repair tree view (regroup constraints under parent parts) a2plib.a2p_repairTreeView() ``` -------------------------------- ### Circular Edge Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Aligns two circular edges concentrically, with an optional offset along the axis. Requires selecting two circular edges in the GUI. ```python import FreeCAD import FreeCADGui import a2p_constraints ``` -------------------------------- ### Angled Planes Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Constrains two planes to meet at a specified angle. ```APIDOC ## Angled Planes Constraint ### Description Constrains two planes to meet at a specified angle. ### Method ```python import FreeCAD import FreeCADGui import a2p_constraints # Select two plane faces selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.AngledPlanesConstraint.isValidSelection(selection): constraint = a2p_constraints.AngledPlanesConstraint(selection) c = constraint.constraintObject c.angle = 45.0 # Set 45 degree angle between planes ``` ``` -------------------------------- ### Create Axial Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Constrains two axis-defining elements to be coaxial. Supports 'aligned' or 'opposed' direction constraints and rotation locking. ```python import FreeCAD import FreeCADGui import a2p_constraints # Select cylindrical faces or linear edges selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.AxialConstraint.isValidSelection(selection): constraint = a2p_constraints.AxialConstraint(selection) c = constraint.constraintObject c.directionConstraint = "aligned" # or "opposed" c.lockRotation = False # Allow rotation around axis ``` -------------------------------- ### Circular Edge Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Constrains two circular edges to be coincident, with options for offset and direction. ```APIDOC ## Circular Edge Constraint ### Description Constrains two circular edges to be coincident, with options for offset and direction. ### Method ```python import FreeCAD import FreeCADGui import a2p_constraints # Select two circular edges in the GUI selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.CircularEdgeConstraint.isValidSelection(selection): constraint = a2p_constraints.CircularEdgeConstraint(selection) # Configure constraint properties c = constraint.constraintObject c.offset = 5.0 # Offset along the axis c.directionConstraint = "aligned" # Axes point same direction c.lockRotation = True # Lock rotation around the axis ``` ``` -------------------------------- ### Axial Constraint Source: https://context7.com/kbwbe/a2plus/llms.txt Constrains two axis-defining elements (edges, cylindrical faces) to be coaxial. ```APIDOC ## Axial Constraint ### Description Constrains two axis-defining elements (edges, cylindrical faces) to be coaxial. ### Method ```python import FreeCAD import FreeCADGui import a2p_constraints # Select cylindrical faces or linear edges selection = FreeCADGui.Selection.getSelectionEx() if a2p_constraints.AxialConstraint.isValidSelection(selection): constraint = a2p_constraints.AxialConstraint(selection) c = constraint.constraintObject c.directionConstraint = "aligned" # or "opposed" c.lockRotation = False # Allow rotation around axis ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.