[App::Link] Link Execute Property [SOLVED]

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
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

[App::Link] Link Execute Property [SOLVED]

Post by gbroques »

What does the "Link Execute" property do and when would you want to use it?

From Std_LinkMake, it says:
name of the execute function that will run for this particular Link object. It defaults to appLinkExecute. Set it to None to disable it.
It's not very clear what the intention was behind exposing the ability for an end-user to reference a global replacement execute function.

I'm assuming this is similar to Scripted objects and execute for Link objects is called on every recompute.

What does the default appLinkExecute function do? Are there any caveats when you choose to override it?
realthunder wrote: :bell:
Last edited by gbroques on Wed Mar 24, 2021 11:40 pm, edited 2 times in total.
paullee
Veteran
Posts: 5136
Joined: Wed May 04, 2016 3:58 pm

Re: [App::Link] Link Execute Property

Post by paullee »

This should be where it begins :D before Realthunder can explain more -


[Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?
User avatar
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: [App::Link] Link Execute Property

Post by gbroques »

paullee wrote: Tue Mar 23, 2021 1:25 pm This should be where it begins :D before Realthunder can explain more -


[Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?
Thanks Paullee! :)

You seemed to have planted this idea in this post:
paullee wrote: Wed Jan 15, 2020 9:51 pm Thanks mentoring :) Not directly calling execute() indeed. I have a more general idea about how Link should better working calling methods() in LinkObject below... make sense ? ...


Make sense ?

And should stock Link already can do this instead of making a general LinkPython ?
Then the reply was:
realthunder wrote: Fri Jan 17, 2020 12:30 am That is actually not a bad idea. I'll add that feature, so that Link's execute() function will search and run python method in linked object with name 'appLinkExecute', passing the linked object and the Link itself as input arguments. For array elements, it will pass two additional parameters as parent link object, and element index. The method will look something like this,

Code: Select all

class _Window:
	def appLinkExecute(self, obj, linkObj, linkParent, index):
		pass
Maybe you can try explaining at a high-level what this is for, or the problem you ran into in a concise and generally-applicable way?

It's a bit tiresome for me to try and sift through that thread to gain an understanding of this.

Seems to have something to do with using Std Link in conjunction with Scripted objects or FeaturePython Objects, and the "proxy methods" being stripped or inaccessible.
paullee
Veteran
Posts: 5136
Joined: Wed May 04, 2016 3:58 pm

Re: [App::Link] Link Execute Property

Post by paullee »

gbroques wrote: Tue Mar 23, 2021 6:03 pm Seems to have something to do with using Std Link in conjunction with Scripted objects or FeaturePython Objects, and the "proxy methods" being stripped or inaccessible.
Yes it is like the way you describe.

To my understanding, it allow some 'features' of a FeaturePython objects to works in a Link. E.g. I make Arch Windows to auto placing itself to its Host object in a Method. Without the appLinkExecute, its Links would not know it should execute this and the Links would not update its placement likewise.

Realthunder would explain the potential and mechanism in details :D
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: [App::Link] Link Execute Property

Post by realthunder »

paullee wrote: Tue Mar 23, 2021 11:52 pm
gbroques wrote: Tue Mar 23, 2021 6:03 pm Seems to have something to do with using Std Link in conjunction with Scripted objects or FeaturePython Objects, and the "proxy methods" being stripped or inaccessible.
Yes it is like the way you describe.

To my understanding, it allow some 'features' of a FeaturePython objects to works in a Link. E.g. I make Arch Windows to auto placing itself to its Host object in a Method. Without the appLinkExecute, its Links would not know it should execute this and the Links would not update its placement likewise.

Realthunder would explain the potential and mechanism in details :D
Yes that's pretty much it. If you are creating a python extension object for your own workbench, you can define a customized behavior when a Link is created and links to your object. You don't need to create yet another python extension for a new type of Link. The default behavior for Link when recomputed is to look for a method called 'appLinkExecute' in the linked object's python extension (i.e. the Proxy object), and execute it if found.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: [App::Link] Link Execute Property

Post by gbroques »

realthunder wrote: Wed Mar 24, 2021 3:34 am Yes that's pretty much it. If you are creating a python extension object for your own workbench, you can define a customized behavior when a Link is created and links to your object. You don't need to create yet another python extension for a new type of Link. The default behavior for Link when recomputed is to look for a method called 'appLinkExecute' in the linked object's python extension (i.e. the Proxy object), and execute it if found.
Thank you both for the clarifications!
Post Reply