How to add lost Origin?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
How to add lost Origin?
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.
Re: How to add lost Origin?
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.
Re: How to add lost Origin?
It's difficult to figure out what's an Origin...
so I check for
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!
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).
so I check for
Code: Select all
len(dobj.OutList)>=6 and dobj.OutList[0].__class__.__name__ == '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))
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).