Assembly 4 workbench

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Assembly 4 workbench

Post by onekk »

A little advancing in Scripting Asm4 WB.
20230429-asm4_scripting-v1.py
(23.05 KiB) Downloaded 37 times
Essentially is working in a decent flawless manner.

I have to find a more GUI way to set angles, and modify them.

I have some doubt about the correctness of some "helpers methods", as they are derived from Zolko Asm4 code, without a deep knowledge of what they are doing in reality.

But without proper documentation, this is the best I could achieve.

I hope this will be helpful for some users.

As usual, comment and code improvements or quirks are welcomed.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

onekk wrote: Sat Apr 29, 2023 10:18 am 20230429-asm4_scripting-v1.py
I understand better. But that raises other questions: the function create_asm4_model(asm_doc) seems to create a new assembly. Did you try to call

Code: Select all

Gui.runCommand('Asm4_newAssembly')
Wouldn't that do the same ? And for create_pd_body ( Gui.runCommand('Asm4_newBody') ) ?

The logic behind the way Asm4 is coded is that 1 command is 1 file which includes all helper functions and the UI. Except for functions that are called in many places, then it goes into the Asm4_libs file to be available for all. And I tried to avoid global variables (and functions/classes) as much as I could.
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Assembly 4 workbench

Post by onekk »

Zolko wrote: Sat May 06, 2023 5:46 pm ...

Thanks for reply.

IMHO if the whole Activated code will be exposed in a proper method, that will be usable both by the Activated gui.command and by a script most of the helper methods would not needed.

Same for create link command.

I had to copy and paste the whole code to make things works with new version of ASM4.

code changes was only related to the fact that I pass the FreeCAD doc where I want to put the "Assembly".

Technically speaking self is not used in the code so it will be not a big work.

This way it will be usable if placed in Asm4libs even when using "FreeCAD as a library" or from freecadcmd.exe (only to give an idea).

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

onekk wrote: Sun May 07, 2023 8:08 am IMHO if the whole Activated code will be exposed in a proper method, that will be usable both by the Activated gui.command and by a script most of the helper methods would not needed.
OK, why not. Would you make a proposal (a PR) to show what you have in mind ?
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Assembly 4 workbench

Post by onekk »

Zolko wrote: Sun May 07, 2023 11:36 am ...
Ok i will try to make a PR.

EDIT: see below

Regards

Carlo D.
Last edited by onekk on Sun May 07, 2023 2:43 pm, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Assembly 4 workbench

Post by onekk »

Hello, I've made a PR.

This modified code will work with the PR proposed:
20230507-asm4_scripting-v2.py
(22.53 KiB) Downloaded 26 times
my code to make a link is a mix of insertLink and placeLink so it is probably more difficult to separate them without some refactoring of your code.

But as it is a mere guess on how things are working, (But It seems to work most of the time.) probably some revision is needed.

Code: Select all

def create_link(r_Asm, l_Name, l_Obj, at_by, at_to):
    """Create a App::Link."""
    obj = r_Asm.newObject('App::Link', l_Name)
    obj.LinkedObject = l_Obj
    # If the name was already chosen, and a UID was generated:
    if obj.Name != l_Name:
        # we try to set the label to the chosen name
        obj.Label = l_Name
    Asm4.makeAsmProperties(obj)
    obj.AttachedBy = at_by
    obj.AttachedTo = at_to
    #obj.AssemblyType = "Part::Link"
    obj.LinkTransform = False
    obj.SolverId = "Asm4EE"
    (a_Link, sep, a_LCS) = obj.AttachedTo.partition('#')

    if a_Link == 'Parent Assembly':
        a_Part = None
    else:
        a_Part = obj.Document.getObject(a_Link).LinkedObject.Document.Name

    l_Part = obj.LinkedObject.Document.Name

    if obj.AttachedBy[0] == "#":
        l_LCS = obj.AttachedBy[1:]
    else:
        l_LCS = obj.AttachedBy

    expr = Asm4.makeExpressionPart(a_Link, a_Part, a_LCS, l_Part, l_LCS)
    # print(expr)
    obj.setExpression('Placement', expr)

    # update the link
    obj.recompute()

    return obj
Kind Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Bernard19
Posts: 887
Joined: Sun Feb 20, 2022 7:16 pm

Re: Assembly 4 workbench

Post by Bernard19 »

Hello,
I would like to rotate the belt around the pulleys. Currently I managed to produce this movement on the sketch002 (Courroie) with the LCS5. I can't associate it with the belt. I don't know if that's the way to do it. Could one of you help me?
Thank you in advance for this beneficial help for my understanding of ASM4.
Attachments
Capture d'écran 2023-05-08 090026.png
Capture d'écran 2023-05-08 090026.png (29.02 KiB) Viewed 1919 times
ASM4-AnimCourroie.FCStd
(356.72 KiB) Downloaded 32 times
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

Some great news: thanx to @leoheck, there is now (or rather: will be with the next release) an interference check for assemblies. This is a fundamental function for an assembly tool ! This is for now only in the development branch, and for those who know how to use that branch, it would be very nice if you could test this function and give your feedback. There are still errors left and it would be cool to smoothen them out. Please be aware that the check can take long time, depending on the complexity of your assembly.

Usage is very simple (as per Asm4 habit) : click the button. You can hide the ShapesCopy folder and use the measurement tool to measure the interference dimensions between objects. To get back to normal workflow, simply delete the Interferences folder and un-hide the assembly.

check_interferences.png
check_interferences.png (795.03 KiB) Viewed 1835 times

EDIT: added link to forum post
Last edited by Zolko on Mon May 08, 2023 6:54 pm, edited 1 time in total.
try the Assembly4 workbench for FreCAD — tutorials here and here
leoheck
Veteran
Posts: 1223
Joined: Tue Mar 13, 2018 5:56 pm
Location: Coffee shop

Re: Assembly 4 workbench

Post by leoheck »

Zolko wrote: Mon May 08, 2023 5:37 pm Some great news: thanx to @leoheck,...
Oh, nice. Thank you too!
User avatar
Bernard19
Posts: 887
Joined: Sun Feb 20, 2022 7:16 pm

Re: Assembly 4 workbench

Post by Bernard19 »

@Zolko
A quick throwback
I just installed the new version of Assembly4 today 0.50.2 and the "Check Intereferences" icon is not visible; is not in the Assembly drop-down menu
Ok for Delete variable icon is here.
Post Reply