Command Syntax to get a String for CubitInterface::parse_cubit_list()

Hi,

i want to use the CubitInterface::parse_cubit_list in my custom command. But i can`t get the desired syntax working to get 1 string that i can put into the parser.

i want to have an command input like “block all except 1 3 5 element type hex20” but i can only get it work when i use quotes for my string data type. so the input would end up like “block ‘all except 1 3 5’ element type hex20”

i already tried to change the number attribute from my string data but cubit always throws me an invalid command error.

how should the syntax look to get an string or an vector that i can use for the parser?

Hi,

You have to break that out into two commands. The parse_cubit_list method doesn’t know how to parse “element type hex20”

# get the block ids
block_ids = cubit.parse_cubit_list("block", "all except 1 3 5")
# convert the tuple into a space separated list. Note the single quotes inside the double quoted string
cubit.cmd( f" block {' '.join([str(i) for i in block_ids]) } element type hex20")

Does that make sense?

Thanks,
Karl

Hello Karl,

that’s something i have done when i build one of my custom widgets. But i want that functionality when someone uses the console in cubit.

What i meant was, how the syntax for a custom command should look like.

Right now my get_syntax() from the custom command looks something like this

std::vector<'std::string> ccxBlockElementTypeCommand::get_syntax()
{
std::vector<‘std::string> syntax_list;
std::string syntax = "ccx "
"block <string:type=‘unquoted’,number=‘1’,label=‘block id’,help=’<‘block id>’> "
“element_type C3D20”;
syntax_list.push_back(syntax);
return syntax_list;
}

and in the execute i want to get my input string for the label ‘block id’ to use it with the parser.

bool ccxBlockElementTypeCommand::execute(CubitCommandData &data)
{

std::vector block_ids;
std::string block_string;
data.get_string(“block id”, block_string);
block_ids = CubitInterface::parse_cubit_list(“block”, block_string);

}

what changes to the syntax must be made so that the command “ccx block all except 1 3 5 element_type c3d20” will also work and not just the quoted version “ccx block ‘all except 1 3 5’ element_type c3d20” ?

Hi Norbert,

You should get that handling with the default C++ parsing. As an example from our code base,

std::vector<CubitString> ExportForestCommand::get_syntax()
{
  std::vector<CubitString> commands;
  CubitString syntax;
  
  syntax = "export forest <string:label='mFileroot'>"
  "[<entities:type='<block:label='mBlockList'>'>]"
  "[overwrite]";
  
  commands.push_back(syntax);
  return commands;
}

and then in the execute method you do something like

 std::vector<ElementOutputGroup*> block_entities;
  if (data.get_entity_list("mBlockList", block_entities)) {
      mBlockList = block_entities;
 }

Karl

Hi Karl,
i tried it, but i only got it working if the input were numbers.
I already made a little workaround to fix this, with more syntax lines for the command and then checking for keywords in the execude.

Norbert