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

Need help, or want to share a macro? Post here!
paullee
Posts: 2041
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee » Tue Jan 14, 2020 7:22 pm

realthunder wrote:
Tue Jan 07, 2020 1:25 am

Code: Select all

class _WindowLink:

  def execute(self, obj):
...
Just another thought reading again some fundamental python wiki for beginner, sorry if below is silly :)

About "Python extended version of App::Link" / specialized LinkPython for _Window in this discussion -

Could this custom LinkPython multiple inherit / subclass the _Window object - so the method() (automatic update of placement in my experiment) can be used in the LinkPython ?


Then I do not need to maintain the same methods but now in 2 objects (the _Window object and custom LinkPython for _Window) twice.


Thanks.
realthunder
Posts: 1345
Joined: Tue Jan 03, 2017 10:55 am

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

Post by realthunder » Tue Jan 14, 2020 10:31 pm

paullee wrote:
Tue Jan 14, 2020 7:22 pm
Could this custom LinkPython multiple inherit / subclass the _Window object - so the method() (automatic update of placement in my experiment) can be used in the LinkPython ?
Calling other Proxy's execute is not a good idea. But if you can make a method in _Windows for just the placement calculation, then you can do something like this. Make sure calculatePlacement() does not change anything internal to _Windows class, just the Placement property.

Code: Select all

class _WindowLink
	def execute(self, obj):
		if isinstance(getattr(obj.LinkedObject, 'Proxy', _Window):
			obj.LinkedObject.Proxy.calculatePlacement(obj)
Try Assembly3 (latest version 0.10.2) along 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
paullee
Posts: 2041
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee » Wed Jan 15, 2020 9:51 pm

realthunder wrote:
Tue Jan 14, 2020 10:31 pm
Calling other Proxy's execute is not a good idea. But if you can make a method in _Windows for just the placement calculation, then you can do something like this. Make sure calculatePlacement() does not change anything internal to _Windows class, just the Placement property.
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 ? ...


Pseudo-code

Code: Select all

Add a special method say LinkMethods() in every Objects for Link / LinkPython to identify this could be run 'Locally' and be called by a Link 'Remotely' in 'Child Link Instances '... 

class _Window:

	def execute(self, obj):
            ...
            self.LinkMethods(obj)
            ...

	def LinkMethods(self, obj):
            ''' Designated methods which could be called 'Locally' and also be called by a Link object to run as Child Instances '''

            self.LinkAddProperties(obj)
            self.LinkCalculateShape(obj)
            self.LinkCalculatePlacement(obj)
           
        @staticmethod
	def LinkAddProperties(obj):
            ''' Designated method to Add Properties that allows to vary in Link Object - i.e. to be different from the Linked Object in each Child Instances'''
            
            obj.addProperty("App::PropertyLink","Attachment","AttachedObject","Object to Attach on")
            obj.addProperty("App::PropertyInteger","Attachment","Offset-X","")
            obj.addProperty("App::PropertyInteger","Shape","Height","")            
            ...

        @staticmethod
	def LinkCalculatePlacement(obj):
            ... say this use Link's properties added by LinkAddProperties, Offset-X, to define this Child Instances specific Attachment

Code: Select all

Then a Link  / General purpose LinkPython can have methods, already identified and managed by the Linked Object itself, rather than writing specific LinkPython(say _Window) which needs itself to identify again which methods needs to run for each LinkObjectType.

class _GeneralLinkPython
	def execute(self, obj):
		if hasattr(obj.LinkedObject, 'LinkMethods'):
			obj.LinkedObject.Proxy.LinkMethods(obj)
Make sense ?

And should stock Link already can do this instead of making a general LinkPython ?

And have some related idea about Variant Link @Zolko in separate thread

Thanks again!

EDIT -
UseCases - Placing Frank Gehry's jumping window on his 'dancing house', placing (repetitive) doors on layout...
1024px-Praag,_Tsjechië_Aug_21,_2019_05-42-54_PM.jpeg
1024px-Praag,_Tsjechië_Aug_21,_2019_05-42-54_PM.jpeg (274.57 KiB) Viewed 322 times
Source: wikipedia
Screenshot from 2020-01-05 02-15-37.png
Screenshot from 2020-01-05 02-15-37.png (239.29 KiB) Viewed 325 times
realthunder
Posts: 1345
Joined: Tue Jan 03, 2017 10:55 am

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

Post by realthunder » 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
Try Assembly3 (latest version 0.10.2) along 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
paullee
Posts: 2041
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee » Fri Jan 17, 2020 11:38 am

Glad the concept is feasible to be implemented, and hope it is useful for other peoples :D

Can't wait to test !
realthunder
Posts: 1345
Joined: Tue Jan 03, 2017 10:55 am

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

Post by realthunder » Wed Feb 12, 2020 9:33 am

PR submitted here.

Slight difference than the one described above. appLinkExecute() will not be called on array element object, only on the parent array link, with additional third (index) and fourth (element object) argument. In case the array is collapsed, fourth element will be None. If linkElement is not None, you can change its placement directly. If it is None, you can change the placement with linkObj.PlacementList[index]. Anyway, handling array is kind of tricky. I suggest you try normal link first.

Code: Select all

class _Window:
	def appLinkExecute(self, obj, linkObj, index, linkElement):
		pass

Try Assembly3 (latest version 0.10.2) along 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
paullee
Posts: 2041
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee » Thu Feb 13, 2020 5:32 am

realthunder wrote:
Wed Feb 12, 2020 9:33 am
PR submitted here.

Slight difference than the one described above. appLinkExecute() will not be called on array element object, only on the parent array link, with additional third (index) and fourth (element object) argument. In case the array is collapsed, fourth element will be None. If linkElement is not None, you can change its placement directly. If it is None, you can change the placement with linkObj.PlacementList[index]. Anyway, handling array is kind of tricky. I suggest you try normal link first.

Code: Select all

class _Window:
	def appLinkExecute(self, obj, linkObj, index, linkElement):
		pass

Thanks, hope it is useful for many other peoples, and get merged soon :)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests