How to get last time of modification of object?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
usbhub
Posts: 280
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

How to get last time of modification of object?

Post by usbhub »

Hello,
I'm programming a macro that creates meshes among other things. But it can take a lot of time to get a mesh with a high resolution so I got the idea to create a mesh, write it temoprary down to the temporary folder and if you restart the macro, it looks for the time of last modification on an object and if it isn't modified since the last start of the macro, the macro can use the mesh from the temporary folder.

With search in the python console and Google I found nothing in this direction.

Is there any solution or is that not intended?

regards
usbhub
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: How to get last time of modification of object?

Post by ezzieyguywuf »

os.path has a method for checking modification time.

Is that what you’re looking for?

Writing to and reading from the hard drive is incredibly “slow” : are you sure this will save any time?

How long does the mesh operation take?

What do you mean by “restart the macro”? Can the user arbitrarily make changes and re-trigger the mesh operation? If so, how will a cache help?
usbhub
Posts: 280
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: How to get last time of modification of object?

Post by usbhub »

ezzieyguywuf wrote: Sun Dec 01, 2019 1:35 am os.path has a method for checking modification time.

Is that what you’re looking for?
No, I think, there's a misapprehension. I dont't want to check the time of the file, I want to check the time of the object in FreeCAD (e.g a cube).
Writing to and reading from the hard drive is incredibly “slow” : are you sure this will save any time?

How long does the mesh operation take?
Yes, this will save a lot of time, I think. The mesh operation can take about 10 minutes for complex object with a lot of roundings. My macro is for rendering, so it needs a pretty high resolution.
What do you mean by “restart the macro”? Can the user arbitrarily make changes and re-trigger the mesh operation? If so, how will a cache help?
Yes, the user can restart the macro if he want to do another rendering. But often only one little object is changed and every object, the unchanged objects too, have to be "remeshed".
ezzieyguywuf
Posts: 656
Joined: Tue May 19, 2015 1:11 am

Re: How to get last time of modification of object?

Post by ezzieyguywuf »

usbhub wrote: Tue Dec 03, 2019 7:34 pm I dont't want to check the time of the file, I want to check the time of the object in FreeCAD (e.g a cube).
If this is the case, I don't think necessarily checking "time" is what you want here. For example, consider the following pseudocode:

Code: Select all

toMesh = getAllObjectsInCurrentDocument()
myMeshInfo = {}
for item in toMesh:
    processItem = True
    if item.name in myMeshInfo.keys():
        oldObj = myMeshInf[item.name]
        if oldObj == item:
            processItem = False
     if processItem:
            processNewItemInRenderFunction(item)
    myMeshInfo[item.name] = item
In other words, any time you go to do your "mesh" stuff, store a copy of each item that you are meshing. Now, whenever you go to re-mesh, you can first check if the item has actually changed or not.

Granted, this approach will double the amount of RAM needed for a given model, but it may be worth it for the improved cycle time of the render operation?
usbhub
Posts: 280
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: How to get last time of modification of object?

Post by usbhub »

ezzieyguywuf wrote: Tue Dec 03, 2019 8:21 pm

Code: Select all

toMesh = getAllObjectsInCurrentDocument()
myMeshInfo = {}
for item in toMesh:
    processItem = True
    if item.name in myMeshInfo.keys():
        oldObj = myMeshInf[item.name]
        if oldObj == item:
            processItem = False
     if processItem:
            processNewItemInRenderFunction(item)
    myMeshInfo[item.name] = item
In other words, any time you go to do your "mesh" stuff, store a copy of each item that you are meshing. Now, whenever you go to re-mesh, you can first check if the item has actually changed or not.

Granted, this approach will double the amount of RAM needed for a given model, but it may be worth it for the improved cycle time of the render operation?
The higher RAM need is not a problem I think. But I don't understand your pseudo code.

But I find another option, I think:
A shape has the method isEqual() and I think, I can use this for check for equality.

But thank you very much!!!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to get last time of modification of object?

Post by Kunda1 »

usbhub wrote: Thu Dec 05, 2019 9:05 pm But I find another option, I think:
A shape has the method isEqual() and I think, I can use this for check for equality.
Could you share your solution in that case?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
usbhub
Posts: 280
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: How to get last time of modification of object?

Post by usbhub »

Kunda1 wrote: Thu Dec 05, 2019 10:07 pm
usbhub wrote: Thu Dec 05, 2019 9:05 pm But I find another option, I think:
A shape has the method isEqual() and I think, I can use this for check for equality.
Could you share your solution in that case?
I will, but actually I have not so much time for implementing this feature. But when it is finished, I will share my solution.
Post Reply