Can't use named constraints in 0.20 202112202219

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
mfraz74
Posts: 158
Joined: Mon Apr 05, 2021 9:19 am
Contact:

Can't use named constraints in 0.20 202112202219

Post by mfraz74 »

If I create a rectangle in Sketcher and name a horizontal constraint for one side SideLength I get an error box appear saying No attribute named 'SideLength' and if I try to use it in a formula for the width of the rectangle it isn't recognised. I have to use Constraints[10] instead.

If I go back into that formula to edit it, it is changed to ".Constraints.SideLength" and again I see "No attribute named 'SideLength'"

Report view shows:

14:46:21 <Exception> ObjectIdentifier.cpp(622): No attribute named 'SideLength'
14:46:25 <Exception> ObjectIdentifier.cpp(622): No attribute named 'SideLength'
14:47:25 <Exception> ObjectIdentifier.cpp(622): No attribute named 'SideLength'
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by onekk »

Maybe with a file it would be easy to reproduce the behaviour and see if it is an error.

In case of a reserved file. Could you put together a Minimal Working Example file that produce the behaviour.

I deliberately not use "error" as maybe it is an expected behaviour due to some missing things or other quirks.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
mfraz74
Posts: 158
Joined: Mon Apr 05, 2021 9:19 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by mfraz74 »

onekk wrote: Tue Dec 21, 2021 4:45 pm Maybe with a file it would be easy to reproduce the behaviour and see if it is an error.

In case of a reserved file. Could you put together a Minimal Working Example file that produce the behaviour.

I deliberately not use "error" as maybe it is an expected behaviour due to some missing things or other quirks.

Regards

Carlo D.
In the attached file, if I try to use a formula based on the length (SideLong) to constrain the width with Constraints.SideLong. I get "No attribute named 'SideLong', but Constraints[10] works.

Don't know if it is related, but in data view of the sketch
Rectangle Constraints.FCStd
(9.86 KiB) Downloaded 21 times
The constraint is called Side Long.
Attachments
Screenshot_20211221_165346.png
Screenshot_20211221_165346.png (27.94 KiB) Viewed 2484 times
drmacro
Veteran
Posts: 8867
Joined: Sun Mar 02, 2014 4:35 pm

Re: Can't use named constraints in 0.20 202112202219

Post by drmacro »

Confirmed behaviour in build with today's source.

OS: Debian GNU/Linux 10 (buster) (XFCE/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.20.26720 (Git)
Build type: Release
Branch: master
Hash: 283b0a63824fd33b4f5a79c42e3f9ba7d0bd342b
Python version: 3.7.3
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by Syres »

All I can add, is it definitely worked with Git revision 0.20.26683, hash acfde1a4b655cee307e3a8fc0066ca5c1dc2fdc9. Looks like some Git Bisecting is required as unless I'm completely blind (quite possible) I don't see an obvious candidate for the regression. If no-one's pinned it down by tomorrow morning UK time I'll have a crack at it.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by chrisb »

chennes is working on the expressions.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by onekk »

A side nite if you active Python Console and modify Constraints Side Long what is appearing.

It could be that simply Side_Long is became the New Name.

In many places FreeCAD translate space and - and other characters to _ (underscore) so maybe something is changed in exposition of "variable names".

It is a rough guess but trying is not si difficult.

As someone that has deep knowledge of FreeCAD internals has told you that @chennes is working on it maybe us only a temporary regression due maybe to some "Work in Progress" in some methods.

Regards
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
mfraz74
Posts: 158
Joined: Mon Apr 05, 2021 9:19 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by mfraz74 »

One further issue of note. If I rename the original name from SideLong to something else, I get an error saying "No attribute named '...'" and where I have used Constraints[10] in the formula for the width is replaced by this new name and also says "No attribute named '...'".
User avatar
mfraz74
Posts: 158
Joined: Mon Apr 05, 2021 9:19 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by mfraz74 »

onekk wrote: Tue Dec 21, 2021 8:39 pm A side nite if you active Python Console and modify Constraints Side Long what is appearing.

It could be that simply Side_Long is became the New Name.

In many places FreeCAD translate space and - and other characters to _ (underscore) so maybe something is changed in exposition of "variable names".

It is a rough guess but trying is not si difficult.

As someone that has deep knowledge of FreeCAD internals has told you that @chennes is working on it maybe us only a temporary regression due maybe to some "Work in Progress" in some methods.

Regards
Does this help at all?

Code: Select all

Python 3.9.9 (main, Nov 20 2021, 00:05:03) 
[GCC 10.3.0] on linux
Type 'help', 'copyright', 'credits' or 'license' for more information.
MRU="0"
with open('/usr/share/freecad-daily/Mod/Start/StartPage/LoadMRU.py') as file:
	exec(file.read())
FreeCAD.openDocument('/home/mfraser/Pictures/FreeCAD/Rectangle Constraints.FCStd')
# App.setActiveDocument("Rectangle_Constraints")
# App.ActiveDocument=App.getDocument("Rectangle_Constraints")
# Gui.ActiveDocument=Gui.getDocument("Rectangle_Constraints")
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.')
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Edge2',3.17461,29.3883,0)
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Edge2',20,29.3883,0)
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.',20,29.3883,0)
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.')
# Gui.Selection.clearSelection()
ActiveSketch = App.getDocument('Rectangle_Constraints').getObject('Sketch')
tv = Show.TempoVis(App.ActiveDocument, tag= ActiveSketch.ViewObject.TypeId)
ActiveSketch.ViewObject.TempoVis = tv
if ActiveSketch.ViewObject.EditingWorkbench:
  tv.activateWorkbench(ActiveSketch.ViewObject.EditingWorkbench)
if ActiveSketch.ViewObject.HideDependent:
  tv.hide(tv.get_all_dependent(App.getDocument('Rectangle_Constraints').getObject('Body'), 'Sketch.'))
if ActiveSketch.ViewObject.ShowSupport:
  tv.show([ref[0] for ref in ActiveSketch.Support if not ref[0].isDerivedFrom("PartDesign::Plane")])
if ActiveSketch.ViewObject.ShowLinks:
  tv.show([ref[0] for ref in ActiveSketch.ExternalGeometry])
  tv.sketchClipPlane(ActiveSketch, ActiveSketch.ViewObject.SectionView)
tv.hide(ActiveSketch)
del(tv)
del(ActiveSketch)

import PartDesignGui
ActiveSketch = App.getDocument('Rectangle_Constraints').getObject('Sketch')
if ActiveSketch.ViewObject.RestoreCamera:
  ActiveSketch.ViewObject.TempoVis.saveCamera()
  if ActiveSketch.ViewObject.ForceOrtho:
    ActiveSketch.ViewObject.Document.ActiveView.setCameraType('Orthographic')

# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Constraint11',4.60317,36.0317,0.009,False)
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Edge1',50,-6.19048,0.008,False)
# Gui.Selection.removeSelection('Rectangle_Constraints','Body','Sketch.Edge1')
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Edge1',50,-2.53968,0.008,False)
### Begin command Sketcher_ConstrainDistanceY
App.getDocument('Rectangle_Constraints').getObject('Sketch').addConstraint(Sketcher.Constraint('DistanceY',0,1,0,2,58.776592)) 
App.getDocument('Rectangle_Constraints').Sketch.setExpression('Constraints[11]', u'Constraints[10] / 2')
App.ActiveDocument.recompute()
App.ActiveDocument.recompute()
### End command Sketcher_ConstrainDistanceY
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Constraint11',3.49207,32.0635,0.009,False)
App.getDocument('Rectangle_Constraints').getObject('Sketch').setDatum(10,App.Units.Quantity('100.000000 mm'))
App.getDocument('Rectangle_Constraints').getObject('Sketch').renameConstraint(10, u'SideLongNew')
# Gui.Selection.clearSelection()
# Gui.Selection.addSelection('Rectangle_Constraints','Body','Sketch.Constraint12',43.1746,-3.65079,0.009,False)
# Gui.Selection.clearSelection()
Last edited by mfraz74 on Wed Dec 22, 2021 7:35 am, edited 1 time in total.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by chrisb »

Put the Python code in code tags for improved readability. You can for further improvement copy only the code, without the leading ">>>".
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply