Question about some possibilities of AnyScript

Hi,

These days I’m trying to study AnyScript++ and ClassExamples in the Documentation/AnyScriptReference/demo folder.

I have two questions.

  1. Is there a kind of ‘for-loop’ statement in AnyScript like C++ language?

  2. In C++ STL(Standard Template Library), there are some containers like Vector, List, Map and so on.
    For instance, it would be very useful if there can be a container like std:vector<AnyVec3>.
    Then AnyScript user can access to the individual element of the container by index.
    So I’d like to know whether there are some containers in AnyScript like C++ STL.
    And, if not, would you have some plans to implement those things in AnyScript?

Best regards and thanks in advance,
Moonki

Dear Moonki,

Here are some answers:

There is no for loop available in AnyBody, the thing which comes closest is a parameter study, this will allow you to run a sequence of analysis, but it will not allow you to construct multiple items in the script using a loop. This would be a nice feature to have.

It should be possible to construct a parameter study and then use the step index to access a certain quantity in a matrix or vector would this type of solution solve your problem?

In general the matrices and vectors can be accessed with an index, this is for example used in the definition of the forceplate classes available in the toolbox/mocap folder.

Best regards
Søren

Dear Søren,

Yes, what I want is to construct multiple items in the AnyScript using the for-loop statement. I hope that this feature would be realized in the future.

And, let's assume that the following code:

std:Vector<AnyVec3> AnyVec3Container;
AnyVec3 vec0 = {0,0,0};
AnyVec3 vec1 = {1,1,1};
AnyVec3 vec2 = {2,2,2};
AnyVec3Container.push_back(vec0);
AnyVec3Container.push_back(vec1);
AnyVec3Container.push_back(vec2);
AnyVec3 vec0_copy = AnyVec3Container[0];
AnyVec3 vec1_copy = AnyVec3Container[1];
AnyVec3 vec2_copy = AnyVec3Container[2];

If there is a container like std::vector<AnyVec3>, then we can put the unlimited numbers of AnyVec3 instances into the std::vector<AnyVec3> instance.

I couldn't find this kind of feature in the toolbox/mocap folder.

Best regards,
Moonki

Hi Moonki,

What come closest to this today is something like this:


AnyMatrix Matrix={
  {1.1,1.2,1.3},
  {2.1,2.2,2.3},
  {3.1,3.2,3.3}
};
AnyVec3 vec1 =Matrix[0];   
AnyVec3 vec1 =Matrix[1];
AnyVec3 vec1 =Matrix[2];

Will the vectors have different length?

Best regards
Søren

Hi Søren,

Let me compare my code and your code.

My code:

std:Vector<AnyVec3> AnyVec3Container;
AnyVec3 vec0 = {0,0,0};
AnyVec3 vec1 = {1,1,1};
AnyVec3 vec2 = {2,2,2};
AnyVec3Container.push_back(vec0);
AnyVec3Container.push_back(vec1);
AnyVec3Container.push_back(vec2);
AnyVec3 vec0_copy = AnyVec3Container[0];
AnyVec3 vec1_copy = AnyVec3Container[1];
AnyVec3 vec2_copy = AnyVec3Container[2];

Your code:

AnyMatrix Matrix={
  {1.1,1.2,1.3},
  {2.1,2.2,2.3},
  {3.1,3.2,3.3}
};
AnyVec3 vec1 =Matrix[0];   
AnyVec3 vec1 =Matrix[1];
AnyVec3 vec1 =Matrix[2];

In my code, ‘AnyVec3Container’ can contain the unlimited number of AnyVec3 instances. When this instance of container is created, the capacity of this container is unlimited because this container has the operator ‘push_back()’.

But in your code, when the instance of AnyMatrix was created, the dimension of the instance is determined when it is created. After that, user can’t change it. It means that we can’t change the size of ‘Matrix’.

I think that this kind of feature may be very useful if it can be used with the for-loop statement. In a for-loop, a lot of processes for creating instances repeatedly can be automated.

I hope that my reply may explain my original intention well.

Best regards,
Moonki

Hi Moonki,

I see the difference…

we have discussed a new feature which would essential be a function that would let you pick a certain element in a folder.

So it would look more or less like this

AnyVec3 test =XXfunctionXX(myfolder,2);

AnyFolder myfolder={
AnyVec3 t1={1,2,3};
AnyVec3 t2={2,2,3};
AnyVec3 t3={3,2,3};
};

and

test={3,2,3}

would this be a solution?

Creating for loops in the script for creating the multiple objects may turn out to be very difficult, because it makes the parsing much more complicated, so at this moment i am unsure if we will attempt to do this.

Best regards
Søren

Hi Søren,

Thanks for your consideration.

If the implementation of the for-loop statement in the AnyScript may not be easy in near future, I think that your suggestion like ‘XXfunctionXX’ would be the best currently.

Additionally, I’d like to suggest that the function ‘XXfunctionXX’ would be better to extract any kind of object. For instance, not only to AnyVec3, but also AnyMat33 and so on.

If to do that, the function ‘XXfunctionXX’ should have more arguments like this.

XXfunctionXX(AnyFolder& targetFolder, AnyString targetObjectType, AnyInt index)

Best regards,
Moonki

Hi Moonki,

Yes the folder should take all sorts of items not just vec3.

Thanks for the suggestion to the function call it makes much sense to me.

Best regards
Søren