how to use a variable name in checkpoint?
I have below code :
function CheckFeatures()
{
var i,featureItem,featureName;
SelectFeatureTree()
for(i=0;i<12;i++)
{
featureItem = FeatureTree.wItems.Item(0).Items.Item(3).Items.Item(i);
featureName = featureItem.Text;
featureName = name(featureName)
Regions.featureName.Check(Aliases.SLDWORKS.dlgFeatureParameters.Window("SysListView32", "", 1));
}
There are 12 feature Items for which there are 12 region items with names same as feature items.
I want to compare these region items with their respective feature items using region checkpoint.
So I have created a for loop, and featureName which is obtained want to use in region checkpoint.
For example :
for i = 0, featureName = Punch and Region Item present is also with name Punch.
So region checkpoint will be
Regions.Punch.Check(Aliases.SLDWORKS.dlgFeatureParameters.Window("SysListView32", "", 1));
Now to use it in for loop I replace Punch with featureName but get this error "'Regions.featureName' is null or not an object Error location"
Where am I going wrong ?
In above code, I assign name of object to featureName and I want to use this
A neat trick that HKosova showed me recently is that, if you're using JScript/JavaScript, you can change dot syntax to bracket syntax. So, try the following:
function CheckFeatures() { var i,featureItem,featureName; SelectFeatureTree() for(i=0;i<12;i++) { featureItem = FeatureTree.wItems.Item(0).Items.Item(3).Items.Item(i); featureName = featureItem.Text; featureName = name(featureName) Regions[featureName].Check(Aliases.SLDWORKS.dlgFeatureParameters.Window("SysListView32", "", 1)); }
Now, this assumes that you actually have regions stored in Stores.Regions named for each of your feature names. However, this SHOULD work. Give it a go.
If that doesn't work, you might have to resort to eval
function CheckFeatures() { var i,featureItem,featureName, featureRegion; SelectFeatureTree() for(i=0;i<12;i++) { featureItem = FeatureTree.wItems.Item(0).Items.Item(3).Items.Item(i); featureName = featureItem.Text; featureName = name(featureName) featureRegion = eval('Regions.' + featureName); featureRegion.Check(Aliases.SLDWORKS.dlgFeatureParameters.Window("SysListView32", "", 1)); }
I think you can try
Regions.Items(featureName).Check(Aliases.SLDWORKS.dlgFeatureParameters.Window("SysListView32", "", 1))
instead of eval.