How to show properties in Property Editor in added order

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

How to show properties in Property Editor in added order

Post by Son »

I am writing a python script to create an I-beam. It works so far. However in the script I added the properties in a certain order (please see code below) for convenience and hoped that they would show exactly like that in the Property Editor but apparently they are listed in alphabetical order (please see attached picture). Is there any way it can be scripted for the properties to show in their added order?

Code: Select all

import Part
class IShape:

 def __init__(self,obj):
   obj.Proxy = self
   obj.addProperty("App::PropertyFloat","Length").Length = 60.0
   obj.addProperty("App::PropertyFloat","Depth").Depth = 44.0
   obj.addProperty("App::PropertyFloat","Flange Width").Flange_Width = 16.0
   obj.addProperty("App::PropertyFloat","Web Thickness").Web_Thickness = 1.0
   obj.addProperty("App::PropertyFloat","Flange Thickness").Flange_Thickness = 1.75

 def execute(self,obj):
   ...
Capture.PNG
Capture.PNG (22.29 KiB) Viewed 1404 times
FreeCAD Info:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6706 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: How to show properties in Property Editor in added order

Post by wmayer »

Is there any way it can be scripted for the properties to show in their added order?
No, this is currently impossible because the alphabetical order is caused by using a std::map in https://github.com/FreeCAD/FreeCAD/blob ... rty.h#L136

A std::map has the property to sort all elements by the key value and for a string as key it means they are sorted alphabetically.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: How to show properties in Property Editor in added order

Post by microelly2 »

Code: Select all

obj.addProperty("App::PropertyBool","noExecute" ,"Base")
obj.addProperty("App::PropertyInteger","Degree","Base").Degree=3

obj.addProperty("App::PropertyLink","Meridians","RibCage")
obj.addProperty("App::PropertyInteger","RibCount","RibCage").RibCount=10

obj.addProperty("App::PropertyInteger","MeshUCount","Mesh").MeshUCount=5
obj.addProperty("App::PropertyInteger","MeshVCount","Mesh").MeshVCount=5

obj.addProperty("App::PropertyLink","ribtemplateSource","Spreadsheet")
obj.addProperty("App::PropertyLink","backboneSource","Spreadsheet")
obj.addProperty("App::PropertyBool","externSourcesOff" ,"Spreadsheet")
A workaround is to group the properties.
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

Re: How to show properties in Property Editor in added order

Post by Son »

Thank you all for your help.

microelly2: I will try grouping the properties when I get home.
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

Re: How to show properties in Property Editor in added order

Post by Son »

The properties are organized better with groups. They are still sorted alphabetical within a group so I made up some names to help with that, a little awkward but they'll do for now. 8-)

Code: Select all

   lenGrpName = "Beam Length"
   obj.addProperty("App::PropertyFloat","Length",lenGrpName).Length = 60.0

   sxnGrpName = "Cross Section"
   obj.addProperty("App::PropertyFloat","Depth",sxnGrpName).Depth = 44.0
   obj.addProperty("App::PropertyFloat","FlangeWidth",sxnGrpName).FlangeWidth = 16.0
   obj.addProperty("App::PropertyFloat","ThicknessWeb",sxnGrpName).ThicknessWeb = 1.0
   obj.addProperty("App::PropertyFloat","ThicknessFlange",sxnGrpName).ThicknessFlange = 1.75
Capture2.PNG
Capture2.PNG (8.17 KiB) Viewed 1344 times
Post Reply