Part Attachment Feature with Custom Scripted Objects

Need help, or want to share a macro? Post here!
Post Reply
User avatar
gbroques
Posts: 162
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Part Attachment Feature with Custom Scripted Objects

Post by gbroques »

Hi all, I decided to make a minimal example of the Part Attachment feature for custom scripted objects to learn it better myself.

Also, it seemed other were struggling with this. For example, here.

See the following repository for detail:
https://github.com/gbroques/freecad-par ... on-example

Hopefully this helps others who are interested in making their custom scripted objects "attachable" to other objects in FreeCAD. :)

Let me know if you have any thoughts or feedback!
Last edited by gbroques on Tue May 05, 2020 3:33 am, edited 1 time in total.
vocx
Veteran
Posts: 5205
Joined: Thu Oct 18, 2018 9:18 pm

Re: Part Attachment Feature with Custom Scripted Objects

Post by vocx »

gbroques wrote: Tue May 05, 2020 2:21 am ...
See the following repository for detail:
https://github.com/gbroques/freecad-par ... on-example
...
I suggest you don't name it .FCMacro because that doesn't allow editors to recognize it immediately as a Python file. It's just a Python file, so add the .py extension. Then it could be imported and run at the same time.

Also, maybe you'd be interested in adding it to the wiki, for example, to some document called, Scripted objects with attachment, or something similar. And that example could be placed somewhere in the Power users hub.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
gbroques
Posts: 162
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: Part Attachment Feature with Custom Scripted Objects

Post by gbroques »

vocx wrote: Tue May 05, 2020 2:40 am I suggest you don't name it .FCMacro because that doesn't allow editors to recognize it immediately as a Python file. It's just a Python file, so add the .py extension. Then it could be imported and run at the same time.
Good point. I renamed the extension to .py in the GitHub repository for syntax highlighting purposes.

---
vocx wrote: Tue May 05, 2020 2:40 am Also, maybe you'd be interested in adding it to the wiki, for example, to some document called, Scripted objects with attachment, or something similar. And that example could be placed somewhere in the Power users hub.
Great idea! I added this to the Wiki and included a link to it on the Power users hub:
https://wiki.freecadweb.org/Scripted_ob ... attachment

Thanks for the suggestions vocx. :)
vocx
Veteran
Posts: 5205
Joined: Thu Oct 18, 2018 9:18 pm

Re: Part Attachment Feature with Custom Scripted Objects

Post by vocx »

gbroques wrote: Tue May 05, 2020 11:24 pm Great idea! I added this to the Wiki and included a link to it on the Power users hub:
https://wiki.freecadweb.org/Scripted_ob ... attachment
I changed the headings to start at the ==second level==. First level headings is used only for the title.

Also, hmm. Syntax highlighting works? This is actually good news. The highlighter was deactivated a long time ago because it didn't work correctly in the previous wiki server. But I never tested again after the new server was deployed.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
gbroques
Posts: 162
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: Part Attachment Feature with Custom Scripted Objects

Post by gbroques »

vocx wrote: Tue May 05, 2020 11:58 pm I changed the headings to start at the ==second level==. First level headings is used only for the title.
Good tip, thanks!
vocx wrote: Tue May 05, 2020 11:58 pm Also, hmm. Syntax highlighting works? This is actually good news. The highlighter was deactivated a long time ago because it didn't work correctly in the previous wiki server. But I never tested again after the new server was deployed.
Yes, it's great :)
User avatar
Vincent B
Veteran
Posts: 4346
Joined: Sun Apr 05, 2015 9:02 am
Location: La Rochelle, France

Re: Part Attachment Feature with Custom Scripted Objects

Post by Vincent B »

Following this example, how to set the attachment for an object?
example: I select an edge then a box. Then set the box attached "Z tangent" of the edge. :roll:
Post Reply