Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby paullee » Wed Jan 01, 2020 2:35 am

Hi, Happy 1st Day of New Year 2020 !

I am testing usecase of Link and found not understanding if below usecase is possible.
  1. Say create a Sketch
  2. Create a Link to the Sketch
  3. Say create a Box
  4. Map the 1st Sketch by Box to say Face 3 of the Box
    - So far so Good
    Now ...
  5. Want to Map the Link of Sketch to another Face of the Box...
    - It seems the MapMode is for the original Sketch
    - Can't use MapMode / Attachment Offset for the Link Object ?
realthunder wrote:Ping
Thanks for any idea.
Screenshot from 2020-01-01 09-45-55.png
Screenshot from 2020-01-01 09-45-55.png (171.45 KiB) Viewed 438 times
Screenshot from 2020-01-01 09-46-05.png
Screenshot from 2020-01-01 09-46-05.png (145.55 KiB) Viewed 438 times
Screenshot from 2020-01-01 09-46-54.png
Screenshot from 2020-01-01 09-46-54.png (186.04 KiB) Viewed 436 times
Screenshot from 2020-01-01 09-48-08.png
Screenshot from 2020-01-01 09-48-08.png (186 KiB) Viewed 438 times
Attachments
Test_ Link Object_ Attachment Offset.FCStd
(6.46 KiB) Downloaded 10 times
realthunder
Posts: 1810
Joined: Tue Jan 03, 2017 10:55 am

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby realthunder » Wed Jan 01, 2020 11:56 pm

Happy new year!

DeepSOIC wrote: ping
@DeepSOIC, is there any potential side effect of simply inserting the AttachExtensionPython to any type of object on demand? How about insert the following code after this line.

Code: Select all

        if not self.obj.hasExtension('Part::AttachExtension'):
            self.obj.addExtension('Part::AttachExtensionPython', None)

@paullee, if this can work, then you can add attachment to any type of object by using Part workbench menu 'Attachment...'. In the meantime, you can manually type the 'addExtension()' line of code to insert the AttachExtension and try it yourself.
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
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby paullee » Thu Jan 02, 2020 2:38 pm

realthunder wrote:
Wed Jan 01, 2020 11:56 pm

Code: Select all

        if not self.obj.hasExtension('Part::AttachExtension'):
            self.obj.addExtension('Part::AttachExtensionPython', None)
@paullee, if this can work, then you can add attachment to any type of object by using Part workbench menu 'Attachment...'. In the meantime, you can manually type the 'addExtension()' line of code to insert the AttachExtension and try it yourself.
Thanks! I had tried adding attachment to ArchWall more than 1 year ago ! Would test again.

Seem good to have this capability in every Link object?
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby paullee » Thu Jan 02, 2020 2:39 pm

Roy_043 wrote:
Thu Jan 02, 2020 8:54 am
Related:
https://forum.freecadweb.org/viewtopic.php?f=3&t=41715
Thanks! Sounds familiar... adding my thoughts in that thread :)
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby paullee » Thu Jan 02, 2020 5:50 pm

realthunder wrote:
Wed Jan 01, 2020 11:56 pm

Code: Select all

        if not self.obj.hasExtension('Part::AttachExtension'):
            self.obj.addExtension('Part::AttachExtensionPython', None)
@paullee, if this can work, then you can add attachment to any type of object by using Part workbench menu 'Attachment...'. In the meantime, you can manually type the 'addExtension()' line of code to insert the AttachExtension and try it yourself.
paullee wrote:
Thu Jan 02, 2020 2:38 pm

Thanks! I had tried adding attachment to ArchWall more than 1 year ago ! Would test again.

Seem good to have this capability in every Link object?
Hi, I am digging into my earlier test and noted the scripted object seems needs to add positionBySupport() method in execute() method. @DeepSOCI seems also point this out https://forum.freecadweb.org/viewtopic. ... 15#p354256

Code: Select all

  def execute(self, fp):
      ''' '''
      fp.positionBySupport()
DeepSOIC wrote:
Mon Dec 16, 2019 9:46 am
Roy_043 wrote:
Mon Dec 16, 2019 9:36 am
Wow, I am surprised that this is possible.
Me too!

I think you'll experience recompute problems. AttachExtensionPython requires one to call positionBySupport() from execute, which the Part obviously doesn't.

Adding attachextension to Part is a bit tricky, because Part is defined in FreeCAD, but AttachExtension in Part. FreeCAD cannot use Part (Werner won't allow it ;) )
realthunder
Posts: 1810
Joined: Tue Jan 03, 2017 10:55 am

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby realthunder » Thu Jan 02, 2020 9:56 pm

paullee wrote:
Thu Jan 02, 2020 5:50 pm
Hi, I am digging into my earlier test and noted the scripted object seems needs to add positionBySupport() method in execute() method. @DeepSOCI seems also point this out https://forum.freecadweb.org/viewtopic. ... 15#p354256
The extension has its own extensionExecute() function, which is called by DocumentObject::execute(). The derived object has the chance to decide when or whether to call it. And Link will call it. You can try it. The reason for the error Roy have in the other post is because of the second argument of addExtension(). It should be None.

Code: Select all

obj.addExtension('Part::AttachExtensionPython', None)
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
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby paullee » Thu Jan 02, 2020 11:56 pm

realthunder wrote:
Thu Jan 02, 2020 9:56 pm
The extension has its own extensionExecute() function, which is called by DocumentObject::execute(). The derived object has the chance to decide when or whether to call it. And Link will call it. You can try it. The reason for the error Roy have in the other post is because of the second argument of addExtension(). It should be None.

Code: Select all

obj.addExtension('Part::AttachExtensionPython', None)
Thanks explaining.

In fact, I have tested on the Link to the Sketch object - with the 2nd argument = obj - and it works !

Haven't tested 'None', but can you slightly elaborate the difference ?
( I haven't found the original discussion where I copy the code without understanding the technicality behind).

May test Link to object other than Sketch later...

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

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby realthunder » Fri Jan 03, 2020 12:50 am

paullee wrote:
Thu Jan 02, 2020 11:56 pm
Thanks explaining.

In fact, I have tested on the Link to the Sketch object - with the 2nd argument = obj - and it works !

Haven't tested 'None', but can you slightly elaborate the difference ?
( I haven't found the original discussion where I copy the code without understanding the technicality behind).

May test Link to object other than Sketch later...

Thanks.
You may already know that FC allows to extend C++ object using Python, through the 'Proxy' property. Extension (e.g. AttachExtension here) can be extended, too, with 'ExtensionProxy' property. The second argument is supposed to be a Python object to further 'extend' the extension. It is optional, but obviously cannot be the object itself.
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
paullee
Posts: 2768
Joined: Wed May 04, 2016 3:58 pm

Re: Link Object (Sketch) has no separate MapMode/ Attachment Offset ?

Postby paullee » Fri Jan 03, 2020 6:28 pm

realthunder wrote:
Fri Jan 03, 2020 12:50 am
You may already know that FC allows to extend C++ object using Python, through the 'Proxy' property. Extension (e.g. AttachExtension here) can be extended, too, with 'ExtensionProxy' property. The second argument is supposed to be a Python object to further 'extend' the extension. It is optional, but obviously cannot be the object itself.
Thanks again taking all these time to explain !

Much better picture now :) Though I am not trained as a programmer. In fact I am not aware and fully understand the capability 'to extend C++ object ...'. :D

Hope the MapMode feature is one found useful by users/developers to have it 'built-in'.