Usage of existing elements created by someone else

  • Hello!

    Can we use in the state updater element functionality of existing SAMSON elements?

    We want to use in our element functionality of TWISTER element. Is it possible somehow specify in our code control points for Twister and move points to twist molecule?


  • Hello @Andrii

    Brief answers to the two questions: 1) Yes; 2) No, not for now.

    The answer to the 1st question. Yes, you can use the functionality of existing SAMSON Elements in your Element, but only the functionality which is exposed. Please, check SAMSON Introspection mechanism (note, that some parts of the introspection functionality described in the documentation have been updated and not yet modified in the documentation).

    Let's say you want to use the functionality of a class called SEMyClass from the SAMSON Element with UUID 554FEFC0-CF52-A7EC-BEBB-3230C5705738. It can be done like this:

    // Create a class proxy
    SBProxy* classProxy = SAMSON::getProxy("SEMyClass", SBUUID("554FEFC0-CF52-A7EC-BEBB-3230C5705738"));
    // Create an instance of the class
    SBValue objectHolder = classProxy->createInstance();

    Now you can use the exposed functionality of this class. Let's say the exposed class has an exposed function called multiply which multiplies two arguments. This function can be called like this:

    SBValue resultHolder = classProxy->call(objectHolder, "multiply", 10.0, 3.14);
    double result = SB_CAST<double>(resultHolder);

    The answer to the 2nd question. For now, it is not possible to use the Twister functionality in the code, because its functionality is not exposed. It might be updated in the next version.

  • @DMITRIY MARIN, thank you!

    Could you please advise how find exposed functionality of existing SAMSON Elements?

    Thanks again

  • @Andrii It can be done from the code. For now, we do not have docs/help web-pages for each of the SAMSON Elements, but it is in our plans to have them generated automatically for the exposed functionality.

    To get UUID and the class name of an Element from which you want to use functionality, you can open the Log (Edit menu -> Show log), then you can search for the Element and check its UUID and the class name:

    Now, in your code, you can do the following to print the exposed functionality of the Element:

    // Create a class proxy
    SBProxy* classProxy = SAMSON::getProxy("PDBDownload", SBUUID("6F5D45C5-E76E-CDC8-52D5-D2821C128BE8"));
    // Print class constructors
    // Prints the interface

    It will print the exposed functionality (constructor factory, interface functions, attributes) in the terminal (std::cout stream), like this:

    Class proxy:
    	Name	:PDBDownload
    	UUID	:23E5619D-CF88-CD8D-C516-725286102AF8
    	Element	:PDBDownload
    	Type	:10
    		download(std::string, std::string)

    You might need to allow the terminal with "--logconsole" flag when running SAMSON.

    If you have some problems with std::cout not printing to your terminal, you might print it yourself into std::cerr:

    // Print interface
    std::cerr << "Interface:\n";
    auto functionMap = classProxy->getInterface()->getFunctionMap();
    for (auto i = functionMap.begin(); i != functionMap.end(); ++i)
    	std::cerr << i->getKey() << "\n";
    // Print attributes
    std::cerr << "Attributes:\n";
    auto attributeMap = classProxy->getInterface()->getAttributeMap();
    for (auto i = attributeMap.begin(); i != attributeMap.end(); ++i)
    	std::cerr << i->getKey() << "\n";

Log in to reply

Looks like your connection to SAMSON Connect - Forum was lost, please wait while we try to reconnect.