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

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

OK, tested and read GlouGlou's thread.

I thought 'MapMode' is Sketch's 'inherent' function so no need to addExtension, following the example and added that code. Not sure if linkFp.positionBySupport() is needed.

In any rate, it seem really need PR to merge, currently anything try to alter Link's 'Attachment attributes' become changing Linked object's 'Attachment attributes'. So the Linked Object move instead of the Links. Seems this problem affect adding Attacher to Links only, adding Attacher to other objects has been working right ?

Have to wait. Thanks ! :D
ArchSketchObject.py
(2.06 KiB) Downloaded 66 times

Code: Select all

import FreeCAD

class ArchSketchObject:
  def __init__(self, obj):
      pass


class ArchSketch(ArchSketchObject):

  def __init__(self, obj):
      ArchSketchObject.__init__(self, obj)

  def setProperties(self, fp):
      fp.Proxy = self
      if not hasattr(self,"Type"):
          self.Type = "ArchSketch"

  def execute(self, fp):
      updateAttachmentOffset(fp)

  def onChanged(self, fp, prop):
      pass
	 
  def setPropertiesLinkCommon(self, orgFp, linkFp=None):

      if linkFp:
          fp = linkFp
          print (" It is linFp")
      else:
          fp = orgFp
          print (" It is fp")

      prop = fp.PropertiesList

      if not fp.hasExtension('Part::AttachExtension'):
          print ("  debug -  Part::AttachExtension NOT in prop")
          fp.addExtension('Part::AttachExtensionPython', None)
      else:
          print ("  debug -  Part::AttachExtension in prop")

  def appLinkExecute(self, fp, linkFp, index, linkElement):
      self.setPropertiesLinkCommon(fp, linkFp)
      updateAttachmentOffset(fp, linkFp)
      #linkFp.positionBySupport()  # need this ?


def updateAttachmentOffset(fp, linkFp=None):

    if linkFp:
        fp = linkFp
        print (" fp = linkFp, fp.Name is ... ", fp.Name)
        tempAttachmentOffset = FreeCAD.Placement(FreeCAD.Vector(2000,500,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
        print (" tempAttachmentOffset is ... ", tempAttachmentOffset)
        fp.MapMode = "ObjectXY"
        support = FreeCAD.ActiveDocument.getObject("ArchSketch065")
        fp.Support = support

    else:
        print (" fp is ... ", fp.Name)
        tempAttachmentOffset = FreeCAD.Placement(FreeCAD.Vector(0,500,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
        print (" tempAttachmentOffset is ... ", tempAttachmentOffset)
        fp.MapMode = "ObjectXY"
        support = FreeCAD.ActiveDocument.getObject("ArchSketch064")
        fp.Support = support

    fp.AttachmentOffset = tempAttachmentOffset

    print (" fp.AttachmentOffset = tempAttachmentOffset" )
    print (" (fp / linkfp) fp.AttachmentOffset is ... ", fp.AttachmentOffset)


Screenshot from 2020-09-19 07-13-05.png
Screenshot from 2020-09-19 07-13-05.png (222.06 KiB) Viewed 2766 times
Screenshot from 2020-09-19 07-13-39.png
Screenshot from 2020-09-19 07-13-39.png (223.63 KiB) Viewed 2766 times
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

OK, a working mock-up before PR merged to make AttachmentOffset works in Link, by using multiplication of Placement atm :D

So now -
  1. ArchSketch063's AttachmentOffset depends on ArchSketch064 (its 'MasterSketch')
  2. Make a Link of ArchSketch063
  3. Link's placement can now be calculated Independently and Automagically depends on another selected 'MasterSketch' and other parameters
  4. Link's placement depends on ArchSketch065
Thanks @Realthundar for the guidance !

ArchSketchObject.py
(2.66 KiB) Downloaded 63 times
Test_ Link_appLinkExecute_ 02.FCStd
(273.08 KiB) Downloaded 74 times
Screenshot from 2020-09-19 10-45-13.png
Screenshot from 2020-09-19 10-45-13.png (231.31 KiB) Viewed 2754 times
Screenshot from 2020-09-19 10-46-04.png
Screenshot from 2020-09-19 10-46-04.png (246.85 KiB) Viewed 2754 times
Screenshot from 2020-09-19 10-46-57.png
Screenshot from 2020-09-19 10-46-57.png (256.07 KiB) Viewed 2754 times
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

Now, a mock-up of Links of Door each automatically placed at walls.

Two issues now -
  1. Link of Arch Door do not create an opening in ArchWall, not behaving same as Arch Door itself
    [EDIT PR Merged - Link of Window Not Creating Hole ]
  2. Let Arch Door to have appLinkExecute() and use updateAttachmentOffset() to acquire this feature
    [EDIT Implemented / Not Merged yet - Intuitive Automatic Windows/Doors + Equipment Placement ]
phpBB [video]
Last edited by paullee on Thu Jan 28, 2021 6:49 pm, edited 1 time in total.
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

realthunder wrote: Wed Feb 12, 2020 9:33 am

Code: Select all

class _Window:
	def appLinkExecute(self, obj, linkObj, index, linkElement):
		pass
Preliminary attempt to migrate automatic disposition support to Arch Window done and trying to clean up the code etc :)

Can now create a numbers of Link of a Window object, and each of them can place themselves on wall according to each of their parameters.


In the meantime, curious how Array / linkElement of a Link works, hope to obtain some advice when you have a gap, thanks - imagining if ultimately a formula of something can be input and array of Windows follows like placing Window on Gehry's building below :lol:



phpBB [video]

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 2678 times
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

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

Post by realthunder »

paullee wrote: Fri Oct 02, 2020 2:01 am In the meantime, curious how Array / linkElement of a Link works, hope to obtain some advice when you have a gap, thanks - imagining if ultimately a formula of something can be input and array of Windows follows like placing Window on Gehry's building below :lol:
The link array is a bit more complex, because it has two distinctive state, controlled by property ShowElement. If set to True, then the array is expanded and each array element is an object and you can change the element object's Placement property directly. If collapsed, then there is no element object exposed, and you can access the element's placement through link's PlacementList property.

Code: Select all

def appLinkExecute(self, linkedObj, link, index, linkElement)
If the link is expanded, the element object is pass to appLinkExecute() as linkElement. If it is collapsed, linkElement is None, and you can access its placement through link.PlacementList[index].

Another complication is the placement of link itself. As an array, link act as a group, so its own placement will be applied on top of each element. So to calculate the correct placement of each element, you need to take that into account, like cancel it using link.Placement.inverse(). You can first experiment it without considering the link's placement for starter.
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
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

realthunder wrote: Fri Sep 18, 2020 1:21 pm

Code: Select all

if not linkObj.hasExtension('Part::AttachExtension'):
	linkObj.addExtension('Part::AttachExtensionPython', None)
Once you install the extension, linkObj will have its own 'AttachmentOffset' attribute. Note that, there is a pending PR fixing a relating bug, which also exists in my current release as well. You'll have to wait for it to be merged before you can test installing extension. Or, you can manually apply the PR and compile it yourself.
Seem the PR is not merged yet and no further discussion :?: :)

Is it safe to add AttachExtension to Link now ?

Thanks !
Last edited by paullee on Fri Jan 29, 2021 1:28 pm, edited 1 time in total.
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

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

Post by realthunder »

wmayer wrote: ping
Hi Werner, @paullee is asking about the this PR. So how's the status? Shall we move extensionExecute() to recompute()?
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
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

Oh yes, I will merge this soon, too. And I'll make the changes I once suggested.
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

Great, thanks ! :D
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

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

Post by paullee »

realthunder wrote: Tue Oct 06, 2020 12:10 am
paullee wrote: Fri Oct 02, 2020 2:01 am In the meantime, curious how Array / linkElement of a Link works, hope to obtain some advice when you have a gap, thanks - imagining if ultimately a formula of something can be input and array of Windows follows like placing Window on Gehry's building below :lol:
The link array is a bit more complex, because it has two distinctive state, controlled by property ShowElement. If set to True, then the array is expanded and each array element is an object and you can change the element object's Placement property directly. If collapsed, then there is no element object exposed, and you can access the element's placement through link's PlacementList property.

Code: Select all

def appLinkExecute(self, linkedObj, link, index, linkElement)
Whilst waiting for Attachment to be able to add to Link object, thinking about previous idea of placing a series of objects with an unified rule / or kind of formulas.

E.g.
Placement.Base.x = 1000mm x index
Placement.Base.y = - Placement.Base.x

So that with this 1 set of formulas, user just increase the Element Count, and all the linkElement just pick up its own placement.


See can't find any reference / discussion any idea how this could be done ?

Thanks for any idea.

Screenshot from 2021-01-30 18-26-32.png
Screenshot from 2021-01-30 18-26-32.png (273.23 KiB) Viewed 2346 times
Post Reply