BOLTS Open Library of Technical Specifications

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Post by jreinhardt »

yorikvanhavre wrote:Just tested, amazing work! One little cosmetic bug I found, if you press the "add shape" button when there is no value in the "I" field, an error arises.
Another thing I found strange, is that the top faces of the bolts are heavily triangulated?

I would also suggest turning this into a macro, with an icon, so it could be added to the FreeCAD interface without the hassle to make a complete workbench, which would be overkill in this case... If your bolts folder is placed inside the FreeCAD macros folder (~/.FreeCAD on linux & mac, don't remember exactly where for windows), and you rename freecad_bolts.py as __init__.py, you can do "import bolts" without the need for your launch script... So your macro would basically contain only that line :)
Hi,

in the last days I did a big overhaul of the infrastructure code of BOLTS, and as a result of this, I turned the FreeCAD version into a macro that can be used like you described. Apart from that there are no new features yet, only changes under the hood, but working on it feels a lot less like a prototype, and it is much easier to actually extend it.

For those that want to test, get the latest version from the Homepage http://jreinhardt.github.io/BOLTS/index.html. For FreeCAD still only hexagon fasteners and washers are working.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: BOLTS Open Library of Technical Specifications

Post by ickby »

Hello,

I'm still not able to get it to work. I copyed the down-loadable archive into my freecad dir and can execute the start_bolts.py. However, it raises this error:

Code: Select all

Traceback (most recent call last):
  File "/home/stefan/.FreeCAD/start_bolts.py", line 1, in <module>
    import BOLTS
<type 'exceptions.ImportError'>: No module named BOLTS
Any Idea about this? The BOLTS folder is in the very same folder. MAybe thats because this folder is not in the python oath? Unfortunatly I don't know very much about python, so any help is appreciated!
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: BOLTS Open Library of Technical Specifications

Post by ulrich1a »

The python file that should be imported has to be in one of these folders:
-The folder that contains the macros: The path can be set in the FreeCAD preferences. This is my favorite.
-The Mod-folder of your FreeCAD-installation or in one the folders it contains.
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Post by jreinhardt »

ickby wrote:Hello,

I'm still not able to get it to work. I copyed the down-loadable archive into my freecad dir and can execute the start_bolts.py. However, it raises this error:

Code: Select all

Traceback (most recent call last):
  File "/home/stefan/.FreeCAD/start_bolts.py", line 1, in <module>
    import BOLTS
<type 'exceptions.ImportError'>: No module named BOLTS
Any Idea about this? The BOLTS folder is in the very same folder. Maybe thats because this folder is not in the python oath? Unfortunatly I don't know very much about python, so any help is appreciated!
Do you execute start_bolts.py from the FreeCAD python console? Or do you execute the python script from your terminal or by double clicking on the file? The latter probably won't work (but I would have expected a different error then).

It should be like this:
- The directory /home/stefan/.FreeCAD/ should contain start_bolts.py and a subdirectory called BOLTS with more stuff in it.
- The directory /home/stefan/.FreeCAD/ should be the macro directory. This can be checked in FreeCAD by choosing Edit->Preferences, then going to the macro tab. There the macro path is listed.

Then the following ways to start the widget should work:
- Type "import BOLTS" in the FreeCAD python console
- Choose Macro->Macros, select "start_bolts.py" and click execute.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: BOLTS Open Library of Technical Specifications

Post by ickby »

ahh stupid me :) works now!

I really like the idea, congrats! I hope you achieve your goal of a comprehensible library. A few remarks:

1. You can use the part->refine shape on your bolts, that would remove the clutter on the surface. Of course it's accessible from python.
2. You should use QT Layouts in the gui part so that the list scales with the dock window size.

Again, nice project!
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Post by jreinhardt »

1. I can reproduce the removal of the clutter, but I cannot find anything about how to script that. Can you give me a hint?
2. I fixed that. Thank you for the hint.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: BOLTS Open Library of Technical Specifications

Post by ickby »

the remove splitter function belongs to the shape class and returns an alterated shape without chaning the original one. therefore you have to assign the new shape to a document object, something like this for overiding the original shape:

Code: Select all

App.ActiveDocument.ActiveObject.Shape = App.ActiveDocument.ActiveObject.Shape.removeSplitter()
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Post by jreinhardt »

Hi,

until now, BOLTS needed a python function for every entry in the library, that set up the geometry. But as this is annoying in many cases, and python scripting is not for everybody, I work on loading parts from a fcstd file. To load a part from a fcstd file, I use code like this

Code: Select all

·   ·   import FreeCAD
·   ·   newdoc = FreeCAD.openDocument(self.filename)
·   ·   obj = newdoc.getObjectsByLabel(self.objectlabel)
·   ·   if len(obj) != 1:
·   ·   ·   raise MalformedBaseError("No file %s found" % self.filename)
·   ·   doc.copyObject(obj[0])
·   ·   FreeCAD.setActiveDocument(doc.Name)
·   ·   FreeCAD.closeDocument(newdoc.Name)
With this I have run into a couple of difficulties:

1) It is more a cosmetic issue, and I do not care too much about it: everything flickers when I load a file from fcstd, because when a new document is opened, the Gui automatically switches to it. Is there a way to circumvent the Gui and load the file in a document, that is not visible?

I also want to have the possibility to change parameters in the loaded part. For development I use aluminium extrusions as a test case and try to change its length:

2) I can load a Pad of the crosssection from the fcstd file with the code above, but when I want to change the Length property, I get the error "No sketch linked", and indeed, the Sketch that is present when I load the file manually is absent when using the code above.

3)When I load the File manually, the sketch is there, and I can change the length of the Pad manually in the ComboView, and the 3D View updates, just like expected. When doing that, the Python console says something like

Code: Select all

FreeCAD.getDocument("tube_rectangular_v000").getObject("Pad").Length = 200.00
But typing this in the Python Console only updates the value in the Combo View, not the 3D view.

4) I do not want to be restricted to Pads and its Lengths, so the property that is to be changed should be passed to the load function as a parameter. If Length were a simple member of the <Part::PartFeature>, I would expect something like this to work:

Code: Select all

FreeCAD.getDocument("tube_rectangular_v000").getObject("Pad").__dict__["Length"] = 200.0
but it doesn't. Then I thought I might use

Code: Select all

FreeCAD.getDocument("tube_rectangular_v000").getObject("Pad").__setattr__("Length",200.0)
but then I get a "TypeError: can't apply this __setattr__ to Part.Feature object"
Is there a nice possibility to access the properties of a Part.Feature with the name of the property as a string, or do I have to resort to something like

Code: Select all

 if property == "Length":
    part.Length = value
elif property == "Length2":
    part.Length2 = value
elif ...
I would be very happy, if someone help me with or point me to useful literature about one or several of these. This was done on
OS: Ubuntu 13.04
Platform: 64-bit
Version: 0.13.1830 (Git)
Branch: releases/FreeCAD-0-13
Hash: ec7636d7aaf2612e9b43cff5d6a424037d53e505
Python version: 2.7.4
Qt version: 4.8.4
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.5.0

Greetings

Johannes
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
yorik
Founder
Posts: 13659
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: BOLTS Open Library of Technical Specifications

Post by yorik »

1) I don't think it's possible...
2) You mean the contents of the loaded file are different when loading the file via the GUI or via python? Are you sure??
3) After changing a value with python, you need to recompute the document:

Code: Select all

FreeCAD.ActiveDocument.recompute()
4) this works for me, don't know why __setattr__ doesn't...

Code: Select all

setattr(App.ActiveDocument.ActiveObject,"Length",20)
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Post by jreinhardt »

1) That is no big deal
2) No, I think the contents of the loaded file are ok, but I guess my attempts to copy the object with the specified label to the other documents are not good. I will fiddle around a bit more.
3) That works
4) That works for me as well

Thank you very much, you got 3 out of 4 in just one post! :)
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
Post Reply