What's new

Wooden_Box_Generator

Cator

Senior Member
Hi everyone,
after three months of working with Alibre at a hobby level and just over a month of initiation into the Python language, I am happy to share with you one of the jobs that I was able to do as a beginner. I await your advice to improve and ask:

a) Is it possible to customize the color and the material through the script?

b) Could you simply explain to me what is the difference between AlignConstraint and MateConstraint?

PS: If you deem it worthy I would be very happy if this little program was used among the default examples in Alibre_script to better illustrate the basic creation and assembly capabilities.

Thanks and good job!
Francesco
 

Attachments

  • Wooden_Box_Generator.py
    5.6 KB · Views: 18
  • Wooden_box_image.png
    Wooden_box_image.png
    8.3 KB · Views: 33

DavidJ

Administrator
Staff member
Align : Imagine placing both hands palms down on a desk. the palms are 'aligned'

Mate: Imagine placing your hands together (as when people pray). the palms are 'mated'

The difference is about DIRECTION. For faces of a solid that is pretty obvious, but even planes in CAD space have a direction (you'll see an arrow normal to the plane if 'show plane normals' is selected in system options -> parts/assemblies -> design viewing.
 

idslk

Alibre Super User
Hello Francesco,

congrats for your first posted script.

Sorry for the following, but...
default examples in Alibre_script

I gave it a try:
first start:

upload_2021-2-13_12-53-36.png

... no problem for me...

second start:

upload_2021-2-13_12-54-31.png

third start:

upload_2021-2-13_12-55-27.png

fourth start:

upload_2021-2-13_12-56-11.png

....

may it needs a little bit of polishing...
I'm sure, if you ask the community to test the script, you will get advice during your learning phase...
Another way can be to look at all the posted scripts in the forum section...

Don't give up ;)
What you acchived in this short time is pretty good!

Regards
Stefan
 

Cator

Senior Member
Thanks Stefan,
for having "tested" my little debut work and for the encouragement. May I know the measures you used in the input window? I tried the program several times and it did not give me problems besides a greater side of the thickness ..... Thank you so much for the suggestions I treasure your feedback and those who want to try and give me useful tips on how to improve my work!

Thanks Francesco
 

idslk

Alibre Super User
Hello Francesco,

May I know the measures you used in the input window?
of course. I haven't alltered your default values (0,0,0,0) and pressed ok. ;-)

Here are some comments to my last post... ;-)
If you want it as an example, it needs more comments about what your code lines will do...

If you use a picture in your script
- the user needs to know to copy it to the script folder (It isn't self explaning specially for new users)
- you can ask via script for existency of the picture and tell the user to copy this picture into the script directory,
if it does not exist there...
- Alternatively you can convert your picture into Python code using "image to python"

If you want to save something
- ask the user at least where (choose folder...)
- and better also for the name the user wants to give it

If you ask the user for values
- you should choose the default values so, that they (if not altered by the user) lead to an result of your script
(and not to a failure...)

- If there is a needed range for the values
- you should inform the user about the valid range
- or (in addition) use the script to check for validity before trying to work​

These are my personal opinions, may not be valid for everyone!

As you asked for what i've done with you input window i will also show one possible solution to avoid this.
The little code sample is appended (If someone wants to optimize it... everytime wellcome...)
Maybe some other samples will follow...

Regards
Stefan
 

Attachments

  • Catch_values_out_of_range_V01.py
    1.9 KB · Views: 9

Cator

Senior Member
Stefan
I will try to improve the code through your valuable suggestions ... Is the image very clear in your opinion? I have doubts especially for the T value ...
 

idslk

Alibre Super User
I have doubts especially for the T value ...
? What doubts? Of course you have to addept the logic to the type of input you want to process...(...if you want to write a script on your own, otherwise...)
In case of "T" you have to change your input line to value type "real"... or you have stay with integer values for thickness ;-)

Regards
Stefan

Edit:
Sample for value type "real" appended
 

Attachments

  • Catch_values_out_of_range_V02.py
    2 KB · Views: 6
Last edited:

NateLiquidGravity

Alibre Super User
Make sure you add this to the top of your script or division may not be correct.
https://www.alibreforum.com/forum/i...ortant-thing-in-script-when-doing-math.22265/


Code:
Wdb.AddAlignConstraint(0,PartSX,PartSX.GetFace("Face<10>"),Part_back,Part_back.GetFace("Face<4>"),True,'Assembly')
Should be:
Code:
Wdb.AddMateConstraint(0,PartSX,PartSX.GetFace("Face<4>"),Part_back,Part_back.GetFace("Face<4>"),True,'Assembly')

Also It did not like to try saving on my PC since I use Alibre Vault. You might want to look at building everything the assembly without saving anything. It would also generate less windows that way.
 

Cator

Senior Member
Make sure you add this to the top of your script or division may not be correct.
https://www.alibreforum.com/forum/i...ortant-thing-in-script-when-doing-math.22265/


Code:
Wdb.AddAlignConstraint(0,PartSX,PartSX.GetFace("Face<10>"),Part_back,Part_back.GetFace("Face<4>"),True,'Assembly')
Should be:
Code:
Wdb.AddMateConstraint(0,PartSX,PartSX.GetFace("Face<4>"),Part_back,Part_back.GetFace("Face<4>"),True,'Assembly')

Also It did not like to try saving on my PC since I use Alibre Vault. You might want to look at building everything the assembly without saving anything. It would also generate less windows that way.

Thank you
for giving me these tips. What makes you prefer AddMate () to AddAlign () in that case?
I will try over the weekend to improve the generator with your advice!
 

NateLiquidGravity

Alibre Super User
Thank you
for giving me these tips. What makes you prefer AddMate () to AddAlign () in that case?
I will try over the weekend to improve the generator with your advice!
That's not the only difference: I changed Face<10> to face<4> because otherwise parts were constrained into each other.
 
Top