How to show properties in Property Editor in added order

Need help, or want to share a macro? Post here!
Son
Posts: 3
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

How to show properties in Property Editor in added order

Postby Son » Mon Mar 20, 2017 5:34 am

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 92 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
Site Admin
Posts: 11222
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Mon Mar 20, 2017 9:31 am

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
Posts: 2356
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

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

Postby microelly2 » Mon Mar 20, 2017 10:20 am

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: 3
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

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

Postby Son » Mon Mar 20, 2017 3:54 pm

Thank you all for your help.

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

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

Postby Son » Tue Mar 21, 2017 5:33 am

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 32 times