In need of a FreeCAD macro cont… Getting hung up on step 1

I’ve been playing around a bit with Python FreeCAD macros.   (They’re sort of fun once you understand the indentation requirements).   My objective is to develop a generic macro, while solving a specific problem.

Specific Problem to be Solved
I have my modified Sherline saddle and I need to model the x-axis ball screw.   This new part needs to orientated in space so it within the bore of the the modified saddle. (This makes it easy to virtually assemble the mill, by importing individual step file(exported from individual part files))

The First part of  the Plan
I detailed the overall plan in a previous blog post.  Suffice it to say, what I need to do at this point (no pun) is to programmatically extract the the world coordinates of centerpoint of  the x-axis counterbore on the saddle.

ExampleofSelectionViewNew stuff I learned
In FreeCAD you can select an object[s] by clicking[shift-clicking] objects in a view or by selecting it in the tree-view(or items within combo view project).  The names of the selected elements by  enabling the selection view ( view->views->selection view).   So I selected the point that I want to extract.

So after a conversation with Daniel Falck, I found out that there are two ways to programatically gain access to a selected object.

  • To access an Object selected from a view: Gui.Selection.getSelectionEx():
  • To access an Object selected from Treeview: Gui.Selection.getSelection():

Daniel was kind enough to post a link of some of his python utilities. http://pastebin.com/LvVfLsts along with some advice/tricks on how to access the underlying methods/properties of those objects.

The conundrum
I got stopped dead in my tracks of my goal of extracting the coordinates of what was going on.   I kept getting this error message:

>>> for o in Gui.Selection.getSelectionEx():
...    print "ObjectName: ", o.ObjectName
...    print '---------------------------'
...    for s in o.SubElementNames:
...      print " name: ",s
...      print '---------------------------'
...    for s in o.SubObjects:
...      print " object: ",s
...      print " ShapeType: ",s.ShapeType
...      print " Type: ", s.Type
...      print " Check: ", s.check()
...      if s.ShapeType == "Vertex":
...         print " Point: ", s.Point
...    print '++++++++++++++++++++++++'
...
ObjectName: Sketch008
---------------------------
name: Vertex0
---------------------------

Traceback (most recent call last):
File ““, line 7, in
Exception: Unknown exception while reading attribute ‘SubObjects’ of object ‘SelectionObject’

>>>
It took me a while to figure out what was going on.  It seems that that if the selected point is connected to an edge linked to an external geometry, these problems occured ;(

PointExtractionWorksAs a check, I created a solid with a sketch that was not linked to an external geometry.  When I clicked on a point and ran the script it ran just fine as you can see.

Ugg… my theory is that is some code that hasn’t been implemented yet with a link to external geometry that causes the point not to be returned.   I need to have the experts look at this.
[Edit]

This may be coincidence that my test worked here.  According to wmayer there is currently a bug in sketch edit in element counting.   If a point is selected outside sketch edit, it a non issue. (View=>appearance and select flat lines will make points selectable)   Unfortunately center points of arcs are not displayed at this point. ;*(

 

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to In need of a FreeCAD macro cont… Getting hung up on step 1

  1. James Dawson says:

    I happened upon your site, which is very fascinating, as I was trying to find out if FreeCAD had a way to toggle from Metric to English. I read you had found no means, and it seems you had nothing more to say about it due to this. I’m just getting into 3d modeling to have some items 3dprinted. While my preference is English I need software that’s free so I might be limited. Aside from the Metric aspect, is there anything about FreeCAD that isn’t desirable? Would you have another freeware recommendation that would allow me to accomplish the same (I have very little 3d experience; Photoshop and InDesign are my knowledge base). So, I need something pretty user-friendly. Thank you! James Dawson

  2. admin says:

    Hey James,
    I’ve been out of the freecad development loop, but I had caught something about a unit converter being being in the .14 development release.

    There’s a post in the forum that talks about it. http://forum.freecadweb.org/viewtopic.php?f=8&t=5177&hilit=inch

    FreeCAD has come a long way. I’ve heard some people say that the interphase could be more intuitive, but I’m pretty used to it. To me anyway, its seems far more intuitive than blender. I’ve modeled quite a few things in Freecad to print out and I’ve been very pleased with the result.

Leave a Reply

Your email address will not be published. Required fields are marked *