Using Transform tool with a group object.

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
prandall
Posts: 76
Joined: Thu Feb 16, 2017 12:42 pm
Contact:

Using Transform tool with a group object.

Post by prandall »

Hello All,

I am trying to add a Placement to a Group object. I would like to be able to use the transform tool like it is used in the Arch work bench.

Something like this:

Code: Select all

obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython", "Test")
obj.addProperty("App::PropertyPlacement","Placement","Base","Location of this Member")
However adding a Placement object doesn't trigger the Transform tool context menu item. So I am trying to determine how to add that to the context menu.

Group object ( as building ) showing Transform option
Selection_253.png
Selection_253.png (43.93 KiB) Viewed 2134 times
Group object added with code , no Transform Tool
Selection_254.png
Selection_254.png (33.27 KiB) Viewed 2134 times


OS: Linux Mint 19
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4.
Build type: Release
Python version: 3.6.8
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
3D Printing, CAD, Electronics and other errata at: https://www.youtube.com/channel/mathcodeprint
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Using Transform tool with a group object.

Post by carlopav »

Maybe here you can find something of your interest:
https://forum.freecadweb.org/viewtopic. ... 255#p83319
follow my experiments on BIM modelling for architecture design
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Using Transform tool with a group object.

Post by vocx »

prandall wrote: Sat Nov 30, 2019 5:08 pm Hello All,

I am trying to add a Placement to a Group object. I would like to be able to use the transform tool like it is used in the Arch work bench.

Something like this:

Code: Select all

obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython", "Test")
obj.addProperty("App::PropertyPlacement","Placement","Base","Location of this Member")
...
I'm not sure how to achieve what you want, but maybe you can investigate the code of Arch Building for clues.

The old Arch Building is a class of type ArchBuilding._Building. It creates an object derived from a Std_Group, that is, App::DocumentObjectGroupPython.

Code: Select all

def makeBuilding(objectslist=None,baseobj=None,name="Building"):
    if not FreeCAD.ActiveDocument:
        FreeCAD.Console.PrintError("No active document. Aborting\n")
        return
    obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython","Building")
    _Building(obj)
However, the newer Arch Building is derived from Arch BuildingPart.

https://github.com/FreeCAD/FreeCAD/blob ... #L232-L238

Code: Select all

def makeBuilding(objectslist=None,baseobj=None,name="Building"):
    """overwrites ArchBuilding.makeBuilding"""
    obj = makeBuildingPart(objectslist)
    obj.Label = name
    obj.IfcType = "Building"
The BuildingPart is a class of type ArchBuildingPart.BuildingPart. It creates an object derived from App::GeometryPython

https://github.com/FreeCAD/FreeCAD/blob ... #L202-L210

Code: Select all

def makeBuildingPart(objectslist=None,baseobj=None,name="BuildingPart"):
    obj = FreeCAD.ActiveDocument.addObject("App::GeometryPython","BuildingPart")
    #obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","BuildingPart")
    obj.Label = translate("Arch","BuildingPart")
    BuildingPart(obj)
Then this object is extended by an App::GroupExtensionPython.

https://github.com/FreeCAD/FreeCAD/blob ... #L319-L329

Code: Select all

class BuildingPart(ArchIFC.IfcProduct):
    def __init__(self,obj):
        obj.Proxy = self
        obj.addExtension('App::GroupExtensionPython', self)
        #obj.addExtension('App::OriginGroupExtensionPython', self)
        self.setProperties(obj)
This sounds to me that you can do the same: create a basic App::GeometryPython object, and then extend it to behave as a group.

The other alternative is the opposite way, which is what you proposed initially: create a basic group, and then extend it with the correct class (GeometryExtension or something like that?).
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
chrisb
Veteran
Posts: 54288
Joined: Tue Mar 17, 2015 9:14 am

Re: Using Transform tool with a group object.

Post by chrisb »

prandall wrote: Sat Nov 30, 2019 5:08 pm I am trying to add a Placement to a Group object. I would like to be able to use the transform tool like it is used in the Arch work bench.
A group can - besides grouping - do almost nothing, just control visibility. The modern replacement is the Std Part container (Yellow stair icon). It has its own Placement and can move all the objects inside relative to its own coordinate system.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Using Transform tool with a group object.

Post by carlopav »

chrisb wrote: Sun Dec 01, 2019 8:37 am A group can - besides grouping - do almost nothing, just control visibility. The modern replacement is the Std Part container (Yellow stair icon). It has its own Placement and can move all the objects inside relative to its own coordinate system.
Indeed that's an interesting observation.
I agree that App::Part should be a better thing to use. However in most arch module Yorik decided to use groups instead, mainly because he pointed out that if you have to frequently move objects inside and outside parts they dont keep their position but are moved according to part origin. And also they don't remember their global placement.
To propagate placement from the group to the children, arch component, onBeforeChange store old placement, and onChanged evaluate Placement changes and propagate it to children.
I think app::part would simplify things a lot... But probably I'm not considering all the aspects of the problem.
follow my experiments on BIM modelling for architecture design
chrisb
Veteran
Posts: 54288
Joined: Tue Mar 17, 2015 9:14 am

Re: Using Transform tool with a group object.

Post by chrisb »

I'm not familiar with Arch, so I cannot comment. I had understood that prandall wanted to use something he new from Arch in a different workbench.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
prandall
Posts: 76
Joined: Thu Feb 16, 2017 12:42 pm
Contact:

Re: Using Transform tool with a group object.

Post by prandall »

Thanks for all the replies. The very simple reason why I am trying to use groups is that I was unable to "easily" change the icon on the Part object. AS I had already learned the approach for the custom icon for group I wanted to go with that approach. I didn't want to go on a side quest to figure out "Part", yet.

I think my answer lies in carlovpav's reply which addresses how the context menu is called. The navigation style queries the workbench, so I have to figure out how to give it the correct answer.

To vcx, I was in fact looking at the Arch_Building object and not BuildingPart, so I will have to take a second look.

chrisb, I would like to uses the Std Part eventually, the workbench I am writing is an educational excersize for me and hopefully useful to others. I am forcing myself to work through understanding the mysteries of Placement :)

Thanks so much to all for some direction. Today i explore !
3D Printing, CAD, Electronics and other errata at: https://www.youtube.com/channel/mathcodeprint
Post Reply