Problem Statement
I have a Block called "Block1". In the Block I have inserted a standard Property type with name "est_Mass". I want to define the Initial Value of using a script (which pulls the number from somewhere else). However I couldn't find a way to do so.
My pseudocode was as follows
define theBlock as EA.Element;
theBlock = Repository.GetTreeSelectedObject();
someValue = 49;
numOfElements = theBlock.Elements.Count;
counter = 0;
while (counter < numOfElements) {
if (theBlock.Elements.GetAt(counter).Name = "est_Mass"){
//how to set the "Initial" value for this property to someValue?
}
counter = counter + 1;
}
Solution with CustomProperties
Updated based on the provided answers and re-iterated here in JavaScript for completeness
I've written a script that updates the 'default' value using the CustomProperties class.
Script
var theBlock as EA.Element;
var eaPart as EA.Element;
var numOfElements;
var numOfCustomProperties;
var someValue = 49;
let counter = 0;
let customPropCounter = 0;
theBlock = Repository.GetTreeSelectedObject();
numOfElements = theBlock.Elements.Count;
//loop through elements that are owned by the Block
loop:
while (counter < numOfElements){
if (theBlock.Elements.GetAt(counter).Name === "est_Mass"){
eaPart = theBlock.Elements.GetAt(counter);
numOfCustomProperties = eaPart.CustomProperties.Count;
//loop through custom properties of the desired part
while (customPropCounter < numOfCustomProperties) {
if (eaPart.CustomProperties.GetAt(customPropCounter).Name === "default") {
Session.Output( `***\n Before assignment ${eaPart.CustomProperties.GetAt(customPropCounter).Name} \
custom property of ${theBlock.Elements.GetAt(counter).Name} \
is ${eaPart.CustomProperties.GetAt(customPropCounter).Value} \n***`);
//assign new value
eaPart.CustomProperties.GetAt(customPropCounter).Value = someValue;
//update the part that owns the custom propert
eaPart.Update();
Session.Output( `***\n After assignment ${eaPart.CustomProperties.GetAt(customPropCounter).Name} \
custom property of ${theBlock.Elements.GetAt(counter).Name} \
is ${eaPart.CustomProperties.GetAt(customPropCounter).Value} \n***`);
//let's get outta here
break loop;
}
customPropCounter = customPropCounter + 1;
}
}
counter = counter + 1;
}
Output
***
Before assignment default custom property of est_Mass is 0
***
***
After assignment default custom property of est_Mass is 49
***
Close the diagram that shows the block and reopen it. The value for the "est_Mass" is now 49



