# CMB6 - New Resource operateInternal()

**URL:** https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144
**Category:** Computational Model Builder (CMB)
**Created:** [August 17, 2018, 4:53pm UTC](https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144 "2018-08-17T16:53:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chart3388](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@chart3388](https://discourse.kitware.com/u/chart3388)
#### Post date: [August 17, 2018, 4:53pm UTC](https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144/1 "2018-08-17T16:53:40Z")

</div>

Hi Guys,

I am trying to create resource from File -\> New Resource -\> Malone. I am able to open the dialog box, populate the dialog box but when I click apply I am not able to use the operateInternal() function. IE I am unable to access the operator in the session. I can’t do a simple print and get the value for instance. It works through the operator panel.

Thanks,

Corey

---

<div class="post-metadata">

### Author: ![tj.corona](https://discourse.kitware.com/user_avatar/discourse.kitware.com/tj.corona/32/35_2.png) [@tj.corona](https://discourse.kitware.com/u/tj.corona)
#### Post date: [August 17, 2018, 6:09pm UTC](https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144/2 "2018-08-17T18:09:45Z")

</div>

Hi Corey,

If you are able to select `Malone` from `File->New Resource`, then I am guessing you have written a `Malone` bridge and provided a `create()` operation for this resource type. Awesome!

Without seeing the internals of your `create()` operation, my first guess would be that the operation’s `operateInternal()` method is not returning the right thing. As an example, let’s look at the last few lines of `operateInternal()` in `smtk::bridge::mesh::Read()`:

```auto
  Result result = this->createResult(smtk::operation::Operation::Outcome::SUCCEEDED);

  {
    smtk::attribute::ResourceItem::Ptr created = result->findResource("resource");
    created->setValue(resourceItem->value());
  }

  return result;

```

This code works in tandem with the description code for `smtk::bridge::Read::Result`:

```auto
    <AttDef Type="result(read)" BaseType="result">
      <ItemDefinitions>

        <Resource Name="resource">
          <Accepts>
            <Resource Name="smtk::bridge::mesh::Resource"/>
          </Accepts>
        </Resource>

        <Void Name="allow camera reset" IsEnabledByDefault="true" AdvanceLevel="11"/>
      </ItemDefinitions>
    </AttDef>

```

Registering a `create` operation implies (with no documentation yet, sorry!) that the operation will return a resource in its result.

Hope this helps!

Sincerely,  
T.J.

---

<div class="post-metadata">

### Author: ![tj.corona](https://discourse.kitware.com/user_avatar/discourse.kitware.com/tj.corona/32/35_2.png) [@tj.corona](https://discourse.kitware.com/u/tj.corona)
#### Post date: [August 17, 2018, 6:13pm UTC](https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144/3 "2018-08-17T18:13:42Z")

</div>

Also, to print something in an operation’s `operateInternal` and have it show up in ModelBuilder’s output window you must use the operation’s logger (accessible within `operateInternal()` via `this->log()`).

---

<div class="post-metadata">

### Author: ![chart3388](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@chart3388](https://discourse.kitware.com/u/chart3388)
#### Post date: [August 17, 2018, 6:28pm UTC](https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144/4 "2018-08-17T18:28:58Z")

</div>

Hi TJ,

Thanks for the quick reply.

We do that with the python code below:

```python
rsrc = cheers.malone.Resource.create()
# Assign malone session to malone resource
sess = cheers.malone.Session.create()
rsrc.setSession(sess)
result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED)
created = result.findResource("resource")
created.setValue(rsrc)
 
return result

```

The SBT Code looks like:

```xml
<AttDef Type="result(set working directory)" BaseType="result">
            <ItemDefinitions>
                <Resource Name="resource" Label="malone">
                    <Accepts>
                        <Resource Name="cheers::malone::Resource"/>
                    </Accepts>
                </Resource>
            </ItemDefinitions>
        </AttDef>

```

This is still not working.

Thanks,

---

<div class="post-metadata">

### Author: ![chart3388](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/c/82dd89/32.png) [@chart3388](https://discourse.kitware.com/u/chart3388)
#### Post date: [August 22, 2018, 7:52pm UTC](https://discourse.kitware.com/t/cmb6-new-resource-operateinternal/144/5 "2018-08-22T19:52:06Z")

</div>

All is working now as described above in SMTK as of [this commit](https://gitlab.kitware.com/cmb/smtk/commit/1bb66575011230d68270f838baebb49c64f0a69e).
