How to add lost Origin?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
kisolre
Veteran
Posts: 4166
Joined: Wed Nov 21, 2018 1:13 pm

How to add lost Origin?

Post by kisolre »

As posted here https://forum.freecadweb.org/viewtopic.php?f=3&t=33351 one could lose the Origin of an object. But is there an easy way to add it back? Missing the Origin does not allow to add extra sketches so no further editing is possible. I could add sketches based on existing faces but since their names can change in any moment that could easily brake all subsequent edits.
chrisb
Veteran
Posts: 54313
Joined: Tue Mar 17, 2015 9:14 am

Re: How to add lost Origin?

Post by chrisb »

I don't know of any possiblity to do this without scripting - besides creating a new body and move everything there. So I moved it to the Python forum.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
MIngB
Posts: 30
Joined: Sat Jan 28, 2017 5:01 pm

Re: How to add lost Origin?

Post by MIngB »

It's difficult to figure out what's an Origin...
so I check for

Code: Select all

len(dobj.OutList)>=6 and dobj.OutList[0].__class__.__name__ == 'GeoFeature'
an Object with at least 6 Outlist and 1st has to be a Geofeature


here is my Code that creates new GeoFeatures for Origins that share Geofeatures.

Still needs to be improved if
- Sketches are involved
- Origins are shared
- GeoFeatures already missing
- Origins already missing

Any Help welcome!

Code: Select all

myDoc = App.activeDocument()
for obj in myDoc.Objects:
  if str(obj.__class__.__name__) == 'GeoFeature':
    objList = [
      dobj for dobj in obj.InList 
        if len(dobj.OutList)>=6 and dobj.OutList[0].__class__.__name__ == 'GeoFeature']
    if len(objList)>1 and len(objList) == len(obj.InList):
      print("{} -> {}:".format(obj.Label, obj.InList[0].Label))
      for ori in obj.InList[1:]:
        newO = App.activeDocument().addObject('App::Origin','Origin')
        for InObj in newO.OutList: InObj.Visibility = False
        ori.OriginFeatures = newO.OriginFeatures
        newO.OriginFeatures = []
        App.activeDocument().removeObject(newO.Name)
        print(" - {}:".format(ori.Label))
        for bdy in ori.InList:
          print(" --- {}:".format(bdy.Label))

It goes throw all Object in Document and looks for GeoFeatures.
Then finds Origins as described above, in the Outlist of each Geofeature.
If there are more than one Origin and only these Origin are shared (handle Sketches missing here),
the GeoFeatures of a new Origin are given to the other Origin(s).
Post Reply