[Connect CPP] Place parametric cells programmaticaly

Hi

I've created some parametric cells in a celllibrary and I want to place them programmatically. I've looked into the constraint2ddemo example and I've made it work but this example 'just' places a parametric cell with predefined values from a parameterset. i would like to specify the values individually using input from the user. As a test I've made some small modifications to the exampleFunctionalCellFromDgn function:

After this line

auto defaultInfo = ParametricCellInfo::Create(status, *def, L"set1", plcModel/**pModel*/);

I've added these lines of code:

IParameterDefinitionsPtr paramDefs = def->GetParameterDefinitions();
		VirtualCollectionIterator<IParameterDefinitionsIterator> iterEnd = paramDefs->end();
		for (VirtualCollectionIterator<IParameterDefinitionsIterator> iter = paramDefs->begin(); iter != iterEnd; ++iter)
		{
			ECValue val1;
			mdlDialog_dmsgsPrint((*iter).GetDisplayLabel());
			if (wcsicmp((*iter).GetDisplayLabel(), L"Radius1") == 0)
			{
				ECObjectsStatus rc = def->SetValue((*iter).GetAccessString(), ECValue(43.0));
				char msg[80];
				sprintf(msg, "rc = %d", rc);
				mdlDialog_dmsgsPrintA(msg);
			}
		}
		def->WriteValues();

The value returned is 200730 meaning Bentley::ECN::ECOBJECTS_STATUS_UnableToSetReadOnlyProperty

Is it somehow possible to place a parametric cell and specify specify the values individually ?

TIA

Regards, Evan

Parents Reply Children
  • Hi Robert,

    As I see, this example just starts the keyIn for placing a parametric cell. But I can't find any Code to manipulate the parameter values of the cell like in Evans Example above. 

    I need to change the parameters of a placed parametric cell problematically but all tries failed until now. 

    This is the code I tried:

    	EditElementHandle eeh;
    	ParameterStatus status = ParameterStatus::Success;
    
    	DgnFileP designFileP = ACTIVEMODEL->GetDgnFileP();;
    	ElementRefP eleRef = ParametricCellDefHandler::GetInstance().FindByName(m_cellName.c_str(), *designFileP);
    	if (!eleRef)
    		return;
    	ParametricCellDefinitionPtr def = ParametricCellDefHandler::GetInstance().GetCellDefinition(EditElementHandle(eleRef));
    	
    	ParametricCellInfoPtr defaultInfo = ParametricCellInfo::Create(status, *def, NULL, *ACTIVEMODEL->AsDgnModelP());
    
    	//IEditParameterDefinitionsPtr editParamDefs = def->GetParameterDefinitions()->GetForEdit(); //looked like the solution but returns a nullptr
    
    	IParameterDefinitionsPtr paramDefs = def->GetParameterDefinitions();
    	VirtualCollectionIterator<IParameterDefinitionsIterator> iterEnd = paramDefs->end();
    	for (VirtualCollectionIterator<IParameterDefinitionsIterator> iter = paramDefs->begin(); iter != iterEnd; ++iter)
    	{
    		mdlDialog_dmsgsPrint((*iter).GetDisplayLabel());
    		if (wcsicmp((*iter).GetDisplayLabel(), L"Length") == 0)
    		{
    			ECN::ECObjectsStatus rc = def->SetValue((*iter).GetAccessString(), ECN::ECValue(43.0));		//ECOBJECTS_STATUS_UnableToSetReadOnlyProperty
    		}
    	}
    	status=def->WriteValues();  //ERROR
    
    	status = ParametricCellHandler::GetInstance().CreateCellElement(eeh, *defaultInfo.GetCR());	//SUCCESS
    	wprintf(L"%s\n", status == ParameterStatus::Success ? L"SUCCESS" : L"ERROR");
    	eeh.AddToModel();	//SUCCESS
    
    	return;