Description:
How Can I Change the Attribute Sort Order Using The API?
Solution:
Solution reproduced in its entirety from,
http://wb.itboards.com/WB/default.asp?action=9&boardid=10&read=173301&fid=1323
Managed to figure it out. Pseudo code below for those interested or in need of it in the future.
One thing to point out, the API appears to automatically order the PK attributes at the top of the list. So if you try to order something like the following:
Attrib-4
[PK] Attrib-2
Attrib-3
[PK] Attrib-1
The attributes will automatically be ordered as:
[PK] Attrib-2
[PK] Attrib-1
Attrib-4
Attrib-3
This is somewhat expected though in order to mimic what is dispayed in the GUI.
Dim SCSession As SCAPI.SESSION
Dim SCEntityObj As SCAPI.ModelObject
Dim SCEntityObjProperty As SCAPI.ModelProperty
Dim strEntityObjectID As String
strEntityObjectID = "{E091F2DE-6CAA-463D-9E12-2E4981188ACD}+00000000" ' <-- Replace with your entity object ID
' [Create session]
' [Begin transaction]
Set SCEntityObj = SCSession.ModelObjects.Item(strEntityObjectID)
If Not (SCEntityObj Is Nothing) Then
' Get attribute order entity property
Set SCEntityObjProperty = SCEntityObj.Properties.Item("Attributes_Order_Ref")
' --------------------------------------------------------------------
' To replace entire attribute order list with a new one...
' --------------------------------------------------------------------
' Remove existing order
SCEntityObjProperty.RemoveAllValues
' Add new order of attribute object IDs
SCEntityObjProperty.value(0, SCVT_OBJID) = "{FD10E0EA-D30F-4507-9D22-AE0C90F46BDA}+00000000" ' <-- Replace with your attribute object ID
SCEntityObjProperty.value(1, SCVT_OBJID) = "{FD10E0EA-D30F-4507-9D22-AE0C90F46BDA}+00000000"' <-- Replace with your attribute object ID
' etc...
Set SCEntityObj = Nothing
' --------------------------------------------------------------------
' OR, to set the order of an attribute at a particular location, X...
' --------------------------------------------------------------------
SCEntityObjProperty.value(X, SCVT_OBJID) = "{FD10E0EA-D30F-4507-9D22-AE0C90F46BDA}+00000000" ' <-- Replace with your attribute object ID
' [Commit transaction]
' [Save file]
Else
' [Rollback Transaction]
End If
' [Close session]
Comments
0 comments
Please sign in to leave a comment.