Attachment OXY etc.

Need help, or want to share a macro? Post here!
edwilliams16
Veteran
Posts: 1369
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Attachment OXY etc.

Post by edwilliams16 »

@drmacro mentioned that this mode was poorly/explained/obsolete in the wiki. He wrote; https://wiki.freecadweb.org/Advanced_Attachment_OYX

I was inspired to make a little tool to explore this. The model has a cube and a glider stuck together that can be attached to a pair of skew-lines, joined at a vertex. You get to choose the AttachMode in the Dynamic Data enumeration. (OXY, OXZ, OYX, OYZ, OZX, OZY).
In the file, I used Vertex, Vertex, Vertex - but other choices work. Selection1 is the Apex, Selection2 is the end of the blue lIne and Selection3 is the end of the yellow line.

After playing with it, the net result is that for mode OAB (A, B are X, Y, Z). The origin is at the Apex. The A-direction of the glider goes along the blue line towards Selection2. The B-direction of the glider lies in the blue/yellow plane, orthogonal to the A-direction with the yellow direction having a positive projection.

If you play with it you'll quickly get the idea.
Screen Shot 2022-06-21 at 2.35.13 PM.png
Screen Shot 2022-06-21 at 2.35.13 PM.png (41.39 KiB) Viewed 717 times
Screen Shot 2022-06-21 at 2.35.41 PM.png
Screen Shot 2022-06-21 at 2.35.41 PM.png (40 KiB) Viewed 717 times
Screen Shot 2022-06-21 at 2.36.08 PM.png
Screen Shot 2022-06-21 at 2.36.08 PM.png (42.52 KiB) Viewed 717 times
Screen Shot 2022-06-21 at 2.36.24 PM.png
Screen Shot 2022-06-21 at 2.36.24 PM.png (36.1 KiB) Viewed 717 times
There doesn't appear to be FeaturePython points and lines, so I used the following to create them:

Code: Select all

class Line:
    def __init__(self, obj, start, end):
        ''' Add two point properties '''
        obj.addProperty("App::PropertyVector","Start","Line","Start point")
        obj.addProperty("App::PropertyVector","End","Line","End point")
        obj.Start = start
        obj.End = end
        obj.Proxy = self

    def execute(self, obj):
        ''' Print a short message when doing a recomputation, this method is mandatory '''
        obj.Shape = Part.makeLine(obj.Start,obj.End)

class ViewProviderLine:
    def __init__(self, obj):
        ''' Set this object to the proxy object of the actual view provider '''
        obj.Proxy = self

    def getDefaultDisplayMode(self):
        ''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
        return "Flat Lines"

def makeLine(start = FreeCAD.Vector(0, 0, 0), end = FreeCAD.Vector(10, 10, 10)):
    doc=FreeCAD.ActiveDocument
    a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Line")
    Line(a, start, end)
    ViewProviderLine(a.ViewObject)
    #a.ViewObject.Proxy=0 # just set it to something different from None
    doc.recompute()
    return a

class Point:
    def __init__(self, obj, loc):
        ''' Point location '''
        obj.addProperty("App::PropertyVector","Location","Point","Location")
        obj.Location = loc
        obj.addExtension('Part::AttachExtensionPython')
        obj.Proxy = self

    def execute(self, obj):
        obj.Shape = Part.Point(obj.Location).toShape()
        obj.positionBySupport() #add attachment

class ViewProviderPoint:
    def __init__(self, obj):
        ''' Set this object to the proxy object of the actual view provider '''
        obj.Proxy = self

    def getDefaultDisplayMode(self):
        ''' Return the name of the default display mode. It must be defined in getDisplayModes. '''
        return "Points"

def makePoint(loc = FreeCAD.Vector(0, 0, 0)):
    doc=FreeCAD.ActiveDocument
    a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Point")
    Point(a, loc)
    ViewProviderPoint(a.ViewObject)
    #a.ViewObject.Proxy=0 # just set it to something different from None
    doc.recompute()
    return a

doc = App.ActiveDocument
p = makePoint(FreeCAD.Vector(10,10,10))
p.ViewObject.PointSize = 6
l1 = makeLine(FreeCAD.Vector(10,10,10), FreeCAD.Vector(20,20,20))
l1.ViewObject.LineColor = (0.0, 0.333, 1.0, 0.0)
l2 = makeLine(FreeCAD.Vector(10,10,10), FreeCAD.Vector(20,20,0))
l2.ViewObject.LineColor = (1.0, 1.0, 0.0, 0.0)
Attachments
attachChecker.FCStd
(9.88 KiB) Downloaded 7 times
User avatar
onekk
Veteran
Posts: 2788
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Attachment OXY etc.

Post by onekk »

edwilliams16 wrote: Wed Jun 22, 2022 1:05 am...
Thanks forvexplainig this thing.

And thanks even to drmacro for having made the wiki page.

It would be a good thing to have maybe the "glider" costructed with a FPO maybe to have a way to reuse some code for other tutorial or scripting.

Maybe with some option to tune center point of the object like tip, tail and center.

What do you think?

Regards

Carlo D.
My English and Italian Scripting Guide https://github.com/onekk/freecad-doc.
My Blog: https://onekk-maker.blogspot.com/

To help development see on GitHub Page

For enquiry about customized FC Scripting job PM me.
edwilliams16
Veteran
Posts: 1369
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Attachment OXY etc.

Post by edwilliams16 »

The glider is a Lattice workbench object.
drmacro
Veteran
Posts: 5947
Joined: Sun Mar 02, 2014 4:35 pm

Re: Attachment OXY etc.

Post by drmacro »

It has been discussed many times that the sketch needs a visual cue while defining an Attachment. And, that a visualization of the current attachment, that could be toggled on.

The Lattice2 kite would be a good for this. It fits this function really well in the Lattice2 workbench.

I recently suggested that hovering over a sketch have the possibilty of displaying a Datum plane like visualization.

I suppose you could just add a kite to a sketch and hide it...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
User avatar
Simbioz
Posts: 67
Joined: Tue Mar 30, 2021 2:55 pm

Re: Attachment OXY etc.

Post by Simbioz »

When choosing an element from the Dynamic Data enumeration I get

Code: Select all

18:50:56  <string>(1)<class 'TypeError'>: list indices must be integers or slices, not str
ddStringList[ddAttachType]
in property binding 'ddString'
18:50:56  Recompute failed! Please check report view.
OS: Arch Linux (sway/sway)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24415 (Git)
Build type: Release
Branch: makepkg
Hash: 476ecf091941bead59b14e44afa6064d5a66afa3
Python version: 3.10.5
Qt version: 5.15.4
Coin version: 4.0.1
OCC version: 7.5.3
Locale: English/United States (en_US)
Non native English speaker.
edwilliams16
Veteran
Posts: 1369
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Attachment OXY etc.

Post by edwilliams16 »

I'm guessing you need to change the enumeration, not the string in the working area.
User avatar
Simbioz
Posts: 67
Joined: Tue Mar 30, 2021 2:55 pm

Re: Attachment OXY etc.

Post by Simbioz »

This is how it is supposed to work right?
Image


Report view:

Code: Select all

18:05:00  Loading GUI of Part module... done
18:05:00  <string>(1)<class 'AttributeError'>: Module __main__ has no class Point
18:05:00  <string>(1)<class 'AttributeError'>: Module __main__ has no class Line
18:05:00  <string>(1)<class 'AttributeError'>: Module __main__ has no class Line
18:05:00  <string>(1)<class 'AttributeError'>: Module __main__ has no class ViewProviderLine
18:05:00  <string>(1)<class 'AttributeError'>: Module __main__ has no class ViewProviderPoint
18:05:00  <string>(1)<class 'AttributeError'>: Module __main__ has no class ViewProviderLine
18:05:08  <string>(1)<class 'TypeError'>: list indices must be integers or slices, not str
ddStringList[ddAttachType]
in property binding 'ddString'
18:05:08  Recompute failed! Please check report view.


BTW, your file requires lattice WB (which I did not had), maybe this info could be useful to someone who can't get it to work.
Non native English speaker.
edwilliams16
Veteran
Posts: 1369
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Attachment OXY etc.

Post by edwilliams16 »

I do get some error messages about python classes I used, but are not provided, but it works without. Here's a cleaned up version that produces fewer such messages. I do have Dynamic Data and Lattice2 installed - they are likely required. You need to do recomputes after changing the enumeration.

Code: Select all

OS: macOS High Sierra (10.13)
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: (HEAD detached at 0.20)
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.9.13, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods: 
  * Curves 0.4.4
  * DynamicData 2.46.0
  * fasteners 0.3.44
  * fcgear 1.0.0
  * GDML 1.8.0
  * Help 1.0.2
  * lattice2 1.0.0
  * MeshRemodel 1.8919.0
  * toSketch
Attachments
attachChecker.FCStd
(9.75 KiB) Downloaded 5 times
User avatar
Simbioz
Posts: 67
Joined: Tue Mar 30, 2021 2:55 pm

Re: Attachment OXY etc.

Post by Simbioz »

edwilliams16 wrote: Sun Jun 26, 2022 1:02 am ...
I did not had the Dynamic Data WB installed, I thought it was some build-in Freecad feature. Anyway, I installed it but to no avail, same message about class TypeError. Maybe it's because you are on 0.20 and I on 0.19. Will test when my distribution upgrades to the newer version.
Thanks anyway.
Non native English speaker.
edwilliams16
Veteran
Posts: 1369
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Attachment OXY etc.

Post by edwilliams16 »

@drmacro

Here's my cut on documenting O-X-Y etc. I researched what the defaults did if one only selected two references. https://wiki.freecadweb.org/O-X-Y_type_attachment_modes
Post Reply