Hello everyone,
I have submitted an on FreeCAD bug tracker a week ago: https://www.freecadweb.org/tracker/view.php?id=3518
Issue description:
When I try to merge a parametric object in a new document, its expressions are not updated. For eg. suppose we have a parametric object which has an expression "object.Length.Value". And when I try to merge this object in some document which already have some objects, the newly merge object named as "object001" but its expression remains the same (i.e "object.Length.Value"). I expected that newly expression should changed as "object001.Length.Value".
Now, I am working on this issue but please guide me, where is the code related to expression present in the FreeCAD source code.
Thanks,
0003518: Expressions (fx) not updated
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 602
- Joined: Tue Jan 29, 2013 10:35 pm
Re: 0003518: Expressions (fx) not updated
Thank you for looking into this issue; I have had too little time to work on FreeCAD lately.amrit3701 wrote: ↑Sat Jun 30, 2018 6:47 am Hello everyone,
I have submitted an on FreeCAD bug tracker a week ago: https://www.freecadweb.org/tracker/view.php?id=3518
Issue description:
When I try to merge a parametric object in a new document, its expressions are not updated. For eg. suppose we have a parametric object which has an expression "object.Length.Value". And when I try to merge this object in some document which already have some objects, the newly merge object named as "object001" but its expression remains the same (i.e "object.Length.Value"). I expected that newly expression should changed as "object001.Length.Value".
Now, I am working on this issue but please guide me, where is the code related to expression present in the FreeCAD source code.
Every DocumentObject has an ExpressionEngine property, and this property keeps all expressions entered into a DocumentObject. In the merge function, you need to visit each expression and rename objects that are referenced there.
Relevant source code files are:
App/DocumentObject.{cpp,h} (contains the ExpressionEngine property)
App/Expression.{cpp,h}
App/ExpressionVisitors.{cpp,h} (contains renaming visitors; most likely relevant for you, either directly or as inspiration).
Eivind
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: 0003518: Expressions (fx) not updated
Actually, I wouldn't consider it a bug.
object.Length.Value, from your description, appears to be a self-reference. When self-referencing, I would use Length.Value, i.e. drop the object name. Since you explicitly specified the object name in the expression, if I were ExpressionEngine, I would assume that you mean "object named 'object' and nothing else".
BTW...
Expression object.Length.Value is strange, I've never seen such an expression. Particularly the .Value part of it. Could you explain, what Length property has a subproperty?
object.Length.Value, from your description, appears to be a self-reference. When self-referencing, I would use Length.Value, i.e. drop the object name. Since you explicitly specified the object name in the expression, if I were ExpressionEngine, I would assume that you mean "object named 'object' and nothing else".
BTW...
Expression object.Length.Value is strange, I've never seen such an expression. Particularly the .Value part of it. Could you explain, what Length property has a subproperty?
Re: 0003518: Expressions (fx) not updated
The subproperty was coded in the quantity object, in order to allow a transition from python code before existance of quantity to FreeCAD with quantity. The subproperty Value supplies the pure number without unit string. This is what I remember from python coding.
Ulrich
Re: 0003518: Expressions (fx) not updated
Here Length property belongs to App::PropertyLength.DeepSOIC wrote: ↑Sat Jun 30, 2018 11:12 am Actually, I wouldn't consider it a bug.
object.Length.Value, from your description, appears to be a self-reference. When self-referencing, I would use Length.Value, i.e. drop the object name. Since you explicitly specified the object name in the expression, if I were ExpressionEngine, I would assume that you mean "object named 'object' and nothing else".
BTW...
Expression object.Length.Value is strange, I've never seen such an expression. Particularly the .Value part of it. Could you explain, what Length property has a subproperty?
Let me explain with some example.
Suppose, I have two objects (Cone and Box) in a document (testingexp.fcstd). The length, width, and height of Box depend on Cone height.
Code: Select all
>>> obj = App.getDocument("testingexp").getObject("Box")
>>> obj.ExpressionEngine
[('Height', 'Cone.Height'), ('Width', 'Cone.Height'), ('Length', 'Cone.Height')]
Code: Select all
>>> obj = App.getDocument("Unnamed").getObject("Box")
>>> obj.ExpressionEngine
[('Height', 'Cone.Height'), ('Width', 'Cone.Height'), ('Length', 'Cone.Height')]
>>> obj = App.getDocument("Unnamed").getObject("Box001")
>>> obj.ExpressionEngine
[('Height', 'Cone.Height'), ('Width', 'Cone.Height'), ('Length', 'Cone.Height')]
- Attachments
-
- after_merging_testingexp_two_times.fcstd
- (7.17 KiB) Downloaded 25 times
-
- testingexp.fcstd
- (4.6 KiB) Downloaded 27 times
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: 0003518: Expressions (fx) not updated
OK, thanks for clearing it up. It's not a self-reference, and indeed a bug.
Re: 0003518: Expressions (fx) not updated
For my taste that is at the border of things I want to happen automatically.
In your example you use the internally created names of objects. That this leads to problems, if you merge some of them into another model where the same names are used seems to be obvious. If you rename your object to something sensible and refer in the expression to that notion you have no problem keeping the references when copying.
Instead of remapping things I would prefer to mark the objects and tell the user via error messages that references have to be looked after.
In your example you use the internally created names of objects. That this leads to problems, if you merge some of them into another model where the same names are used seems to be obvious. If you rename your object to something sensible and refer in the expression to that notion you have no problem keeping the references when copying.
Instead of remapping things I would prefer to mark the objects and tell the user via error messages that references have to be looked after.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.