Split PolygonObject from multiple Selections

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/05/2011 at 15:48, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R12 
Platform:      
Language(s) :     C++  ;

---------
Hi All,

here my first question:
How to split a PolgonObject with multiple PolygonSelection-Tags (for Materials) into multiple PolygonObjects?

Here my start.

void Walk(BaseObject *object)
{
	while (object)
	{
		if(object->GetType() == Tpolygon)
		{
			BaseTag *tag = object->GetFirstTag();
			
			while (tag)
			{
				if (tag->GetType() == Tpolygonselection)
				{
					SelectionTag *selectionTag = (SelectionTag * )tag;
					BaseSelect *select = selectionTag->GetBaseSelect();
					/*...
						alloc new PolygonObjects, fill given data 
					*/
				}
				tag = tag->GetNext();
			}
  
			if (object->GetDown()) 
			{
				//recursive walk
				Walk(op->GetDown());
			}
			
			object = object->GetNext();
		}
	}
}

Thanks,
ToBSn

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 17/05/2011 at 17:00, xxxxxxxx wrote:

Select the polygons of the PolygonSelection and then use SendModelingCommand() to do a split.  Here is a convenience method which does it for you:

PolygonObject* SplitObject(PolygonObject* op, SelectionTag* pstag)  
{  
  // BaseSelect of Polygon Selection Tag  
  BaseSelect*        pbs =        pstag->GetBaseSelect();  
  if (!pbs)                            return NULL;  
  // BaseSelect of Polygon Object  
  BaseSelect*        bs =        op->GetPolygonS();  
  if (!bs)                            return NULL;  
  // Select Polygons on Polygon Object belonging to Polygon Selection Tag  
  if (!pbs->CopyTo(bs))    return NULL;  
  
  // Split selected polygons (tops) into new object  
  ModelingCommandData    mcd;  
  mcd.doc =                    NULL;  
  mcd.bc =                    NULL;  
  mcd.mode =                MODELINGCOMMANDMODE_POLYGONSELECTION;  
  mcd.flags =                MODELINGCOMMANDFLAGS_0;  
  mcd.op =                    op;  
  if (!(SendModelingCommand(MCOMMAND_SPLIT, mcd) && mcd.result))    return NULL;  
  PolygonObject*    top =    ToPoly(mcd.result->GetIndex(0L));  
  // - it is your responsibility to free the 'result' AtomArray returned in 'mcd'!  
  AtomArray::Free(mcd.result);  
  return top;  
}

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 01:14, xxxxxxxx wrote:

Just btw: If a non-polygonobject is parsed, you will never ever leave the while-loop.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 01:34, xxxxxxxx wrote:

@kuroyume0161
Very cool, thank you. Clever idea to use the modeling command. 🙂

@nux95
a yeah, thats right. thanks.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 18/05/2011 at 08:21, xxxxxxxx wrote:

To avoid the infinite while-loop just move the line "object = object->GetNext();" outside of the if() block.

SendModelingCommand() is your friend ... most of the time but depending upon its mood. 🙂