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

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

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

Postby paullee » Fri Sep 18, 2020 11:23 pm

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 8 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 218 times
Screenshot from 2020-09-19 07-13-39.png
Screenshot from 2020-09-19 07-13-39.png (223.63 KiB) Viewed 218 times
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

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

Postby paullee » Sat Sep 19, 2020 2:58 am

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 8 times
Test_ Link_appLinkExecute_ 02.FCStd
(273.08 KiB) Downloaded 8 times
Screenshot from 2020-09-19 10-45-13.png
Screenshot from 2020-09-19 10-45-13.png (231.31 KiB) Viewed 206 times
Screenshot from 2020-09-19 10-46-04.png
Screenshot from 2020-09-19 10-46-04.png (246.85 KiB) Viewed 206 times
Screenshot from 2020-09-19 10-46-57.png
Screenshot from 2020-09-19 10-46-57.png (256.07 KiB) Viewed 206 times
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

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

Postby paullee » Sat Sep 19, 2020 12:40 pm

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
  2. Let Arch Door to have appLinkExecute() and use updateAttachmentOffset() to acquire this feature
phpBB [video]
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

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

Postby paullee » Fri Oct 02, 2020 2:01 am

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

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

Postby realthunder » 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)
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 (latest version 0.11) 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