Jump to content

Get custom prim Attribute value?


Recommended Posts

How can I get a custom prim attribute value? like this fragment of code

 

GA_RWAttributeRef prNum = gdp->findFloatTuple(GA_ATTRIB_PRIMITIVE, "prNum");

GA_RWHandleF prNumHandle(prNum.getAttribute());

 

GA_FOR_ALL_PRIMITIVES(gdp, prim)

{

    if (prNumHandle.isValid())

    {

         //here how can I get the prNum value like prNum == 12 for example?


         {

             gdp->deletePrimitive(*prim, 0);

         }

    }

}

 

Edited by Wanderson Pereira
Link to comment
Share on other sites

Thanks a lot edward, works perfectly

 

here is the complete cook function with corrections.

OP_ERROR MyClass::cookMySop(OP_Context &context)
{
	if (lockInputs(context) >= UT_ERROR_ABORT)
		return error();

	duplicateSource(0, context);
	GEO_Primitive	 *prim;
	const GA_RWAttributeRef	prNum = gdp->findFloatTuple(GA_ATTRIB_PRIMITIVE, "prNum");
	GA_RWHandleF prNumHandle(prNum);
	if (prNumHandle.isValid())
	{
		GA_FOR_ALL_PRIMITIVES(gdp, prim)
		{
			if (prNumHandle.get(prim->getMapOffset()) == 12.0)
			{
				gdp->deletePrimitive(*prim, 0);
			}
		}
	}
	unlockInputs();
	return error();
}

Link to comment
Share on other sites

Guest mantragora

It's more straightforward if you use GA_Iterator. GA_FOR_ALL_PRIMITIVES is still using some GB compatibility and on top of it GEO, so you are losing everything that the new GA library brings to the table.

 

Also, we got OP_AutoLockInputs in H13 and H14, so instead of locking and unlocking manually, use it.

auto
Foo::cookMySop(Context& context)
-> OP_ERROR
{
    OP_AutoLockInputs autolock;   
    auto wasSuccess = autolock.lock(*this, context);
 
    if (wasSuccess < UT_ERROR_WARNING && error() < UT_ERROR_WARNING or whatever you want to test along the way )
    {
        // your code
    }
 
    return error();
}

I got one in my base class, so it's available in every method that may need it. 

Edited by mantragora
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...