Reference to a list of edges in parametric feature

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
hkroeger
Posts: 15
Joined: Mon Jan 13, 2014 1:27 pm

Reference to a list of edges in parametric feature

Post by hkroeger »

Dear experts,

I would like to create a parametric feature in python. I followed the documentation in http://www.freecadweb.org/wiki/index.ph ... ed_objects and the examples in the mentioned subdirectory "TemplatePyMod". So far I understood how to create a solid body and use numeric parameters for that.

Now I would like pick some edges of a solid and do some processing with them. I'm not sure which is the right Property for that. Is it "App::PropertyLinkSubList"? If I add that to my feature, it does not appear in the properties table and I cannot edit it. I searched the sources for an appropriate example, but didn't find one.

Can someone give me a hint how to proceed? Any suggestions are welcome.

Regards, Hannes
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Reference to a list of edges in parametric feature

Post by ulrich1a »

You may have a look at macro recipes: http://www.freecadweb.org/wiki/index.ph ... os_recipes
There are some macros, which works with user selected objects, for example Macro_FCInfo.

Ulrich
hkroeger
Posts: 15
Joined: Mon Jan 13, 2014 1:27 pm

Re: Reference to a list of edges in parametric feature

Post by hkroeger »

Dear Ulrich,

thanks for your hint. I must add that I already managed to do extract the edges in the way of a macro (using the getSelectionEx function).

But the code is executed only once and if I change the dimensions of the base object, the result of my processing is not updated, it remains static. Now I wanted to extend my application into a parametric feature, i.e. I wanted to select the edges once, store the reference somehow and get my feature updated every time I change the base feature.

Meanwhile I found something similar in the "PathArray" feature of the "Draft" workbench. I adapted it to my case and it works. But the selection of the edges there is made before the new feature is created and I do not see a way to change the selection after my feature is created. Is it possible that I miss something?

Regards, Hannes
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Reference to a list of edges in parametric feature

Post by ulrich1a »

Dear Hannes,
I have to admit, that I am not an experienced programmer. So it may point to something wrong. My one experiment with FeaturePython showed me, that this is a complicate matter.

I had a look to the class Octahedron in FeaturePython.py. There is a reference to a shape stored as property. In updateData you may need to write code to make a new processing. I think you need some extra gui-code, that make changes to this property based on the getSelectionEx function. And I do not remember any function in FreeCAD, that lets you change references to objects on the fly.
Here is some help from the real experts needed. How you can get a button for example in the Data-properties for a call to your new selection gui. If it not exists, you can make a feature-request on the Mantis-bug-tracker.
So unfortunately I can give no real help.
Regards, Ulrich
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Reference to a list of edges in parametric feature

Post by jmaustpc »

The sub components of a shape get a name (from oce/occ), this name is numbered in a at least partly random manor. Any change to the solid can mean that the names of the edges etc. are changed in undefinable way.

There has been lots of talk and coding regarding this issue, I think Jan has done it all, at least most of it, its called "topological naming" or something like that. It will be in future versions of FreeCAD, possibly the next version.

I suggest you search for it in these forums. I think you will find that this is a limiting factor for what you are trying to do, if I am understanding correctly what you are trying to do. :)

Jim
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Reference to a list of edges in parametric feature

Post by wmayer »

I'm not sure which is the right Property for that. Is it "App::PropertyLinkSubList"? If I add that to my feature, it does not appear in the properties table and I cannot edit it.
This is because we do not yet have implemented an editor for this property type.
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Reference to a list of edges in parametric feature

Post by wandererfan »

hkroeger wrote:Meanwhile I found something similar in the "PathArray" feature of the "Draft" workbench. I adapted it to my case and it works. But the selection of the edges there is made before the new feature is created and I do not see a way to change the selection after my feature is created. Is it possible that I miss something?

Regards, Hannes
Probably something to do with the onChanged method. PathArray only recreates itself for some properties.

Code: Select all

    def onChanged(self,obj,prop):
        if prop in ["Count","Xlate","Align"]:
            self.createGeometry(obj)
If I get some time, I'll look into what happens if we add "Base" or "PathSubs" the the onChanged list.

wf
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Reference to a list of edges in parametric feature

Post by wandererfan »

wandererfan wrote:Probably something to do with the onChanged method. PathArray only recreates itself for some properties.
Sorry, that's not it. Changing Base, Path or PathSubs properties rebuilds the PathArray even though they are not in the onChanged list.
hkroeger
Posts: 15
Joined: Mon Jan 13, 2014 1:27 pm

Re: Reference to a list of edges in parametric feature

Post by hkroeger »

Dear wmayer,

ok, I understand. The same seems to apply for the PropertyLink (link to another shape, right?). If I use it, it is listed in the property table and a link "Edit..." is shown, but if I click on it, a disappointing message appears ;-)
Is that just because the editor was not necessary so far, or is there some conceptual difficulty with its implementation?

@jmaustpc: I'm aware of the topological naming problem and its implications, but the same should affect e.g. the fillet feature. But I see it is solved there somehow.

Indeed, I was thinking of implementing something similar like the fillet feature: selecting a list of edges and use them as inputs. In the fillet feature, there seems to be some extra gui code involved (haven't look in detail at it yet). Could something similar be made purely in python? Is there an example somewhere?

Thanks and regards, Hannes
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Reference to a list of edges in parametric feature

Post by wmayer »

Is that just because the editor was not necessary so far, or is there some conceptual difficulty with its implementation?
Yes, it's just laziness :D
Post Reply