Part-o-magic (again) [icon ideas for new tool wanted!]

Need help, or want to share a macro? Post here!
DeepSOIC
Posts: 4462
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Part-o-magic (again) [icon ideas for new tool wanted!]

Postby DeepSOIC » Thu Feb 16, 2017 12:33 am

Hi!
I've updated Part-o-magic to work with Extension-powered containers. But more importantly, Part-o-magic now offers a new object container! I called it "Module". It's an analog of PartDesign Body, but made for Part workbench and any other wb that makes shapes (e.g. Draft, Lattice). This can also be an example of how does one make a python-powered container (see https://github.com/DeepSOIC/Part-o-magi ... /Module.py)

Install:
https://github.com/DeepSOIC/Part-o-magic
Use FreeCAD's built-in add-on manager (menu Tools->Addon manager).

After installing PoM, restart FreeCAD.
* Part-o-magic workbench should appear in workbench selector.
* A small global toolbar should appear, which you can disable or customize in Tools->Customize->Toolbars.
* Behavior of PartDesign workbench should change drastically, that is due to Observer running.
part-o-magic toolbar.png
part-o-magic toolbar.png (397.76 KiB) Viewed 753 times


Uninstall:
You can disable part-o-magic with buttons on the workbench. If you disable the workbench, all the automation stuff should switch off, but features of part-o-magic can still be recomputed in your projects that have them.

If you completely uninstall the workbench (delete Mod/Part-o-magic folder), part-o-magic features you used in your projects will stop working.

Important. Part-o-magic messes with "DisplayModeBody" properties of PartDesign Body objects, and "Selectable" properties of all objects. If you uninstall Part-o-magic, or disable its automation stuff, it will cause somewhat unusual behavior of any projects that were saved with part-o-magic enabled and had any container objects present. You can reset them manually with property editor, or run this simple snippet in Py console:

Code: Select all

for obj in App.ActiveDocument.Objects:
    if hasattr(obj.ViewObject, "DisplayModeBody"):
        obj.ViewObject.DisplayModeBody = "Through"
    if hasattr(obj.ViewObject, "Selectable"):
        obj.ViewObject.Selectable = True



Main features:

"Observer"
* Active container everywhere:
In PartDesign, all new features are automatically added to Body. Observer expands this to all workbenches of FreeCAD: new objects, made in any workbench, are automatically added to active container.
* Visibility automation:
when you activate a container, the container is switched into Through mode, so you see individual contained objects. When you leave it, you see only the final shape (Tip), but not contained objects. Also, when you activate a container, anything outside of it is automatically hidden, so that you can focus on editing the piece.
* Tree automation:
when you activate a container, it is automatically expanded in tree. When deactivated, it is automatically collapsed. With the aim to show you only the features that make up the container, so that you can focus on editing the piece.

Containers
* Module container
It's an analog of PartDesign Body, but for Part and other workbenches. It groups together features that were used to create a final shape, and exposes the final shape (Tip) as its own.
* ShapeGroup container
(similar to Module, but exposing multiple objects)
* PartDesign Additive shape, PartDesign Subtractive shape containers
These are Modules that pretend to be PartDesign features, allowing to integrate other workbench tools into PartDesign workflow. See tutorial post later in this thread.

Other features:
* tool for altering Tip
* buttons to enter and leave objects (can be used to enter/leave containers, and edit objects (e.g. open a sketch))
* button to create Part container
* button to create Shapebinders (works outside of PartDesign, too).
* Exporter feature, for keeping exported files up to date with project. See this post.
* buttons to disable Part-o-magic (there's a good chance part-o-magic will break soon). If disabled, Module containers should still work, albeit not very useful because they rely on part-o-magic's automatic object addition.

Limitations/ known bugs
* will be confused by Groups (probably; untested). This may soon be fixed... when visibility behavior of groups will be changed to match that of Parts

Future plans: (hahaha, things rarely go as planned)
* attachable version of Module, and integration with Lattice, to provide somewhat useful assembly capabilities

The overall goal of doing this was to get some sense of what it takes to create a python powered object container. As well as gain some insights to what interfaces are needed for implementing something like this in FreeCAD itself.
DeepSOIC
Posts: 4462
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Part-o-magic (again)

Postby DeepSOIC » Thu Feb 16, 2017 12:41 am

Interfaces I created for Mocule container, that are emulated by Part-o-magic:

Code: Select all

class _Module:
    ...
    def advanceTip(self, selfobj, new_object):
       # called after a new object was created in this container, and established links
       # to others (the established links are useful for tip advancement logic)
        print("advanceTip")


class _ViewProviderModule:
    ...
    def activationChanged(self, vobj, old_active_container, new_active_container, event):
        # called in an event of changed active container.
        # event: -1 = leaving (active container was self or another container inside, new container is outside)
        #        +1 = entering (active container was outside, new active container is inside)
        # note that self is not necessarily in [old_active_container, new_active_container].
       
        changeDisplayMode(...)
        visibilityAutomation(...) # part-o-magic does it all itself now, but for main FC, I think
                                  #it is useful to make containers take care of it
       
User avatar
easyw-fc
Posts: 601
Joined: Thu Jul 09, 2015 9:34 am

Re: Part-o-magic (again)

Postby easyw-fc » Thu Feb 16, 2017 9:25 am

DeepSOIC wrote:Hi!
I've updated Part-o-magic to work with Extension-powered containers. But more importantly, Part-o-magic now offers a new object container! I called it "Module". It's an analog of PartDesign Body, but made for Part workbench and any other wb that makes shapes (e.g. Draft, Lattice). This can also be an example of how does one make a python-powered container (see https://github.com/DeepSOIC/Part-o-magi ... /Module.py)

Install:
Download from https://github.com/DeepSOIC/Part-o-magic
Install as a workbench. That is, in Path/To/Macros/Mod, create a directory named Part-o-magic, and put the contents of repository there. Restart FreeCAD. Part-o-magic workbench should appear in workbench selector.

Main features:
* New objects, made in any workbench, are automatically added to active container.
* Visibility automation: when you activate a container, the container is switched into Through mode, so you see individual contained objects. When you leave it, you see only the final shape (Tip), but not contained objects. Also, when you activate a container, anything outside of it is automatically hidden, so that you can focus on editing the piece.
* Module container, analog of PartDesign Body, but for Part and other workbenches.

Other features:
* tool for altering Tip
* buttons to enter and leave objects (can be used to enter/leave containers, and edit objects (e.g. open a sketch))
* button to create Part container
* button to create Shapebinders (works outside of PartDesign, too).
* buttons to disable Part-o-magic (there's a good chance part-o-magic will break soon). If disabled, Module containers should still work, albeit not very useful because they rely on part-o-magic's automatic object addition.

Limitations/ known bugs:
* will be confused by Groups (probably; untested). This may soon be fixed... when visibility behavior of groups will be changed to match that of Parts

Future plans:
* attachable version of Module, and integration with Lattice, to provide somewhat useful assembly capabilities

The overall goal of doing this was to get some sense of what it takes to create a python powered object container. As well as gain some insights to what interfaces are needed for implementing something like this in FreeCAD itself.

Hi @DeepSOIC
I'm trying to install Part-o-magic in FC 0.17 win64
I downloaded the Part-o-magic-master.zip, extracted Part-o-magic-master
copied to C:\Users\userC\AppData\Roaming\FreeCAD\Mod\Part-o-magic (renamed Part-o-magic-master to Part-o-magic)
started FC and activated the PoM WB
I get the following errors in Report view
Unknown command 'PartDesign_Part'
Unknown command 'PartDesign_Body'
Cannot find icon: :/icons/PartDesign_Body_Create_New.svg
Cannot find icon: :/icons/PartDesign_ShapeBinder.svg
Cannot find icon: :/icons/Sketcher_EditSketch.svg
Cannot find icon: :/icons/Sketcher_LeaveSketch.svg
Cannot find icon: :/icons/PartDesign_MoveTip.svg
Unknown command 'PartDesign_Part'
Unknown command 'PartDesign_Body'

am I doing something wrong?
thx
Maurice
DeepSOIC
Posts: 4462
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Part-o-magic (again)

Postby DeepSOIC » Thu Feb 16, 2017 9:51 am

Hmm, it is probably necessary to have PartDesign as start-up workbench, I'll see if I can do something about it...
DeepSOIC
Posts: 4462
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Part-o-magic (again)

Postby DeepSOIC » Thu Feb 16, 2017 10:06 am

easyw-fc wrote:I get the following errors in Report view
Unknown command 'PartDesign_Part'
Unknown command 'PartDesign_Body'
Cannot find icon: :/icons/PartDesign_Body_Create_New.svg
Cannot find icon: :/icons/PartDesign_ShapeBinder.svg
Cannot find icon: :/icons/Sketcher_EditSketch.svg
Cannot find icon: :/icons/Sketcher_LeaveSketch.svg
Cannot find icon: :/icons/PartDesign_MoveTip.svg
Unknown command 'PartDesign_Part'
Unknown command 'PartDesign_Body'
Quick fixes:
https://github.com/DeepSOIC/Part-o-magi ... 3df668fde1
https://github.com/DeepSOIC/Part-o-magi ... 186e0dbb2c
Thanks for trying and reporting, Please try again ;)
User avatar
easyw-fc
Posts: 601
Joined: Thu Jul 09, 2015 9:34 am

Re: Part-o-magic (again)

Postby easyw-fc » Thu Feb 16, 2017 10:50 am

DeepSOIC wrote:Thanks for trying and reporting, Please try again ;)

fixed thx ;)
I'm going to play with it now! :D
M
triplus
Posts: 4842
Joined: Mon Dec 12, 2011 4:45 pm

Re: Part-o-magic (again)

Postby triplus » Thu Feb 16, 2017 6:19 pm

DeepSOIC wrote:Install:
Download from https://github.com/DeepSOIC/Part-o-magic
Install as a workbench. That is, in Path/To/Macros/Mod, create a directory named Part-o-magic, and put the contents of repository there. Restart FreeCAD. Part-o-magic workbench should appear in workbench selector.


On Linux this is much more streamlined:

Code: Select all

cd .FreeCAD/Mod/
git clone https://github.com/DeepSOIC/Part-o-magic.git


What i tested for now. I inserted new Part and added new Body (Module) to it. After i added a few Part primitives. I could move everything around by simply altering Part placement. Impressed. And no Super placement was seen anywhere and things like that. Just Placement and it did the job.

* attachable version of Module, and integration with Lattice, to provide somewhat useful assembly capabilities


To me it feels more like Assembly2 material.
User avatar
Kunda1
Posts: 621
Joined: Thu Jan 05, 2017 9:03 pm

Re: Part-o-magic (again)

Postby Kunda1 » Thu Feb 16, 2017 6:27 pm

triplus wrote:On Linux this is much more streamlined:

Code: Select all

cd .FreeCAD/Mod/
git clone https://github.com/DeepSOIC/Part-o-magic.git


Even more streamlined (1 liner):

Code: Select all

git clone https://github.com/DeepSOIC/Part-o-magic.git ~/.FreeCAD/Mod/
triplus
Posts: 4842
Joined: Mon Dec 12, 2011 4:45 pm

Re: Part-o-magic (again)

Postby triplus » Thu Feb 16, 2017 6:41 pm

I try to follow the approach "code is written once and read more times". Therefore i usually try to avoid introducing unneeded complexity. Combining two separate things into one usually comes down to introducing complexity. ;)
User avatar
easyw-fc
Posts: 601
Joined: Thu Jul 09, 2015 9:34 am

Re: Part-o-magic (again)

Postby easyw-fc » Thu Feb 16, 2017 11:07 pm

DeepSOIC wrote:But more importantly, Part-o-magic now offers a new object container! I called it "Module". It's an analog of PartDesign Body, but made for Part workbench and any other wb that makes shapes (e.g. Draft, Lattice).

I played a bit with PoM and it seems very promising...
but atm I cannot test what I would like to create...
I would need to have an App::Part container to contains other objects or even other App::Part containers...
This would be useful to be used in an assembly structure ...
I mean you can have an assembly of many objects, or have an assembly of objects and sub-assemblies
Here an example file of what I'm trying to reach, that I've built using python script
assembly-with-sub-assembly-App-Part.FCStd
(8.83 KiB) Downloaded 10 times

Other things I miss are the option to:
1) make a compound of the App::Part structure
2) make a union of the App::Part structure
3) make a simple copy of the App:Part structure (similar to Mux in assembly2)

I don't know very well the new App::Part structure and I don't know if would be possible to add these option through an evolution of Part-o-Magic or it may need modification in App::Part structure...

Adding these features I think would put Part-o-Magic and FC very close to the assembly evolution that is still missing

Thx
Maurice