Renaming point throws error [Solved]

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Renaming point throws error [Solved]

Post by jfc4120 »

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: English/United States (en_US)
Installed mods: 
  * Help 1.0.3

The follow code works when it's the original name Point. But renaming to StartPoint throws the following error.

Code: Select all

(X1, Y1, Z1) = (doc.getObject('Point').Shape.Point.x, doc.getObject('Point').Shape.Point.y, doc.getObject('Point').Shape.Point.z)

###### That works.
Is it not allowed to do renaming?

line 84, in <module>
(X1, Y1, Z1) = (doc.getObject('StartPoint').Shape.Point.x, doc.getObject('StartPoint').Shape.Point.y, doc.getObject('StartPoint').Shape.Point.z)
<class 'AttributeError'>: 'NoneType' object has no attribute 'Shape'
Last edited by jfc4120 on Wed Jul 27, 2022 2:32 pm, edited 1 time in total.
edwilliams16
Veteran
Posts: 3182
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Renaming point throws error

Post by edwilliams16 »

You changed the Label, not the Name. FreeCAD controls the Name. https://wiki.freecadweb.org/Object_name ... 0document.

Check

Code: Select all

doc.getObjectsByLabel('StartPoint')[0]
jfc4120
Posts: 448
Joined: Sat Jul 02, 2022 11:16 pm

Re: Renaming point throws error

Post by jfc4120 »

Changed to:

Code: Select all

(X1, Y1, Z1) = (doc.getObjectsByLabel('StartPoint').Shape.Point.x, doc.getObjectsByLabel('StartPoint').Shape.Point.y, doc.getObjectsByLabel('StartPoint').Shape.Point.z)
Error:
line 86, in <module>
(X1, Y1, Z1) = (doc.getObjectsByLabel('StartPoint').Shape.Point.x, doc.getObjectsByLabel('StartPoint').Shape.Point.y, doc.getObjectsByLabel('StartPoint').Shape.Point.z)
<class 'AttributeError'>: 'list' object has no attribute 'Shape'
I am going to try a couple of other things.

Edit tried:

Code: Select all

(X1, Y1, Z1) = (doc.getObjectsByLabel('StartPoint')[0].Point.x, doc.getObjectsByLabel('StartPoint')[0].Point.y, doc.getObjectsByLabel('StartPoint')[0].Point.z)
Following: https://wiki.freecadweb.org/Object_name ... e_or_Label

Error:

'
line 86, in <module>
(X1, Y1, Z1) = (doc.getObjectsByLabel('StartPoint')[0].Point.x, doc.getObjectsByLabel('StartPoint')[0].Point.y, doc.getObjectsByLabel('StartPoint')[0].Point.z)
<class 'AttributeError'>: 'FeaturePython' object has no attribute 'Point
Maybe I can't rename a point, was hoping I could.

Sorry another edit:

I believe I got it, some trial and error:

Code: Select all

obj1 = App.ActiveDocument.getObjectsByLabel("StartPoint")[0].Shape.Point.x
obj2 = App.ActiveDocument.getObjectsByLabel("StartPoint")[0].Shape.Point.y
obj3 = App.ActiveDocument.getObjectsByLabel("StartPoint")[0].Shape.Point.z
print('ob',obj1)
print('ob',obj2)
print('ob',obj3)
Seems you have to do x,y,z separately.
edwilliams16
Veteran
Posts: 3182
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Renaming point throws error

Post by edwilliams16 »

jfc4120 wrote:
Seems you have to do x,y,z separately.
Not true. Look at what you typed.
Use command completion to test your code statements and you wont make these errors.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Renaming point throws error

Post by heda »

jfc4120 wrote: Wed Jul 27, 2022 4:51 am I believe I got it, some trial and error:
good, exploring things in fc-py-console along with printing here and there carries great mileage. (so does reading error messages :-)).

"Seems you have to do x,y,z separately."

not really, there is a difference...

Code: Select all

doc.getObjectsByLabel('StartPoint')[0].Point.x
vs
doc.getObjectsByLabel("StartPoint")[0].Shape.Point.x
btw, there is a shorter way to grab individual coord-components

Code: Select all

x, y, z = list(doc.getObjectsByLabel("StartPoint")[0].Shape.Point)
at last, please mark your posts with [solved] when you think they are
Post Reply