Sure, I'll add it in the next release.
Code: Select all
import FreeCAD, FreeCADGui, Part def copy_obj(parentObj=None,doc=None,subname=''): if not doc: # 'doc' allows you to copy object into another document. # If not give, then use the current document. doc = FreeCAD.ActiveDocument if not parentObj: # If no object is given, then obtain selection from all opened document parentObj =  for sel in FreeCADGui.Selection.getSelectionEx('*'): parentObj.append(sel.Object) if not parentObj: return if isinstance(parentObj,(tuple,list)): if len(parentObj) == 1: copy = copy_obj(parentObj,doc) else: part = doc.addObject('App::Part','Part') for o in parentObj: copy = copy_obj(o,doc) if copy: part.addObject(copy) copy = part if copy: FreeCADGui.SendMsgToActiveView("ViewFit") copy.recompute(True) return copy obj,matrix = parentObj.getSubObject(subname,1,FreeCAD.Matrix(),not subname) if not obj: return # getSubObjects() is the API for getting child of a group. It returns a list # of subnames, and the subname inside may contain more than one levels of # hierarchy. Assembly uses this API to skip hierarchy to PartGroup. subs = obj.getSubObjects() if not subs: # Non group object will return empty subs shape = Part.getShape(obj,transform=False) if shape.isNull(): return shape.transformShape(matrix,False,True) copy = doc.addObject('Part::Feature',obj.Name) copy.Label = obj.Label copy.Shape = shape copy.ViewObject.mapShapeColors(obj.Document) return copy part = doc.addObject('App::Part',obj.Name) part.Label = obj.Label part.Placement = FreeCAD.Placement(matrix) for sub in subs: sobj,parent,childName,_ = obj.resolve(sub) if not sobj: continue copy = copy_obj(obj,doc,sub) if not copy: continue vis = parent.isElementVisible(childName) if vis < 0: copy.Visibility = sobj.Visibility else: copy.Visibility = vis>0 part.addObject(copy) return part copy_obj()
Thanks for your lengthy feedback.OakLD wrote: ↑Thu Jun 21, 2018 9:59 amOnce again, Realthnder and the comunity, congratulations to the progress! It's a much better experience, testing assemblies, compared to 3-4 months ago. I tested few assemblies in the new releases and have some feedback bellow.
Following points of possible improvements are not criticism, I would like to just inspire a little discussion on the subjects, perhaps it might help little bit.
I actually tried this in early stage of development, when the solver didn't work quite well yet. And the results is not that good at the time. I may try that again some time. Maybe study more about how SolveSpace itself handle this situation.1. Singularities - even though this improved significantly, I still get a lot of errors like "Solver error", which are usually easy to resolve by re-positioning parts. Often a tiny, bearly noticeable change resolves the problem. This is probably the solver problem and it is unlikely to be possible to tackle it directly in FC. However, I'd think it should be possible and suggest to catch the error and in such an event, change the input conditions by slight modification of input conditions
This sounds like a bug. It would be better if you can post a file to demonstrate the problem. And maybe some screencast to show your steps.A comment to the error: Interesting thing is, that when I opened and closed FC, I got different solver error message with the same configuration "Constraint PlaneAlignment requires at least two elements."
You can either a) turn off auto recompute, and use mover to (roughly) pre-align the part to your desired configuration, and then hit recompute button, or b) turn on auto recompute, and use mover to rotate the part. When rotate pass some threshold, it will flip. What the software does behind the scene is that, it will move the part with your mouse, and call the solver. If the solver fail (which is made silent and hidden from user), the part position will be reset. So the end user won't see the movement, but it does move behind the scene, kind of like method a), and I believe that is how SolveSpace handle this, too.2. Positioning - some constraints have multiple "solutions", that means i.e. in case of "PlaneAlignment" that both combinations of normals direction (Aligned and Opposite) are possible. Once the constraint is set, it doesn't (at least I didn't find a way) allow to flip it to the other configuration.
For some constraint, this can work, and I'll try it someday. Maybe you can open an issue in github for that.Also, some configurations require to position the parts in certain way. Implementation of point (1) should cause, that in any case parts would be aligned (to one of possible configuration). I would suggest to add a "Flip" button
You suggestion will not work well in nested assemblies. Remember that a 'part' can be repeatedly used in many different places, say a screw. The screw has the same geometry element for constraining with others, but each instance will certainly connect to an element of a different part. In other word, one of the elements in the constraint will be different each time the instance is used, so it cannot be grouped with the 'part'.3. Tree - it appears to me, that the "Assembly" node contains a tree, which is rather technical and unrelated to the user's needs. This has nothing to do with the structure it self, I think it works fine, but it deserves a different presentation to the user. For instance, the constraints are practically untraceable to the parts they are constraining, elements are abstract things not related to users work, parts contain whole tree which is only making things less transparent. Thus, I'd suggest a discussion about hiding this tree (in future) and replacing it with a tree (and I mean just a visual layer, not a change in assembly desing) that user wants:
Assembly --> Parts --> Constraints --> Constrained Elements
If you see this message, then there is definitely redundancy. It is not always intuitive, but if you carefully count the DOFs, you'll see. But yeah, I probably should not make that as a warning message.4. "Redundant Constraints" message
Is the message harmless?
I'll add that support in Techdraw later.5. Drawing - probably the most serious problem at this stage is that the assembly cannot be placed into drawing (or did I failed to do it correctly?). "Assembly" would allow to start "Insert ortographic projections..." command, but would result in an empty views.
Switch to Part workbench. Select the assembly you want to merge in the tree view. In the Main window menu, select 'Part -> Create a copy -> Create simple copy'. You will get a single Shape of that assembly.6. Merging - is there or would there be a way to merge particular parts ("bodies") into one body, when assembled this way? One reason for that I can imagine is a FEM analysis, where one wants to assess a body with ribs and brackets as a one solid thing...
Well, it is because I added the delay to not overload the system with recompute of every tiny move. I'll expose the delay in setting later.7. Moving parts - hopefully this feature wouldn't be needed that much in future. However, now it is used a lot and I experience very slow response. It takes few seconds when an object is moved or rotated to see the result on the screen.
I'll improve that later.8. Recomputing buttons - this is a tiny detail, but I noticed, that when set to auto-recompute, it sometimes recomputes the solution and sometimes not. The same with changing constraint parameters (hitting Enter after a change is more likely to invoke recomputing). I think this option might get redundant in time, becasue one always wants to recompute, not only to see the result instantly, but most importantly to discover errors right when produced and not after he does more work.
That is most likely a bug. I'd appreciate if you can post a file to demonstrate this problem. Or, since the problem is gone after reopen the file, maybe recall the steps triggering this problem.jpg87 wrote: ↑Thu Jun 21, 2018 6:44 pmA note for the construction of the assembly: towards the end, the solver no longer caused the placing of parts according to the constraints. I had to record, close the files. Then at the reopening of the assembly, a recalculation of the solver and everything was put in place.
Yes, I'll definitely add that function later.- Is it possible (or is it planned) to motorize some DOF to animate the whole?
I'll add that support in TechDraw later. Meanwhile, you can either use the Macro easyw-fc mentioned, or go to Part workbench, and use menu action Part -> Create a copy -> Create simple copy to get a merged shape.- what to select in TechDraw to get projected views? I tried various possibilities without success.