Forum Discussion

rushikesh's avatar
rushikesh
Contributor
8 years ago

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); ...
  • tristaanogre's avatar
    8 years ago

    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));
    
    }

     

     

  • Bobik's avatar
    Bobik
    8 years ago

    I think you can try

    Regions.Items(featureName).Check(Aliases.SLDWORKS.dlgFeatureParameters.Window("SysListView32", "", 1))

    instead of  eval.