├── CameraAnimation.py ├── EAInit.py ├── ExplodedAssembly.py ├── InitGui.py ├── LICENSE ├── README.md ├── example.fcstd └── icons ├── AlignToEdge.svg ├── AnimationCamera.svg ├── AnimationCameraEdge.svg ├── AnimationCameraFollow.svg ├── AnimationCameraManual.svg ├── BoltGroup.svg ├── ExplodeToSelection.svg ├── GoToEnd.svg ├── GoToStart.svg ├── ModifyIndividualObjectTrajectory.svg ├── Pause.svg ├── PlaceBeforeTrajectory.svg ├── PlayBackward.svg ├── PlayForward.svg ├── Rotate90.svg ├── ShareCenter.svg ├── SharePoint.svg ├── SimpleGroup.svg ├── TrajectoryEdit.svg ├── TrajectoryLineVisibility.svg ├── WireTrajectory.svg └── WorkbenchIcon.svg /CameraAnimation.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Exploded Assembly Animation workbench for FreeCAD 3 | # (c) 2016 Javier Martínez García 4 | #*************************************************************************** 5 | #* (c) Javier Martínez García 2016 * 6 | #* * 7 | #* This program is free software; you can redistribute it and/or modify * 8 | #* it under the terms of the GNU General Public License (GPL) * 9 | #* as published by the Free Software Foundation; either version 2 of * 10 | #* the License, or (at your option) any later version. * 11 | #* for detail see the LICENCE text file. * 12 | #* * 13 | #* This program is distributed in the hope that it will be useful, * 14 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 | #* GNU Lesser General Public License for more details. * 17 | #* * 18 | #* You should have received a copy of the GNU Library General Public * 19 | #* License along with FreeCAD; if not, write to the Free Software * 20 | #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * 21 | #* USA * 22 | #* * 23 | #***************************************************************************/ 24 | 25 | from __future__ import division 26 | import os 27 | import time 28 | import FreeCAD 29 | import Part 30 | from pivy import coin 31 | 32 | 33 | 34 | """ 35 | class AnimationCamera: 36 | def __init__(self, obj): 37 | obj.addProperty('App::PropertyBool', 'Enable') 38 | obj.addProperty('App::PropertyString', 'RunFrom', 'Interval') 39 | obj.addProperty('App::PropertyString', 'RunTo', 'Interval') 40 | # edge trajectory 41 | obj.addProperty('App::PropertyBool', 'EdgeTrajectory', 'Follow Edge') 42 | obj.addProperty('App::PropertyString','ShapeName', 'Follow Edge') 43 | obj.addProperty('App::PropertyFloat', 'EdgeNumber', 'Follow Edge') 44 | # Manual trajectory 45 | obj.addProperty('App::PropertyBool', 'ManualTrajectory', 'Manual trajectory') 46 | obj.addProperty('App::PropertyVector', 'InitialCameraBase', 'Manual trajectory') 47 | obj.addProperty('App::PropertyVector', 'InitialCameraLookPoint', 'Manual trajectory') 48 | obj.addProperty('App::PropertyVector', 'FinalCameraBase', 'Manual trajectory') 49 | obj.addProperty('App::PropertyVector', 'FinalCameraLookPoint', 'Manual trajectory') 50 | obj.addProperty('App::PropertyStringList', 'TransitionMode', 'Manual trajectory').TransitionMode = 'Frame', 'Smooth' 51 | # Attached trajectory 52 | obj.addPropertyd 53 | 54 | """ 55 | class ManualAnimationCamera: 56 | def __init__(self, obj): 57 | obj.addProperty('App::PropertyBool', 'Enable', 'Enable Camera') 58 | obj.addProperty('App::PropertyString', 'RunFrom', 'Interval') 59 | obj.addProperty('App::PropertyString', 'RunTo', 'Interval') 60 | obj.addProperty('App::PropertyVector', 'InitialCameraBase', 'Camera Position') 61 | obj.addProperty('App::PropertyVector', 'FinalCameraBase', 'Camera Position') 62 | obj.addProperty('App::PropertyVector', 'InitialCameraLookPoint', 'Camera Position') 63 | obj.addProperty('App::PropertyVector', 'FinalCameraLookPoint', 'Camera Position') 64 | obj.addProperty('App::PropertyEnumeration', 'Transition', 'Camera Transition').Transition = ['Sudden', 'Linear'] 65 | 66 | 67 | class ManualAnimationCameraViewProvider: 68 | def __init__(self, obj): 69 | obj.Proxy = self 70 | 71 | def getIcon(self): 72 | __dir__ = os.path.dirname(__file__) 73 | return __dir__ + '/icons/AnimationCameraManual.svg' 74 | 75 | 76 | def createManualCamera(): 77 | # retrieve selection 78 | initial_obj = FreeCAD.Gui.Selection.getSelectionEx()[0].Object.Name 79 | final_obj = FreeCAD.Gui.Selection.getSelectionEx()[1].Object.Name 80 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly 81 | MCObj = FreeCAD.ActiveDocument.addObject('App::FeaturePython', 'ManualCamera') 82 | ManualAnimationCamera(MCObj) 83 | ManualAnimationCameraViewProvider(MCObj.ViewObject) 84 | EAFolder.addObject(MCObj) 85 | # add selection to camera from-to 86 | MCObj.RunFrom = initial_obj 87 | MCObj.RunTo = final_obj 88 | # organize inside folder 89 | FreeCAD.Gui.Selection.clearSelection() 90 | FreeCAD.Gui.Selection.addSelection(MCObj) 91 | FreeCAD.Gui.Selection.addSelection(EAFolder.Group[0]) 92 | from ExplodedAssembly import placeBeforeSelectedTrajectory 93 | placeBeforeSelectedTrajectory() 94 | FreeCAD.Console.PrintMessage('\nManual camera created\n') 95 | 96 | """from FreeCAD import Base 97 | cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode() 98 | trajectory = Gui.Selection.getSelectionEx()[0].Object.Shape.Edges 99 | for edge in trajectory: 100 | startPoint = edge.valueAt( 0.0 ) 101 | endPoint = edge.valueAt( edge.Length ) 102 | dirVector = ( endPoint - startPoint ).normalize() 103 | currentPoint = startPoint 104 | while (currentPoint - startPoint).Length < edge.Length: 105 | currentPoint = currentPoint + dirVector 106 | cam.position.setValue(currentPoint + Base.Vector( 0,0, 10) ) 107 | cam.pointAt( coin.SbVec3f( endPoint[0], endPoint[1], endPoint[2]+10) , coin.SbVec3f( 0, 0, 1 ) ) 108 | Gui.updateGui() 109 | time.sleep(0.005) 110 | """ 111 | -------------------------------------------------------------------------------- /EAInit.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # FreeCAD Exploded Assembly Animation Workbench 3 | # (c) 2016 Javier Martínez García 4 | 5 | #*************************************************************************** 6 | #* (c) Javier Martínez García 2016 * 7 | #* * 8 | #* This program is free software; you can redistribute it and/or modify * 9 | #* it under the terms of the GNU General Public License (GPL) * 10 | #* as published by the Free Software Foundation; either version 2 of * 11 | #* the License, or (at your option) any later version. * 12 | #* for detail see the LICENCE text file. * 13 | #* * 14 | #* This macro is distributed in the hope that it will be useful, * 15 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of * 16 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 17 | #* GNU Lesser General Public License for more details. * 18 | #* * 19 | #* You should have received a copy of the GNU Library General Public * 20 | #* License along with FreeCAD; if not, write to the Free Software * 21 | #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * 22 | #* USA * 23 | #* * 24 | #***************************************************************************/ 25 | 26 | import os 27 | import FreeCAD 28 | import FreeCADGui 29 | import ExplodedAssembly as ea 30 | import CameraAnimation as ca 31 | __dir__ = os.path.dirname(__file__) 32 | 33 | # TODO CHANGE NAME: SIMPLE DISASSEMBLE GROUP, WIRE DISASSEMBLE GROUP 34 | 35 | 36 | class CreateBoltGroup: 37 | def GetResources(self): 38 | return {'Pixmap': __dir__ + '/icons/BoltGroup.svg', 39 | 'MenuText': 'Create Bolt Group', 40 | 'ToolTip': 'Create a special exploded group for screws, nuts, bolts... \n Select circular edges of the shape you want to animate, then\n select one face (arbitrary shape) wich has as normal vector\nin the direction in wich you want to move the selected shapes'} 41 | 42 | def IsActive(self): 43 | if FreeCADGui.ActiveDocument: 44 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 45 | return True 46 | 47 | else: 48 | return False 49 | 50 | def Activated(self): 51 | ea.checkDocumentStructure() 52 | ea.createBoltDisassemble() 53 | 54 | 55 | class CreateSimpleGroup: 56 | def GetResources(self): 57 | return {'Pixmap': __dir__ + '/icons/SimpleGroup.svg', 58 | 'MenuText': 'Create Simple Group', 59 | 'ToolTip': 'Select the objects you want to explode and\nfinally the face which its normal is the trajectory director vector'} 60 | 61 | def IsActive(self): 62 | if FreeCADGui.ActiveDocument: 63 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 64 | return True 65 | 66 | else: 67 | return False 68 | 69 | def Activated(self): 70 | ea.checkDocumentStructure() 71 | ea.createSimpleDisassemble() 72 | 73 | class CreateWireGroup: 74 | def GetResources(self): 75 | return {'Pixmap': __dir__ + '/icons/WireTrajectory.svg', 76 | 'MenuText': 'Create Route', 77 | 'ToolTip': 'Select first one or more shapes and last the wire or sketch that represents the trajectory'} 78 | 79 | def IsActive(self): 80 | if FreeCADGui.ActiveDocument: 81 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 82 | return True 83 | 84 | else: 85 | return False 86 | 87 | def Activated(self): 88 | pass 89 | 90 | 91 | 92 | class PlaceBeforeSelectedTrajectory: 93 | # execute this function with caution 94 | def GetResources(self): 95 | return {'Pixmap': __dir__ + '/icons/PlaceBeforeTrajectory.svg', 96 | 'MenuText': 'PlaceBefore', 97 | 'ToolTip': 'Select the trajectories you want to reallocate (in order) and finally\nthe trajectory before which you want to place them'} 98 | 99 | def IsActive(self): 100 | if FreeCADGui.ActiveDocument: 101 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 102 | return True 103 | 104 | else: 105 | return False 106 | 107 | def Activated(self): 108 | # check selection before running (rearrange objects is dangerous, use with caution) 109 | try: 110 | sel = FreeCAD.Gui.Selection.getSelectionEx() 111 | a = sel[0].Object.Distance 112 | a = sel[1].Object.Distance 113 | # selection are trajectories, proceed 114 | ea.placeBeforeSelectedTrajectory() 115 | ea.resetPlacement() 116 | FreeCAD.Gui.Selection.clearSelection() 117 | FreeCAD.Gui.Selection.addSelection(sel[0].Object) 118 | ea.goToSelectedTrajectory() 119 | 120 | except: 121 | FreeCAD.Console.PrintError('\n Select exploded assembly trajectory objects only') 122 | 123 | class ModifyIndividualObjectTrajectory: 124 | # execute this function with caution 125 | def GetResources(self): 126 | return {'Pixmap': __dir__ + '/icons/ModifyIndividualObjectTrajectory.svg', 127 | 'MenuText': 'Modify Individual Object Trajectory', 128 | 'ToolTip': 'Explode objects on several directions at once\nSelect the trajectory, select the object and\nthe face which its normal is the new director\nvector'} 129 | 130 | def IsActive(self): 131 | if FreeCADGui.ActiveDocument: 132 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 133 | return True 134 | 135 | else: 136 | return False 137 | 138 | def Activated(self): 139 | # check selection before running (rearrange objects is dangerous, use with caution) 140 | ea.modifyIndividualObjectTrajectory() 141 | sel_traj = FreeCAD.Gui.Selection.getSelectionEx()[0].Object 142 | FreeCAD.Gui.Selection.clearSelection() 143 | FreeCAD.Gui.Selection.addSelection(sel_traj) 144 | ea.goToSelectedTrajectory() 145 | 146 | 147 | # camera commands 148 | class CreateManualCamera: 149 | def GetResources(self): 150 | return {'Pixmap': __dir__ + '/icons/AnimationCameraManual.svg', 151 | 'MenuText': 'Manual Animation Camera', 152 | 'ToolTip': 'Create a transition between two cameras'} 153 | 154 | def IsActive(self): 155 | if FreeCADGui.ActiveDocument: 156 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 157 | return True 158 | 159 | else: 160 | return False 161 | 162 | def Activated(self): 163 | pass 164 | 165 | 166 | class CreateEdgeCamera: 167 | def GetResources(self): 168 | return {'Pixmap': __dir__ + '/icons/AnimationCameraEdge.svg', 169 | 'MenuText': 'Manual Animation Camera', 170 | 'ToolTip': 'Create a transition between two cameras'} 171 | 172 | def IsActive(self): 173 | if FreeCADGui.ActiveDocument: 174 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 175 | return True 176 | 177 | else: 178 | return False 179 | 180 | def Activated(self): 181 | pass 182 | 183 | 184 | class CreateFollowCamera: 185 | def GetResources(self): 186 | return {'Pixmap': __dir__ + '/icons/AnimationCameraFollow.svg', 187 | 'MenuText': 'Manual Animation Camera', 188 | 'ToolTip': 'Create a transition between two cameras'} 189 | 190 | def IsActive(self): 191 | if FreeCADGui.ActiveDocument: 192 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 193 | return True 194 | 195 | else: 196 | return False 197 | 198 | def Activated(self): 199 | pass 200 | 201 | 202 | class PlayForward: 203 | def GetResources(self): 204 | return {'Pixmap': __dir__ + '/icons/PlayForward.svg', 205 | 'MenuText': 'Play Forward', 206 | 'ToolTip': 'Run the assembly animation'} 207 | 208 | def IsActive(self): 209 | if FreeCADGui.ActiveDocument: 210 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 211 | return True 212 | 213 | else: 214 | return False 215 | 216 | def Activated(self): 217 | EA = FreeCAD.ActiveDocument.ExplodedAssembly 218 | if EA.CurrentTrajectory <= 0: 219 | # if exploded state = 0 or -1, reset and run 220 | ea.resetPlacement() 221 | ea.runAnimation() 222 | 223 | else: 224 | # if animation has been paused in the middle: 225 | cr_traj = EA.Group[EA.CurrentTrajectory] 226 | ea.runAnimation(start=EA.CurrentTrajectory+1, mode='toPoint') 227 | 228 | 229 | class PlayBackward: 230 | def GetResources(self): 231 | return {'Pixmap': __dir__ + '/icons/PlayBackward.svg', 232 | 'MenuText': 'Play Backwards', 233 | 'ToolTip': __dir__ + 'icons/TrajectoryEdit.svg'} 234 | 235 | def IsActive(self): 236 | if FreeCADGui.ActiveDocument: 237 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 238 | return True 239 | 240 | else: 241 | return False 242 | 243 | def Activated(self): 244 | EA = FreeCAD.ActiveDocument.ExplodedAssembly 245 | if EA.CurrentTrajectory <= 0: 246 | # if exploded state = 0 or -1, reset and run 247 | ea.resetPlacement() 248 | ea.goToEnd() 249 | ea.runAnimation(direction='backward') 250 | 251 | else: 252 | # if animation has been paused in the middle: 253 | ea.runAnimation(end=-EA.CurrentTrajectory - 1 + len(EA.Group), 254 | mode='toPoint', 255 | direction='backward') 256 | 257 | 258 | class StopAnimation: 259 | def GetResources(self): 260 | return {'Pixmap': __dir__ + '/icons/Pause.svg', 261 | 'MenuText': 'StopAnimation', 262 | 'ToolTip': 'Stops the animation at the current trajectory'} 263 | 264 | def IsActive(self): 265 | if FreeCADGui.ActiveDocument: 266 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 267 | return False 268 | 269 | else: 270 | return True 271 | 272 | else: 273 | return False 274 | 275 | def Activated(self): 276 | FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation = False 277 | # FreeCAD.Gui.updateGui() 278 | 279 | 280 | class GoToStart: 281 | def GetResources(self): 282 | return {'Pixmap': __dir__ + '/icons/GoToStart.svg', 283 | 'MenuText': 'Assemble', 284 | 'ToolTip': 'Go to the assembled position of the parts'} 285 | 286 | def IsActive(self): 287 | if FreeCADGui.ActiveDocument.ExplodedAssembly: 288 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 289 | return True 290 | 291 | else: 292 | return False 293 | 294 | def Activated(self): 295 | ea.resetPlacement() 296 | FreeCAD.ActiveDocument.ExplodedAssembly.CurrentTrajectory = 0 297 | 298 | 299 | class GoToEnd: 300 | def GetResources(self): 301 | return {'Pixmap': __dir__ + '/icons/GoToEnd.svg', 302 | 'MenuText': 'Disassemble', 303 | 'ToolTip': 'Expand all trajectories'} 304 | 305 | def IsActive(self): 306 | if FreeCADGui.ActiveDocument.ExplodedAssembly: 307 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 308 | return True 309 | 310 | else: 311 | return False 312 | 313 | def Activated(self): 314 | ea.resetPlacement() 315 | ea.goToEnd() 316 | FreeCAD.ActiveDocument.ExplodedAssembly.CurrentTrajectory = -1 317 | 318 | 319 | class GoToSelectedTrajectory: 320 | def GetResources(self): 321 | return {'Pixmap': __dir__ + '/icons/ExplodeToSelection.svg', 322 | 'MenuText': 'ExplodeToSelection', 323 | 'ToolTip': 'Expand up to the selected trajectory'} 324 | 325 | def IsActive(self): 326 | if FreeCADGui.ActiveDocument.ExplodedAssembly: 327 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 328 | return True 329 | 330 | else: 331 | return False 332 | 333 | def Activated(self): 334 | try: 335 | ea.resetPlacement() 336 | ea.goToSelectedTrajectory() 337 | 338 | except: 339 | FreeCAD.Console.PrintError('Error: Select one exploded animation trajectory') 340 | 341 | 342 | class ToggleTrajectoryVisibility: 343 | def __init__(self): 344 | self.visibility = True 345 | 346 | def GetResources(self): 347 | return {'Pixmap': __dir__ + '/icons/TrajectoryLineVisibility.svg', 348 | 'MenuText': 'Trajectory Visibility', 349 | 'ToolTip': 'Toggle trajectory visibility'} 350 | 351 | def IsActive(self): 352 | if FreeCADGui.ActiveDocument.ExplodedAssembly: 353 | return True 354 | 355 | else: 356 | return False 357 | 358 | def Activated(self): 359 | self.visibility = not(self.visibility) 360 | ea.visibilityTrajectoryLines(self.visibility) 361 | 362 | 363 | 364 | # Assembly tools ############################################################### 365 | class AlignToEdge: 366 | def GetResources(self): 367 | return {'Pixmap': __dir__ + '/icons/AlignToEdge.svg', 368 | 'MenuText': 'Align to edge', 369 | 'ToolTip': 'Auxiliary tool to align shapes.\nPick one edge of the object you want to align and\nthen the edge of the object used as reference'} 370 | 371 | def IsActive(self): 372 | if FreeCADGui.ActiveDocument: 373 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 374 | return True 375 | 376 | else: 377 | return False 378 | 379 | def Activated(self): 380 | sel = FreeCAD.Gui.Selection.getSelectionEx() 381 | objA = sel[0].Object 382 | edgeA = sel[0].SubObjects[0] 383 | edgeB = sel[1].SubObjects[0] 384 | # transform object A placement 385 | # edge vector 386 | va = (edgeA.Curve.EndPoint - edgeA.Curve.StartPoint).normalize() 387 | vb = (edgeB.Curve.EndPoint - edgeB.Curve.StartPoint).normalize() 388 | # rot centre 389 | centre = edgeA.Curve.StartPoint 390 | # new placement 391 | new_plm = FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(va, vb), centre) 392 | # apply placement 393 | objA.Placement = new_plm.multiply(objA.Placement) 394 | 395 | 396 | class Rotate15: 397 | def GetResources(self): 398 | return {'Pixmap': __dir__ + '/icons/Rotate90.svg', 399 | 'MenuText': 'Rotate 15', 400 | 'ToolTip': 'Auxiliary tool to rotate a shape 15 degrees.\nSelect a face of the object you want to rotate\n and it will be rotated 15 degrees using its normal as rotation\n axis'} 401 | 402 | def IsActive(self): 403 | if FreeCADGui.ActiveDocument: 404 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 405 | return True 406 | 407 | else: 408 | return False 409 | 410 | def Activated(self): 411 | sel = FreeCAD.Gui.Selection.getSelectionEx() 412 | objA = sel[0].Object 413 | selFace = sel[0].SubObjects[0] 414 | rot_center = selFace.CenterOfMass 415 | rot_axis = selFace.normalAt(0, 0) 416 | rot = FreeCAD.Rotation(rot_axis, 15) 417 | objA.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0), rot, rot_center).multiply(objA.Placement) 418 | 419 | class PointToPoint: 420 | def GetResources(self): 421 | return {'Pixmap': __dir__ + '/icons/SharePoint.svg', 422 | 'MenuText': 'Point to point', 423 | 'ToolTip': 'Auxiliary tool to move point to point.\nSelect one point from the shape you want to move \n and then the point from other shape where you want to place it'} 424 | 425 | def IsActive(self): 426 | if FreeCADGui.ActiveDocument: 427 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 428 | return True 429 | 430 | else: 431 | return False 432 | 433 | def Activated(self): 434 | sel = FreeCAD.Gui.Selection.getSelectionEx() 435 | objA = sel[0].Object 436 | PA = sel[0].SubObjects[0] 437 | PB = sel[1].SubObjects[0] 438 | v = PB.Point - PA.Point 439 | objA.Placement.Base.x += v.x 440 | objA.Placement.Base.y += v.y 441 | objA.Placement.Base.z += v.z 442 | 443 | 444 | class PlaceConcentric: 445 | def GetResources(self): 446 | return {'Pixmap': __dir__ + '/icons/ShareCenter.svg', 447 | 'MenuText': 'Place concentrically', 448 | 'ToolTip': 'Auxiliary tool to place two shapes concentrically\nPlace the first circular edge selected concentric to \nthe second circular edge selected'} 449 | 450 | def IsActive(self): 451 | if FreeCADGui.ActiveDocument: 452 | if not(FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation): 453 | return True 454 | 455 | else: 456 | return False 457 | 458 | def Activated(self): 459 | sel = FreeCAD.Gui.Selection.getSelectionEx() 460 | objA = sel[0].Object 461 | CentreA = sel[0].SubObjects[0].Curve.Center 462 | CentreB = sel[1].SubObjects[0].Curve.Center 463 | v = CentreB - CentreA 464 | objA.Placement.Base.x += v.x 465 | objA.Placement.Base.y += v.y 466 | objA.Placement.Base.z += v.z 467 | 468 | 469 | # non icon comands 470 | class LoadExampleFile: 471 | def GetResources(self): 472 | return {'Pixmap': '', 473 | 'MenuText': 'Load Example File', 474 | 'ToolTip': 'Load an exploded assembly example file'} 475 | 476 | def IsActive(self): 477 | if not(FreeCADGui.ActiveDocument): 478 | return True 479 | 480 | else: 481 | if FreeCAD.ActiveDocument.Name != 'example': 482 | return True 483 | 484 | else: 485 | return False 486 | 487 | def Activated(self): 488 | FreeCAD.open(__dir__ + '/example.fcstd') 489 | 490 | if FreeCAD.GuiUp: 491 | FreeCAD.Gui.addCommand('CreateBoltGroup', CreateBoltGroup()) 492 | FreeCAD.Gui.addCommand('CreateSimpleGroup', CreateSimpleGroup()) 493 | FreeCAD.Gui.addCommand('CreateWireGroup', CreateWireGroup()) 494 | FreeCAD.Gui.addCommand('ModifyIndividualObjectTrajectory', ModifyIndividualObjectTrajectory()) 495 | FreeCAD.Gui.addCommand('CreateManualCamera', CreateManualCamera()) 496 | FreeCAD.Gui.addCommand('CreateEdgeCamera', CreateEdgeCamera()) 497 | FreeCAD.Gui.addCommand('CreateFollowCamera', CreateFollowCamera()) 498 | FreeCAD.Gui.addCommand('PlaceBeforeSelectedTrajectory', PlaceBeforeSelectedTrajectory()) 499 | FreeCAD.Gui.addCommand('GoToStart', GoToStart()) 500 | FreeCAD.Gui.addCommand('PlayBackward', PlayBackward()) 501 | FreeCAD.Gui.addCommand('StopAnimation', StopAnimation()) 502 | FreeCAD.Gui.addCommand('PlayForward', PlayForward()) 503 | FreeCAD.Gui.addCommand('GoToEnd', GoToEnd()) 504 | FreeCAD.Gui.addCommand('GoToSelectedTrajectory',GoToSelectedTrajectory()) 505 | FreeCAD.Gui.addCommand('ToggleTrajectoryVisibility', ToggleTrajectoryVisibility()) 506 | FreeCAD.Gui.addCommand('AlignToEdge', AlignToEdge()) 507 | FreeCAD.Gui.addCommand('Rotate15', Rotate15()) 508 | FreeCAD.Gui.addCommand('PointToPoint', PointToPoint()) 509 | FreeCAD.Gui.addCommand('PlaceConcentric', PlaceConcentric()) 510 | FreeCAD.Gui.addCommand('LoadExampleFile', LoadExampleFile()) 511 | -------------------------------------------------------------------------------- /ExplodedAssembly.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Exploded Assembly Animation workbench for FreeCAD 3 | # (c) 2016 Javier Martínez García 4 | #*************************************************************************** 5 | #* (c) Javier Martínez García 2016 * 6 | #* * 7 | #* This program is free software; you can redistribute it and/or modify * 8 | #* it under the terms of the GNU General Public License (GPL) * 9 | #* as published by the Free Software Foundation; either version 2 of * 10 | #* the License, or (at your option) any later version. * 11 | #* for detail see the LICENCE text file. * 12 | #* * 13 | #* This program is distributed in the hope that it will be useful, * 14 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 | #* GNU Lesser General Public License for more details. * 17 | #* * 18 | #* You should have received a copy of the GNU Library General Public * 19 | #* License along with FreeCAD; if not, write to the Free Software * 20 | #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * 21 | #* USA * 22 | #* * 23 | #***************************************************************************/ 24 | 25 | from __future__ import division 26 | import os 27 | import time 28 | import FreeCAD 29 | import Part 30 | 31 | 32 | # Container python folder 'ExplodedAssembly' 33 | class ExplodedAssemblyFolder: 34 | def __init__(self, obj): 35 | obj.addProperty('App::PropertyPythonObject', 'InitialPlacements').InitialPlacements = {} 36 | obj.addProperty('App::PropertyInteger', 'AnimationStep').AnimationStep = 0 37 | obj.addProperty('App::PropertyInteger', 'CurrentTrajectory').CurrentTrajectory = 0 38 | obj.addProperty('App::PropertyBool', 'ResetAnimation').ResetAnimation = False 39 | obj.addProperty('App::PropertyBool', 'InAnimation').InAnimation = False 40 | obj.addProperty('App::PropertyBool', 'RemoveAllTrajectories').RemoveAllTrajectories = False 41 | obj.Proxy = self 42 | 43 | def execute(self, fp): 44 | if fp.ResetAnimation: 45 | resetPlacement() 46 | fp.ResetAnimation = False 47 | 48 | if fp.RemoveAllTrajectories: 49 | fp.RemoveAllTrajectories = False 50 | for obj in fp.Group: 51 | FreeCAD.ActiveDocument.removeObject(obj.Name) 52 | 53 | # reset initial placement dict 54 | fp.InitialPlacements = {} 55 | 56 | 57 | class ExplodedAssemblyFolderViewProvider: 58 | def __init__(self, obj): 59 | obj.Proxy = self 60 | 61 | def getIcon(self): 62 | __dir__ = os.path.dirname(__file__) 63 | return __dir__ + '/icons/WorkbenchIcon.svg' 64 | 65 | 66 | def checkDocumentStructure(): 67 | # checks the existence of the folder 'ExplodedAssembly' and creates it if not 68 | try: 69 | folder = FreeCAD.ActiveDocument.ExplodedAssembly 70 | 71 | except: 72 | folder = FreeCAD.ActiveDocument.addObject('App::DocumentObjectGroupPython', 'ExplodedAssembly') 73 | ExplodedAssemblyFolder(folder) 74 | ExplodedAssemblyFolderViewProvider(folder.ViewObject) 75 | 76 | 77 | # Bolt group trajectory ######################################################## 78 | class BoltGroupObject: 79 | def __init__(self, obj): 80 | obj.addProperty('App::PropertyPythonObject', 'names').names = [] 81 | obj.addProperty('App::PropertyVectorList', 'dir_vectors').dir_vectors = [] 82 | obj.addProperty('App::PropertyVectorList', 'rot_vectors').rot_vectors = [] 83 | obj.addProperty('App::PropertyVectorList', 'rot_centers').rot_centers = [] 84 | # 85 | obj.addProperty('App::PropertyFloat', 'Distance').Distance = 20.0 86 | obj.addProperty('App::PropertyFloat', 'Revolutions').Revolutions = 0.0 87 | obj.addProperty('App::PropertyFloat', 'AnimationStepTime').AnimationStepTime = 0.0 88 | obj.addProperty('App::PropertyInteger', 'AnimationSteps').AnimationSteps = 20 89 | obj.Proxy = self 90 | 91 | def onChanged(self, fp, prop): 92 | pass 93 | 94 | def execute(self, fp): 95 | resetPlacement() 96 | goToEnd() 97 | FreeCAD.ActiveDocument.ExplodedAssembly.CurrentTrajectory = -1 98 | 99 | class BoltGroupObjectViewProvider: 100 | def __init__(self, obj): 101 | obj.Proxy = self 102 | 103 | def getIcon(self): 104 | __dir__ = os.path.dirname(__file__) 105 | return __dir__ + '/icons/BoltGroup.svg' 106 | 107 | 108 | def createBoltDisassemble(): 109 | # add object to the Document and initialize it 110 | SDObj = FreeCAD.ActiveDocument.addObject('App::DocumentObjectGroupPython','BoltGroup') 111 | BoltGroupObject(SDObj) 112 | BoltGroupObjectViewProvider(SDObj.ViewObject) 113 | # retrieve selection 114 | selection = FreeCAD.Gui.Selection.getSelectionEx() 115 | # try to find the face wich its normal gives the disassemble direction 116 | dir_vector = FreeCAD.Vector(0, 0, 1) 117 | for sel_obj in selection: 118 | for subObject in sel_obj.SubObjects: 119 | try: 120 | dir_vector = subObject.normalAt(0, 0) 121 | break 122 | except: 123 | pass 124 | 125 | for sel_obj in selection: 126 | for subObject in sel_obj.SubObjects: 127 | try: 128 | if str(subObject.Curve)[0:6] == 'Circle': 129 | # append object name 130 | SDObj.names.append(sel_obj.Object.Name) 131 | # append unmount direction 132 | SDObj.dir_vectors += [(dir_vector[0], dir_vector[1], dir_vector[2])] 133 | # apend rotation axis 134 | SDObj.rot_vectors += [(dir_vector[0], dir_vector[1], dir_vector[2])] 135 | # append rotation center 136 | SDObj.rot_centers += [subObject.Curve.Center] 137 | # append initial values for distance, revs, steps 138 | SDObj.distance.append(10.0) 139 | SDObj.revolutions.append(0) 140 | SDObj.animation_steps.append(20.0) 141 | 142 | except: 143 | pass 144 | 145 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly 146 | # add initial placement if this is the first movement of the parts 147 | for name in SDObj.names: 148 | try: 149 | plm = EAFolder.InitialPlacements[name] 150 | 151 | except: 152 | an_object = FreeCAD.ActiveDocument.getObject(name) 153 | # prepare object placement for JSON serialization 154 | # store base placement as vector 155 | plm = an_object.Placement 156 | base = (plm.Base[0], plm.Base[1], plm.Base[2]) 157 | # store rotation as a quaternion 158 | rot = plm.Rotation.Q 159 | placement = (base, rot) 160 | EAFolder.InitialPlacements[name] = placement 161 | 162 | # place inside ExplodedAssembly folder and update document 163 | EAFolder.addObject(SDObj) 164 | updateTrajectoryLines() 165 | FreeCAD.ActiveDocument.recompute() 166 | 167 | 168 | # simple group trajectory ######################################################## 169 | class SimpleGroupObject: 170 | def __init__(self, obj): 171 | obj.addProperty('App::PropertyPythonObject', 'names').names = [] 172 | obj.addProperty('App::PropertyVectorList', 'dir_vectors').dir_vectors = [] 173 | obj.addProperty('App::PropertyVectorList', 'rot_vectors').rot_vectors = [] 174 | obj.addProperty('App::PropertyVectorList', 'rot_centers').rot_centers = [] 175 | # 176 | obj.addProperty('App::PropertyFloat', 'Distance').Distance = 20.0 177 | obj.addProperty('App::PropertyFloat', 'Revolutions').Revolutions = 0.0 178 | obj.addProperty('App::PropertyFloat', 'AnimationStepTime').AnimationStepTime = 0.0 179 | obj.addProperty('App::PropertyInteger', 'AnimationSteps').AnimationSteps = 20 180 | obj.Proxy = self 181 | 182 | def onChanged(self, fp, prop): 183 | pass 184 | 185 | def execute(self, fp): 186 | resetPlacement() 187 | goToEnd() 188 | FreeCAD.ActiveDocument.ExplodedAssembly.CurrentTrajectory = -1 189 | 190 | 191 | class SimpleGroupObjectViewProvider: 192 | def __init__(self, obj): 193 | obj.Proxy = self 194 | 195 | def getIcon(self): 196 | __dir__ = os.path.dirname(__file__) 197 | return __dir__ + '/icons/SimpleGroup.svg' 198 | 199 | 200 | def createSimpleDisassemble(): 201 | # add object to the Document and initialize it 202 | SDObj = FreeCAD.ActiveDocument.addObject('App::DocumentObjectGroupPython', 'SimpleGroup') 203 | SimpleGroupObject(SDObj) 204 | SimpleGroupObjectViewProvider(SDObj.ViewObject) 205 | # retrieve selection 206 | selection = FreeCAD.Gui.Selection.getSelectionEx() 207 | # the last face of the last object selected determines the disassemble dir vector 208 | dir_vector = selection[-1].SubObjects[-1].normalAt(0, 0) 209 | # the rotation center is the center of mass of the last face selected 210 | rot_center = selection[-1].SubObjects[-1].CenterOfMass 211 | # ignore last object if it cannot be moved, it is only used for positioning 212 | if FreeCAD.ActiveDocument.getObject(selection[-1].Object.Name) is None: 213 | del selection[-1] 214 | # create trajectory data 215 | obj_selection = FreeCAD.Gui.Selection.getSelection() 216 | for i, sel_obj in enumerate(obj_selection): 217 | if len(obj_selection) > 1 and i == ( len(obj_selection)-1 ): 218 | # last object only serves as reference 219 | break 220 | SDObj.names.append(sel_obj.Name) 221 | # append unmount direction 222 | SDObj.dir_vectors += [(dir_vector[0], dir_vector[1], dir_vector[2])] 223 | # apend rotation axis 224 | SDObj.rot_vectors += [(dir_vector[0], dir_vector[1], dir_vector[2])] 225 | # append rotation center 226 | SDObj.rot_centers += [(rot_center[0], rot_center[1], rot_center[2])] 227 | 228 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly 229 | # add initial placement if this is the first move of the parts 230 | for name in SDObj.names: 231 | try: 232 | plm = EAFolder.InitialPlacements[name] 233 | 234 | except: 235 | an_object = FreeCAD.ActiveDocument.getObject(name) 236 | # prepare object placement for JSON serialization 237 | # store base placement as vector 238 | plm = an_object.Placement 239 | base = (plm.Base[0], plm.Base[1], plm.Base[2]) 240 | # store rotation as a quaternion 241 | rot = plm.Rotation.Q 242 | placement = (base, rot) 243 | EAFolder.InitialPlacements[name] = placement 244 | 245 | # place inside ExplodedAssembly folder and update document 246 | EAFolder.addObject(SDObj) 247 | updateTrajectoryLines() 248 | FreeCAD.ActiveDocument.recompute() 249 | 250 | 251 | # wire group trajectory ######################################################## 252 | class WireGroupObject: 253 | def __init__(self, obj): 254 | obj.addProperty('App::PropertyPythonObject', 'names').names = [] 255 | obj.addProperty('App::PropertyFloat', 'AnimationStepTime').AnimationStepTime = 0.0 256 | obj.addProperty('App::PropertyInteger', 'AnimationStepsEdge').AnimationStepsEdge = 10 257 | obj.Proxy = self 258 | 259 | def onChanged(self, fp, prop): 260 | pass 261 | 262 | def execute(self, fp): 263 | resetPlacement() 264 | goToEnd() 265 | FreeCAD.ActiveDocument.ExplodedAssembly.CurrentTrajectory = -1 266 | 267 | 268 | class WireGroupObjectViewProvider: 269 | def __init__(self, obj): 270 | obj.Proxy = self 271 | 272 | def getIcon(self): 273 | __dir__ = os.path.dirname(__file__) 274 | return __dir__ + '/icons/WireTrajectory.svg' 275 | 276 | 277 | def createWireDisassemble(): 278 | # select the objects and finally the trajectory objects 279 | # Animation will run over the edges of the trajectory object 280 | sel_objects = FreeCAD.Gui.Selection.getSelection()[0:-2] 281 | sel_wire = FreeCAD.Gui.Selection.getSelection()[-1] 282 | # Initialize object 283 | WDObj = FreeCAD.ActiveDocument.addObject('App::DocumentObjectGroupPython', 'WireGroup') 284 | WireGroupObject(WDObj) 285 | #WireGroupObjectViewProvider(WDObj.ViewObject) 286 | # add object names 287 | for obj in sel_objects: 288 | obj_name = obj.Name 289 | WDObj.names.append(obj_name) 290 | 291 | # add trajectory objecto to this new wire group 292 | WDObj.addObject(sel_wire) 293 | # place inside ea folder 294 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly 295 | EAFolder.addObject(WDObj) 296 | FreeCAD.ActiveDocument.recompute() 297 | 298 | 299 | 300 | 301 | 302 | def resetPlacement(): 303 | # restore the placement of all objects 304 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly 305 | # set everything to its initial position 306 | for traj in EAFolder.Group: 307 | for name in traj.names: 308 | obj = FreeCAD.ActiveDocument.getObject(name) 309 | # create placement from initial placement list 310 | plm = EAFolder.InitialPlacements[name] 311 | base = FreeCAD.Vector(plm[0][0], plm[0][1], plm[0][2]) 312 | rot = FreeCAD.Rotation(plm[1][0], plm[1][1], plm[1][2], plm[1][3]) 313 | obj.Placement = FreeCAD.Placement(base, rot) 314 | 315 | 316 | 317 | def runAnimation(start=0, end=0, mode='complete', direction='forward'): 318 | # runs the animation from a start step number to the end step number 319 | # mode: 'complete', 'toPoint' 320 | # 'complete' means forward from start to end and backwars if already in end 321 | # 'forward' means disassemble from start to end 322 | # 'backward' means assemble from start to end 323 | # 'toPoint' means go to an especific end point without animation 324 | # toggle 'InAnimation variable' to disable other icons temporally 325 | FreeCAD.ActiveDocument.ExplodedAssembly.InAnimation = True 326 | # # complete mode 327 | # start animation 328 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group 329 | if mode == 'complete': 330 | number_of_trajectories = len(EAFolder) 331 | 332 | elif mode == 'toPoint': 333 | number_of_trajectories = len(EAFolder) - start - end 334 | 335 | traj_iterator = range(number_of_trajectories) 336 | if direction == 'backward': 337 | traj_iterator = range(number_of_trajectories-1, -1, -1) 338 | 339 | animation_paused = False 340 | for r in traj_iterator: 341 | # break animation loop if not InAnimation (this is where pause animation takes place): 342 | EA = FreeCAD.ActiveDocument.ExplodedAssembly 343 | if not(EA.InAnimation): 344 | animation_paused = True 345 | break 346 | 347 | if direction == 'forward': 348 | traj = EAFolder[r+start] 349 | # set current stop point 350 | EA.CurrentTrajectory = r+start 351 | 352 | elif direction == 'backward': 353 | traj = EAFolder[r] 354 | # set current stop point 355 | EA.CurrentTrajectory = r-1 356 | 357 | # highligh current trajectory 358 | FreeCAD.Gui.Selection.addSelection(traj) 359 | # If trajectory is a bolt group or simple group: 360 | if traj.Name[0:11] == 'SimpleGroup' or traj.Name[0:9] == 'BoltGroup': 361 | # buffer objects 362 | objects = [] 363 | for name in traj.names: 364 | objects.append(FreeCAD.ActiveDocument.getObject(name)) 365 | 366 | inc_D = traj.Distance / float(traj.AnimationSteps) 367 | inc_R = traj.Revolutions / float(traj.AnimationSteps) 368 | if direction == 'backward': 369 | inc_D = inc_D*-1.0 370 | inc_R = inc_R*-1.0 371 | 372 | for i in range(traj.AnimationSteps): 373 | if i == 0: 374 | dir_vectors = [] 375 | rot_vectors = [] 376 | rot_centers = [] 377 | for s in range(len(objects)): 378 | dir_vectors.append(FreeCAD.Vector(tuple(traj.dir_vectors[s]))) 379 | rot_vectors.append(FreeCAD.Vector(tuple(traj.rot_vectors[s]))) 380 | rot_centers.append(FreeCAD.Vector(tuple(traj.rot_centers[s]))) 381 | 382 | for n in range(len(objects)): 383 | obj = objects[n] 384 | obj_base = dir_vectors[n]*inc_D 385 | obj_rot = FreeCAD.Rotation(rot_vectors[n], inc_R*360.0) 386 | obj_rot_center = rot_centers[n] 387 | incremental_placement = FreeCAD.Placement(obj_base, obj_rot, obj_rot_center) 388 | obj.Placement = incremental_placement.multiply(obj.Placement) 389 | 390 | FreeCAD.Gui.updateGui() 391 | time.sleep(traj.AnimationStepTime) 392 | 393 | else: 394 | # if traj is a WireGroup object 395 | steps = traj.AnimationStepsEdge 396 | edges = traj.Shape.Edges 397 | for edge in edges: 398 | points = edge.discretize(steps) 399 | vectors = [] 400 | for i in range(len(points)-1): 401 | pa = points[i] 402 | pb = points[i+1] 403 | v = (pb[0]+pa[0], pb[1]+pa[1], pb[2]+pa[2]) 404 | vectors.append(v) 405 | 406 | if direction == 'backward': 407 | vectors.reverse() 408 | 409 | for v in vectors: 410 | for i in range((len(traj.names))): 411 | obj = FreeCAD.ActiveDocument.getObject(traj.names[i]) 412 | # incremental placement 413 | obj.Placement.x = obj.Placement.x + v[0] 414 | obj.Placement.y = obj.Placement.y + v[1] 415 | obj.Placement.z = obj.Placement.z + v[2] 416 | 417 | FreeCAD.Gui.udpateGui() 418 | time.sleep(traj.AnimationStepTime) 419 | 420 | 421 | # clear selection 422 | FreeCAD.Gui.Selection.clearSelection() 423 | 424 | # set pointer to current trajectory index 425 | EA = FreeCAD.ActiveDocument.ExplodedAssembly 426 | # toggle InAnimation to activate icons deactivated before 427 | EA.InAnimation = False 428 | # set CurrentTrajectory number 429 | if not(animation_paused): 430 | if direction == 'forward' and end == 0: 431 | EA.CurrentTrajectory = -1 432 | 433 | if direction == 'backward' and start == 0: 434 | EA.CurrentTrajectory = 0 435 | 436 | 437 | 438 | def goToEnd(): 439 | # start animation 440 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group 441 | for traj in EAFolder: 442 | objects = [] 443 | for name in traj.names: 444 | objects.append(FreeCAD.ActiveDocument.getObject(name)) 445 | 446 | inc_D = traj.Distance / float(1) 447 | inc_R = traj.Revolutions / float(1) 448 | for n in range(len(objects)): 449 | obj = objects[n] 450 | obj_base = traj.dir_vectors[n]*inc_D 451 | obj_rot = FreeCAD.Rotation(traj.rot_vectors[n], inc_R*360) 452 | obj_rot_center = traj.rot_centers[n] 453 | incremental_placement = FreeCAD.Placement(obj_base, obj_rot, obj_rot_center) 454 | obj.Placement = incremental_placement.multiply(obj.Placement) 455 | 456 | FreeCAD.Gui.updateGui() 457 | 458 | 459 | def goToSelectedTrajectory(): 460 | # retrieve selection 461 | traj_name = FreeCAD.Gui.Selection.getSelectionEx()[0].Object.Name 462 | # start animation 463 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group 464 | for r in range(len(EAFolder)): 465 | traj = EAFolder[r] 466 | objects = [] 467 | update_gui = False 468 | for name in traj.names: 469 | objects.append(FreeCAD.ActiveDocument.getObject(name)) 470 | 471 | if traj_name == traj.Name: 472 | inc_D = traj.Distance / float(traj.AnimationSteps) 473 | inc_R = traj.Revolutions / float(traj.AnimationSteps) 474 | animation_range = traj.AnimationSteps 475 | update_gui = True 476 | 477 | else: 478 | inc_D = traj.Distance / float(1) 479 | inc_R = traj.Revolutions / float(1) 480 | animation_range = 1 481 | 482 | for i in range(animation_range): 483 | if i == 0: 484 | dir_vectors = [] 485 | rot_vectors = [] 486 | rot_centers = [] 487 | for s in range(len(objects)): 488 | dir_vectors.append(FreeCAD.Vector(tuple(traj.dir_vectors[s]))) 489 | rot_vectors.append(FreeCAD.Vector(tuple(traj.rot_vectors[s]))) 490 | rot_centers.append(FreeCAD.Vector(tuple(traj.rot_centers[s]))) 491 | 492 | for n in range(len(objects)): 493 | obj = objects[n] 494 | obj_base = dir_vectors[n]*inc_D 495 | obj_rot = FreeCAD.Rotation(rot_vectors[n], inc_R*360) 496 | obj_rot_center = rot_centers[n] 497 | incremental_placement = FreeCAD.Placement(obj_base, obj_rot, obj_rot_center) 498 | obj.Placement = incremental_placement.multiply(obj.Placement) 499 | 500 | if update_gui: 501 | FreeCAD.Gui.updateGui() 502 | 503 | if traj_name == traj.Name: 504 | # exit once selected trajectory has been reached 505 | break 506 | 507 | # set current trajectory cursor to current trajectory 508 | FreeCAD.ActiveDocument.ExplodedAssembly.CurrentTrajectory = r 509 | 510 | def placeBeforeSelectedTrajectory(): 511 | # select the trajectoreis you want to reallocate and finally, 512 | # the trajectory before wich you want to place them 513 | sel_traj = FreeCAD.Gui.Selection.getSelectionEx() 514 | # retrieve EA folder 515 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly 516 | # create an auxiliary folder to re organizate exploded assembly 517 | aux_folder = FreeCAD.ActiveDocument.addObject('App::DocumentObjectGroup','ea_aux') 518 | before_traj = sel_traj[-1].Object 519 | for traj in EAFolder.Group: 520 | if traj.Name == before_traj.Name: 521 | for sel in sel_traj: 522 | aux_folder.addObject(sel.Object) 523 | 524 | elif traj.Name != before_traj.Name: 525 | add_traj = True 526 | for sel in sel_traj: 527 | if traj.Name == sel.Object.Name: 528 | add_traj = False 529 | break 530 | 531 | if add_traj: 532 | aux_folder.addObject(traj) 533 | 534 | # save the attributes of EAFolder' 535 | EAF_InitialPlacements = EAFolder.InitialPlacements 536 | EAF_CurrentTrajectory = EAFolder.CurrentTrajectory 537 | EAF_ResetAnimation = EAFolder.ResetAnimation 538 | EAF_InAnimation = EAFolder.InAnimation 539 | EAF_RemoveAllTrajectories = EAFolder.RemoveAllTrajectories 540 | FreeCAD.ActiveDocument.removeObject(EAFolder.Name) 541 | # create the EAFolder 542 | EAFolder = FreeCAD.ActiveDocument.addObject('App::DocumentObjectGroupPython', 'ExplodedAssembly') 543 | ExplodedAssemblyFolder(EAFolder) 544 | ExplodedAssemblyFolderViewProvider(EAFolder.ViewObject) 545 | # restore its content 546 | for traj in aux_folder.Group: 547 | EAFolder.addObject(traj) 548 | 549 | EAFolder.InitialPlacements = EAF_InitialPlacements 550 | EAFolder.CurrentTrajectory = EAF_CurrentTrajectory 551 | EAFolder.ResetAnimation = EAF_ResetAnimation 552 | EAFolder.InAnimation = EAF_InAnimation 553 | EAFolder.RemoveAllTrajectories = EAF_RemoveAllTrajectories 554 | # remove auxiliary folder 555 | FreeCAD.ActiveDocument.removeObject(aux_folder.Name) 556 | # recompute document 557 | FreeCAD.ActiveDocument.recompute() 558 | FreeCAD.Gui.updateGui() 559 | 560 | 561 | def modifyIndividualObjectTrajectory(): 562 | # multi direction for simple trajectory(at the moment) 563 | # selection: trajectory_obj + shape + normal direction 564 | # selection: trajectory_obj + normal_direction(selected over the shape) 565 | sel_traj = FreeCAD.Gui.Selection.getSelectionEx()[0].Object 566 | sel_objects = FreeCAD.Gui.Selection.getSelectionEx()[1:] 567 | if len(sel_objects) == 1: 568 | obj_name = sel_objects[0].Object.Name 569 | sel_face = sel_objects[0].SubObjects[0] 570 | 571 | else: 572 | obj_name = sel_objects[0].Object.Name 573 | sel_face = sel_objects[1].SubObjects[0] 574 | 575 | for i in range(len(sel_traj.names)): 576 | name = sel_traj.names[i] 577 | if obj_name == name: 578 | # if selected trajectory is a simple trajectory: 579 | if sel_traj.Name[0:11] == 'SimpleGroup': 580 | # asign new explosion direction to sel normal 581 | v = sel_face.normalAt(0,0) 582 | sel_traj.dir_vectors[i] = (v[0], v[1], v[2]) 583 | break 584 | 585 | # if selected trajectory is a bolt group 586 | elif sel_traj.Name[0:9] == 'BoltGroup': 587 | # assign new exploded direction, rotation centre and vector 588 | v = sel_face.normalAt(0,0) 589 | c = sel_face.CenterOfMass 590 | sel_traj.dir_vectors[i] = (v[0], v[1], v[2]) 591 | sel_traj.rot_vectors[i] = (v[0], v[1], v[2]) 592 | sel_traj.rot_centers[i] = (c[0], c[1], c[2]) 593 | break 594 | 595 | 596 | 597 | def updateTrajectoryLines(): 598 | # TODO this is disabled because is no longer accurate and needs conversion to new placement 599 | # goes to a try/except until solved 600 | #return 601 | try: 602 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group 603 | # remove all the previous trajectory lines 604 | for traj in EAFolder: 605 | for lines in traj.Group: 606 | FreeCAD.ActiveDocument.removeObject(lines.Name) 607 | 608 | # re-draw all trajectories 609 | for traj in EAFolder: 610 | lines_compound = [] 611 | objects = [] 612 | for name in traj.names: 613 | objects.append(FreeCAD.ActiveDocument.getObject(name)) 614 | 615 | inc_D = traj.Distance 616 | dir_vectors = [] 617 | rot_centers = [] 618 | for s in range(len(objects)): 619 | dir_vectors.append(FreeCAD.Vector(tuple(traj.dir_vectors[s]))) 620 | rot_centers.append(FreeCAD.Vector(tuple(traj.rot_centers[s]))) 621 | 622 | for n in range(len(objects)): 623 | pa = rot_centers[n]# objects[n].Placement.Base 624 | pb = rot_centers[n] + dir_vectors[n]*inc_D 625 | lines_compound.append(Part.makeLine(pa, pb)) 626 | 627 | l_obj = FreeCAD.ActiveDocument.addObject('Part::Feature','trajectory_line') 628 | l_obj.Shape = Part.makeCompound(lines_compound) 629 | l_obj.ViewObject.DrawStyle = "Dashed" 630 | l_obj.ViewObject.LineWidth = 1.0 631 | traj.addObject(l_obj) 632 | except Exception as e: 633 | print("Trajectory Line exception:",e) 634 | 635 | FreeCAD.Gui.updateGui() 636 | 637 | 638 | 639 | def visibilityTrajectoryLines(show): 640 | # show or hide trajectory lines 641 | EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group 642 | for traj in EAFolder: 643 | for lines in traj.Group: 644 | lines.ViewObject.Visibility = show 645 | -------------------------------------------------------------------------------- /InitGui.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Exploded Assembly Animation workbench for FreeCAD 3 | # (c) 2016 Javier Martínez García 4 | #*************************************************************************** 5 | #* (c) Javier Martínez García 2016 * 6 | #* * 7 | #* This program is free software; you can redistribute it and/or modify * 8 | #* it under the terms of the GNU General Public License (GPL) * 9 | #* as published by the Free Software Foundation; either version 2 of * 10 | #* the License, or (at your option) any later version. * 11 | #* for detail see the LICENCE text file. * 12 | #* * 13 | #* This program is distributed in the hope that it will be useful, * 14 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 | #* GNU Lesser General Public License for more details. * 17 | #* * 18 | #* You should have received a copy of the GNU Library General Public * 19 | #* License along with FreeCAD; if not, write to the Free Software * 20 | #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * 21 | #* USA * 22 | #* * 23 | #***************************************************************************/ 24 | 25 | __title__="Exploded Assembly Workbench for FreeCAD" 26 | __author__ = "Javier Martínez García" 27 | __url__ = "http://linuxforanengineer.blogspot.com" 28 | 29 | import FreeCAD 30 | import FreeCADGui 31 | 32 | class ExplodedAssembly(Workbench): 33 | import EAInit# this is needed to load the workbench icon 34 | # __dir__ = os.path.dirname( __file__ ) # __file__ is not working 35 | Icon = EAInit.__dir__ + '/icons/WorkbenchIcon.svg' 36 | MenuText = 'Exploded Assembly' 37 | ToolTip = 'Assemble parts and create exploded drawings and animations' 38 | 39 | def GetClassName(self): 40 | return 'Gui::PythonWorkbench' 41 | 42 | def Initialize(self): 43 | import EAInit 44 | self.CreationTools = ['CreateBoltGroup', 45 | 'CreateSimpleGroup', 46 | 'ModifyIndividualObjectTrajectory', 47 | 'PlaceBeforeSelectedTrajectory', 48 | 'ToggleTrajectoryVisibility'] 49 | 50 | self.CameraAnimation = ['CreateManualCamera', 51 | 'CreateEdgeCamera', 52 | 'CreateFollowCamera'] 53 | 54 | self.AnimationControlTools = ['GoToStart', 55 | 'PlayBackward', 56 | 'StopAnimation', 57 | 'PlayForward', 58 | 'GoToEnd', 59 | 'GoToSelectedTrajectory'] 60 | 61 | self.AuxiliaryAssemblyTools = ['AlignToEdge', 62 | 'Rotate15', 63 | 'PointToPoint', 64 | 'PlaceConcentric'] 65 | 66 | self.Menu_tools = ['CreateBoltGroup', 67 | 'CreateSimpleGroup', 68 | 'ModifyIndividualObjectTrajectory', 69 | 'PlaceBeforeSelectedTrajectory', 70 | 'GoToSelectedTrajectory', 71 | 'GoToStart', 72 | 'PlayBackward', 73 | 'StopAnimation', 74 | 'PlayForward', 75 | 'GoToEnd', 76 | 'ToggleTrajectoryVisibility', 77 | 'AlignToEdge', 78 | 'Rotate15', 79 | 'PointToPoint', 80 | 'PlaceConcentric', 81 | 'LoadExampleFile'] 82 | 83 | self.appendToolbar('ExplodedAssemblyCreationTools', self.CreationTools) 84 | #self.appendToolbar('ExplodedAssemblyCameraTools', self.CameraAnimation) 85 | self.appendToolbar('ExplodedAssemblyAnimationControlTools', self.AnimationControlTools) 86 | self.appendToolbar('ExplodedAssemblyAuxiliarAssemblyTools', self.AuxiliaryAssemblyTools) 87 | self.appendMenu('ExplodedAssembly', self.Menu_tools) 88 | 89 | def Activated(self): 90 | import ExplodedAssembly as ea 91 | if not(FreeCAD.ActiveDocument): 92 | FreeCAD.newDocument() 93 | 94 | ea.checkDocumentStructure() 95 | FreeCAD.Console.PrintMessage('Exploded Assembly workbench loaded\n') 96 | 97 | 98 | FreeCADGui.addWorkbench(ExplodedAssembly) 99 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Exploded Assembly 2 | FreeCAD workbench to create exploded views and animations of assemblies. 3 | 4 | ![ExplodedAssembly Icon](https://cloud.githubusercontent.com/assets/4140247/26527312/3388059a-435f-11e7-8317-10e041f18d35.PNG) The Exploded Assembly icon. 5 | 6 | ![show](https://cloud.githubusercontent.com/assets/4140247/26527729/1cde4544-4368-11e7-9c85-03f974680ad8.PNG) 7 | 8 | Watch a [screencast of Exploded Assembly](https://www.youtube.com/watch?v=lzYR7I2h7KQ) 9 | 10 | **Important note: This repository replaces the now obsolete (https://github.com/JMG1/FreeCAD_ExplodedAssemblyAnimationWorkbench)** 11 | 12 | ### Features 13 | * Create nice explosions of assemblies graphically (no code at all!) 14 | * Create sub-exploded groups 15 | * Give rotation to screws and nuts for realistic disassembles 16 | * Use the provided auxiliary assembly tools to place your parts together 17 | * TODO feature: create trajectory from wires and sketches 18 | 19 | ### Installation 20 | ##### Automatically via Addon Manager (Recommended) 21 | As of FreeCAD v0.17.9944 the new Addon Manager has been merged. Install this addon by: 22 | - Opening **Tools** > **Addon Manager** 23 | - Locating **ExplodedAssembly** and installing. 24 | - Relaunching FreeCAD. 25 | 26 | ##### Manually install using git 27 | Instructions for Ubuntu & Mint specifically but can be adapted to other distros. 28 | - Open the command prompt (terminal) with the keys **ctrl+alt+t** 29 | - Install git: ***sudo apt-get install git*** 30 | - Clone repository: ***git clone https://github.com/JMG1/ExplodedAssembly ~/.FreeCAD/Mod/ExplodedAssembly*** 31 | - Relaunch FreeCAD (workbench should be incorporated automagically). 32 | 33 | ##### Manually install via ZIP 34 | - Download https://github.com/JMG1/ExplodedAssembly as a ZIP (click 'Clone or Download' button) 35 | - For Ubuntu, Mint and similar OS's, extract it inside */home/username/.FreeCAD/Mod* 36 | - For Windows, extract it inside *drive: \Users\your_user_name\AppData\Roaming\FreeCAD\Mod* 37 | Then 38 | - Relaunch FreeCAD (workbench should be incorporated automagically). 39 | 40 | ### Basic usage 41 | 42 | #### Run example file 43 | 1. Check the provided 'example.fcstd'. 44 | 2. Load the workbench and then click on "Load Example File" inside the workbench drowpdown menu. 45 | 46 | ![example file](https://cloud.githubusercontent.com/assets/4140247/26527781/1ea3f7ba-4369-11e7-90cb-2c85a09e878f.PNG) 47 | 48 | Watch the [Exploded Assembly workflow screencast](https://www.youtube.com/watch?v=t72qdG772Q8&feature=youtu.be). 49 | 50 | #### Create Simple Group 51 | #### To explode a single object: 52 | 1. Select the objects you want to explode 53 | 2. If the selected object is of type "Body", the selected face will be used as a normal 54 | 3. If you want to explode an object of type "Part" (contains other objects), select the Part object and then a face to be used as normal vector. 55 | 4. Several parameters can be modified at the properties of the single group (direction, speed, rotation...) 56 | 57 | ##### To explode several objects 58 | 1. Select the objects you want to explode in the same direction (type of objects allowed are Body and Part) 59 | 2. Select one face to use its normal as direction 60 | 3. Press the icon **Create Simple Group** 61 | 4. You can change the direction vectors and other parameters at the properties of the single group 62 | 63 | #### Create Bolt Group 64 | Bolt groups allow to rotate several screws/nuts/bolts around its own axis while moving. To create a Bolt Group: 65 | 1. Select one circular edge of each the bolts you want to animate 66 | 2. Select one face (arbitrary shape) wich has as normal vector in the direction in wich you want to move the selected bolts 67 | 3. Press the icon **Create Bolt Group** 68 | 4. You can change the direction vectors and other parameters at the properties of the single group 69 | 70 | 71 | ### Documentation 72 | Wiki documentation will be available soon. 73 | 74 | ### Feedback 75 | For bugs please open a ticket in the [issue queue](https://github.com/JMG1/ExplodedAssembly/issues). For discussion please use the [dedicated Exploded Assembly thread](https://forum.freecadweb.org/viewtopic.php?f=24&t=9028) in the FreeCAD forums. 76 | 77 | #### License 78 | LGPLv2.1 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /example.fcstd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JMG1/ExplodedAssembly/781a3ff6b4d4778f1f6df7b91a28dd3e4edbccbd/example.fcstd -------------------------------------------------------------------------------- /icons/AlignToEdge.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 62 | 68 | 74 | 80 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /icons/AnimationCamera.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 78 | 83 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /icons/AnimationCameraEdge.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 78 | 83 | 88 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /icons/AnimationCameraFollow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 78 | 83 | 90 | 96 | 103 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /icons/AnimationCameraManual.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 81 | 88 | 95 | 100 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /icons/BoltGroup.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 62 | 70 | 78 | 84 | 92 | 100 | 106 | 114 | 122 | 128 | 136 | 144 | 150 | 156 | 162 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /icons/ExplodeToSelection.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 78 | 85 | 92 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /icons/GoToEnd.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 77 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /icons/GoToStart.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 77 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /icons/ModifyIndividualObjectTrajectory.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 78 | 85 | 92 | 98 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /icons/Pause.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 77 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /icons/PlaceBeforeTrajectory.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 78 | 85 | 91 | 96 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /icons/PlayBackward.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /icons/PlayForward.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /icons/Rotate90.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 29 | 34 | 35 | 43 | 48 | 49 | 57 | 62 | 63 | 64 | 83 | 85 | 86 | 88 | image/svg+xml 89 | 91 | 92 | 93 | 94 | 95 | 99 | 106 | 112 | 117 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /icons/ShareCenter.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 64 | 72 | 77 | 84 | 91 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /icons/SharePoint.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 63 | 70 | 76 | 82 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /icons/SimpleGroup.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 79 | 87 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /icons/TrajectoryEdit.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 28 | 35 | 36 | 55 | 57 | 58 | 60 | image/svg+xml 61 | 63 | 64 | 65 | 66 | 67 | 71 | 77 | 84 | 90 | 96 | 102 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /icons/TrajectoryLineVisibility.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 61 | 67 | 74 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /icons/WireTrajectory.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 22 | 29 | 36 | 39 | 43 | 47 | 48 | 50 | 54 | 58 | 59 | 69 | 76 | 87 | 88 | 107 | 109 | 110 | 112 | image/svg+xml 113 | 115 | 116 | 117 | 118 | 119 | 123 | 129 | 136 | 140 | 146 | 153 | 160 | 177 | 194 | 212 | 213 | 214 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /icons/WorkbenchIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 40 | 42 | 43 | 45 | image/svg+xml 46 | 48 | 49 | 50 | 51 | 52 | 56 | 64 | 72 | 79 | 86 | 93 | 99 | 105 | 111 | 112 | 113 | --------------------------------------------------------------------------------