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

Postby jreinhardt » Tue Sep 24, 2013 3:25 pm

I got 3 as well, could have found that one earlier:

I only copied the Pad, but not the Sketch that it links to, which is then of course missing. I changed my code a bit to copy the whole dependency tree:

Code: Select all

   def _recursive_copy(self,obj,doc):
      doc.copyObject(obj)
      for child in obj.OutList:
         self._recursive_copy(obj,doc)

   def add_part(self,params,doc):
      import FreeCAD
      newdoc = FreeCAD.openDocument(self.filename)
      obj = newdoc.getObjectsByLabel(self.objectlabel)
      if len(obj) != 1:
         raise MalformedBaseError("No file %s found" % self.filename)
      self._recursive_copy(obj,doc)
      FreeCAD.setActiveDocument(doc.Name)
      FreeCAD.closeDocument(newdoc.Name)
This seems to work. Now I got to put everything together.

Edit: I was a bit enthusiastic. It copies both the Pad and the associated Sketch, but they are not linked anymore.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Postby jreinhardt » Wed Sep 25, 2013 10:35 am

I was too early with my declamation of success, I still could not successfully copy a object with all its associated objects from one document to another.

I found out that InList and Outlist allow me to get the associated objects (e.g. the sketch on which a pad is based), and I can use that to copy all of them. But in the destination document, the link between the copies is lost, and modifying InList and Outlist seems to not help.

Here is a bit of code, that shows the different things I tried, to try a different way of copying, change the copy function. The fcstd with an example Pad is attached:

Code: Select all

import FreeCAD                                                                                                        

def _copy(obj,doc):
   doc.copyObject(obj)

def _recursive_copy(obj,doc):
   doc.copyObject(obj)
   obj_copy = doc.getObject(obj.Name)
   for child in obj.OutList:                                                                                         
      _recursive_copy(child,doc)
   return obj_copy

def _recursive_copy_with_link(obj,doc):                                                                               
   doc.copyObject(obj)                                                                                               
   obj_copy = doc.getObject(obj.Name)                                                                                
   for child in obj.OutList:                                                                                         
      child_copy = _recursive_copy_with_link(child,doc)                                                             
      obj_copy.OutList.append(child_copy)                                                                           
      child_copy.InList.append(obj_copy)
   return obj_copy

def add_part(filename,obj_name,doc):                                                                                  
   src_doc = FreeCAD.openDocument(filename)                                                                          
   obj = src_doc.getObject(obj_name)                                                                                 
   obj_copy = _recursive_copy_with_link(obj,doc)                                                                     
   FreeCAD.setActiveDocument(doc.Name)
   FreeCAD.closeDocument(src_doc.Name)

if FreeCAD.ActiveDocument is None:
   FreeCAD.newDocument()

add_part("examp-L.fcstd","Pad",FreeCAD.ActiveDocument)  
Any help or pointers is appreciated
Attachments
examp-L.fcstd
(5.47 KiB) Downloaded 61 times
Last edited by jreinhardt on Wed Sep 25, 2013 11:42 am, edited 1 time in total.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
shoogen
Posts: 2823
Joined: Thu Dec 01, 2011 5:24 pm

Re: BOLTS Open Library of Technical Specifications

Postby shoogen » Wed Sep 25, 2013 11:01 am

AFAIK, In- and Outlist just reflect the Links defined by other Properties.
I solved this problem be searching through all properties.
See https://github.com/FreeCAD/FreeCAD_sf_m ... obj.py#L31
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Postby jreinhardt » Wed Sep 25, 2013 1:06 pm

Thank you very much! That helped a lot.

I managed to get my Pad testcase to work with the following copy:

Code: Select all

def _recursive_copy_with_prop_update(obj,doc):
   doc.copyObject(obj)
   obj_copy = doc.getObject(obj.Name)
   for prop_name in obj.PropertiesList:
       prop = obj.getPropertyByName(prop_name)
       prop_copy = obj_copy.getPropertyByName(prop_name)
       if prop_copy is None and (not prop is None):
           setattr(obj_copy,prop_name,_recursive_copy_with_prop_update(prop,doc))
   return obj_copy
I arrived there by trial and error and manual inspection of the property list, so I pretty sure that it is not water tight, but I will run with it and see what it takes to break.

Thank you again
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Postby jreinhardt » Wed Sep 25, 2013 6:08 pm

Hi everybody,

I just uploaded a new development snapshot of BOLTS to the website: http://jreinhardt.github.io/BOLTS/index.html

I am still working on the foundations, but the changes are becoming more visible. Biggest new feature is the possibility to store parts in the library in freecad files. As an example I have added the coffee table from the FreeCAD library https://github.com/yorikvanhavre/FreeCAD-library to a furniture collection.

But it is even more a bit more than a handy file opening dialog, because it can change the parameters of some parts. At the moment this is restricted to Pads, I will have to ask some questions about best practices and parametric modeling later. As example for this functionality I added a profile collection containing for now a single rectangular tube, modeled by bajsi viewtopic.php?f=19&t=4205. The idea is that the user does not have to care whether the part that he adds is generated by a python script or loaded from a file.

Also added were several different kinds of bearings, thanks the help of JavierMG. This uncovered the fact, that my GUI is not very well suited for the case of many versions of a part. I will have to think more about that.

The Website was also renovated a bit, the blog now got comments, I plan to blog more about the BOLTS development there in the future. The automatically generated overview pages for parts and collections have been updated a bit, and although there are many rough edges, I believe they can already be useful as a reference for the parts that are available.

The next steps will be polishing of the current features, and then I will documentt how one can contribute to this project.

You are cordially invited to play around the current state of BOLTS and tell me what you think about it.

Greetings Johannes
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Postby jreinhardt » Mon Sep 30, 2013 9:40 am

I am still trying to implement the infrastructure to include parametric parts created in FreeCAD seamlessly into BOLTS. I am not sure I understood everything correctly (I am not an engineer and have very little CAD experience), and I have a few questions, so I would be very thankful, if someone could comment on (some of) these:

1) There seem to be different ways to create parametric models in FreeCAD: Using sketches and the partdesign workbench and using parametric primitives and the part workbench, and possibly more. Is there one that is preferred?

With both of these ways, the part that one ends up with seems to consist of several Objects (e.g. a Sketch, a Pad that uses this Sketch, a Pocket that removes something (specified by Sketch2) from the Pad, a Fillet that filletes a few of the edges of the Pocket). My current mental model is, that one has to copy a top level object (e.g. the fillet) and all of its dependencies (Pocket, Sketch2, Pad, Sketch). The dimensional parameters that one could want to set are now distributed over all those Objects, so to change one of the dimensions, I might have to change Pad.Length, or Pocket.Length.

2) Is this picture complete?

3) Can I programmatically change the dimensions in a Sketch?

4) Is it customary (or is there even a way) to group all these Objects together somehow, similar to the compound when doing CSG scripting?

5) Is it possible to script parametric models in python? I think it would be nice to be able to change e.g. the length of a bolt after adding it, which is not possible with the current way of scripting that I know. http://freecadweb.org/wiki/index.php?ti ... _scripting

6) Is it possible to save parametric objects to a portable file format like STEP or IGES?

And on an unrelated topic:

At the moment I am distributing BOLTS for FreeCAD as a Python package and a starter macro with extension .py. This macro appears when I use the Macro->Macros dialog. However, when trying to add a button to a toolbar like described here:
http://freecadweb.org/wiki/index.php?ti ... _to_use.3F
only macros with ectension .FCMacro turn up.

7) I should use FCMacro as extension for my starter script, shouldn't I?

8) Is there a way to set up a toolbar button automatically with icon and everything?

And another one:

9) is there documentation on how to use the test framework workbench? It would be nice to have a possibility to check whether all parts work, and I would prefer to use an existing infrastructure if possible than write something on my own.

Edit: And one about organisation:

10) Is it ok to have all my questions and announcements and discussions in this thread or shall I create separate threads for separate questions?
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
yorik
Site Admin
Posts: 12058
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: BOLTS Open Library of Technical Specifications

Postby yorik » Mon Sep 30, 2013 1:35 pm

Hi!

1+2) These are some of the methods, others would be doing it 100% programmatically (see below). Basically there is no preferred method. It all depends on your preference and the way you want your final object (is it interesting that it is based on a sketch? Or it doesn't matter? etc...). Have a script build an object from scratch, and be able to re-run the script to change the shape of that object, is totally valid parametric behaviour, it is that way that parametric objects work in freecad.

3) You can (explore the contents of App.ActiveDocument.YourSketch, there are several methods such as setDatum()), but it is still not easy to find your constraint among the list of constraints. It is planned to be able to give names to constraints, I think, so they can be found easily, but it is still not implemented.

4) I don't think it is really something needed, but if you need it, check the Draft.makeBlock(), it takes a list of objects and creates a new object which is a parametric compound of the original ones (they are kept linked)

5) Yes, you are referring to the correct page. Check the bottom of Draft.py in the draft module for examples

6) I don't think so...

7) Yes indeed. I wasn't aware of that, but it's just a matter of renaming the file.

8) I don't think so... Only via the GUI

9) There is no doc I believe, but I've been doing that recently for Arch and Draft, check in them, both of them have a test module, that you can call from the Test WB (I think I had to add these somewhere in the Test WB itself, though)

10) As you prefer, i guess...
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: BOLTS Open Library of Technical Specifications

Postby NormandC » Tue Oct 01, 2013 12:14 am

jreinhardt wrote:1) There seem to be different ways to create parametric models in FreeCAD: Using sketches and the partdesign workbench and using parametric primitives and the part workbench, and possibly more. Is there one that is preferred?
As Yorik said, there will be no consensus here. ;) Personally I much prefer the sketch/Part Design approach as I've been using this for many years in one software package or the other in my field of work. But others prefer the CSG method.
jreinhardt wrote:5) Is it possible to script parametric models in python? I think it would be nice to be able to change e.g. the length of a bolt after adding it, which is not possible with the current way of scripting that I know.
Just FYI, in the few parts libraries I've seen/used in a few commercial packages, regular hardware like bolts and washers is usually not parametric. A "dumb" solid is dropped into the assembly. Changing the length of a bolt would be cool, but then wouldn't the user have to change its name/label if it includes the length (as I think it should)? I for one would not expect a bolt to be a fully parametric part with a complex tree.

On the other hand, some other parts in the library would be more interesting if they were fully parametric, like a table. As to should it include a full tree or be a single shape object with parameters to be edited in the Properties tab, I don't have strong feelings for either case.
jreinhardt wrote:With both of these ways, the part that one ends up with seems to consist of several Objects (e.g. a Sketch, a Pad that uses this Sketch, a Pocket that removes something (specified by Sketch2) from the Pad, a Fillet that filletes a few of the edges of the Pocket).
Just some CAD terminology: the sketch/Part Design methodology is very different from the Part or CSG approach. With CSG you do deal with multiple objects, but in Part Design you are actually working on a single object/part that you modify by adding or subtracting material. Those are operations rather than "objects" and they represent the state of your part at this point in its history of creation. The commonly used term for these operations in parametric CAD modeling is "feature".
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Postby jreinhardt » Tue Oct 01, 2013 8:03 am

First of all: Thank you very much both of you for your answers, they help me a lot.

So I think I will more or less stick to my original plan, because all the extensions and gimmicks I thought of seem to be very complex or not offering much additional value.
normandc wrote:Just some CAD terminology: the sketch/Part Design methodology is very different from the Part or CSG approach. With CSG you do deal with multiple objects, but in Part Design you are actually working on a single object/part that you modify by adding or subtracting material. Those are operations rather than "objects" and they represent the state of your part at this point in its history of creation. The commonly used term for these operations in parametric CAD modeling is "feature".
I always find terminology one of the most difficult things to learn when diving into a new field. Most concepts are in the end not so different to something that you have seen before, but getting the terminology is difficult. I have used "object", because this is what the python api calls it (getObject ...).
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: BOLTS Open Library of Technical Specifications

Postby jreinhardt » Mon Oct 07, 2013 1:02 pm

Hi everybody,

I am coming closer to hitting a major milestone with BOLTS (https://github.com/jreinhardt/BOLTS/issues/milestones). Most of the functionality I want to have for the moment is in place.

There are a few remaining questions, mostly revolving around license issues. I am not a lawyer, but I have a rough understanding of how these things work. I am not asking for legal advice, I just want to synchronize my understanding with yours, to make sure I don't do things completely wrong. I do not have questions in a strict sense, but still ask you kindly to comment on the points below.

Also it seems to me that it is a good idea to keep track of licensing terms and authorship from the beginning, to be able to sort out problems with e.g. Debian packaging.

What makes the licensing situation difficult is that there are many different stakeholders involved, and BOLTS consists of many different parts with potentially different licensing terms:

The infrastructure code (https://github.com/jreinhardt/bolttools), that takes care of parsing data files, generating html output, OpenSCAD code, etc. is written exclusively by me and licensed under LGPL 3.0, this is not so much a problem.

The .blt files containing informations, descriptions and metadata about parts and standards, in particular tables of dimensions. These can be contributed by people under a license of their choice:

1. I am not sure what kind of licenses are appropriate for this kind of content. I think CC licenses and copyleft licenses should be fine in principle. I stumbled upon the open data base license http://opendatacommons.org/licenses/odbl/1.0/, but I am not sure whether the advantages really apply to this case. Im the documentation I would suggest a liberal CC license (http://creativecommons.org/licenses/by-sa/3.0/) for contributors that do not have a strong opinion.

2. It is my understanding that the content of such tables is not copyrightable, just the form. So it should be fine to get the numbers from the web sites of vendors or even from the standard documents directly without violating copyright.

The application specific information necessary to create a representation of the part in a CAD application consists of a rather simple .base file and other files like fcstd files, python code, OpenSCAD code or stl files. I expect that this is the part where it is most difficult to keep track of the licenses, because I think in many cases these files will be taken from forum posts, thingiverse or other sources, where the licensing terms might be not clear. And even if the licensing terms are clear, I expect to have content licensed under a diverse selection of licenses.

3. The final part is created using information from the base file and the blt file, e.g. by executing a python function with parameters obtained from a table of dimensions. I tend to consider this a combined work or linking, which would restrict the possible combinations of blt file license and the license of the python code.

4. I think I will have to build a mechanism to make sure that only compatible licenses are used together and also to allow to create a stripped down distribution filtered by license terms (e.g. for inclusion in Debian).

5. I would suggest LGPL or MIT for code (OpenSCAD, python) and a liberal CC license for content (fcstd, stl) files.

6. Is there stored license information in fcstd files that I can query?

The OpenSCAD Backend creates code to glue code fragments together and to make table data available.

7. I would consider this the output of the program and I think this http://www.gnu.org/licenses/gpl-faq.html#GPLOutput applies, so I would include a license header with the license of the source files into the generated code.


Thank you for you input

Johannes



At the moment I have a author field in the blt and base files, would it be more accurate to rename it to copyright?
BOLTS, standard parts library for FreeCAD Thread, Help with Translation