How to insert a parametric cell with C# in Connect edition?

Hi,

i try to insert a paramtric cell in my model.

I have an attached cell lib nd I can find the cell via the name in the lib and get a ParametricCellDefinitionElement object.

I can iterate over the variables of the parametric cell, and with a IECPropertyValue objct I can the the needed values for the variables.

But I didn't find a way to insert the parametric block into the model.

CreateCellElementXX and CreateSharedCellElementXX only create a normal cells. Any command I missed? Or can I change the cell to a paramtric cell and set the variables?

Or do i have to use something like:

      App.CadInputQueue.SendCommand("PLACE CELL", true);
      App.CadInputQueue.SendKeyin(parametricCellData.ParametricCellName);

      Point3d dataPoint;
      dataPoint.X = parametricCellData.PtInsert.X;
      dataPoint.Y = parametricCellData.PtInsert.Y;
      dataPoint.Z = parametricCellData.PtInsert.Z;
      App.CadInputQueue.SendDataPoint(ref dataPoint, 1, 0);

Thanks for help

Markus

  • // create new element
    var cellElem = ParametricCellElement.Create(cellDefElem, parameterSetName, placementModel);
    // ...modify placement if desired...
    cellElem.Rotation = someDMatrix3d;
    cellElem.Origin = someDPoint3d;
    // insert the element
    cellElem.AddToModel();

    Native C++ API is more fleshed-out; e.g., C# only gives you the cell's parameter values as an IECInstance whereas native API gives you more convenient means to query/edit them.

  • Hi, many thanks for the hint.

    Now I can create the parameteric cells, butstill some questons:

    - What is the "parameterSetName"? any value different from null or "" seems to crash mirostation

    - I can't change the variables of the cells. I tried: (without checking the returnvalues here)

          var dgnFile = Session.Instance.GetActiveDgnFile();
          var parametricCell = ParametricCellDefinitionElement.FindByName(cellName, dgnFile);
          var parametricCellElement = ParametricCellElement.Create(parametricCell, null, dgnModel);
          parametricCellElement.Origin = new DPoint3d(ptInsert.X, ptInsert.Y, ptInsert.Z);
          parametricCellElement.Rotation = DMatrix3d.Scale(scaleFactor);
          var parameters = parametricCellElement.Parameters;
          var parameterDefinition = parametricCell.ParameterDefinitions.FirstOrDefault(item => item.DisplayLabel == variableName);
          var propertyValue = parameters.FindPropertyValue(parameterDefinition.AccessString, false, false, false, true);
          propertyValue.DoubleValue = doubleParam.Value;
          (parameters as IDgnECInstance)?.WriteChanges();
          var statusInt = parametricCellElement.AddToModel();

          But the variables for the cell stay unchanged :-(

    - and similar to another of my questions here, how can I add xdata the the newly created parametric cell

    Any ideas or hints?

    Greetings

    Markus

  • Hi Markus, did you ever get this to work? I am having the same problem.

    Cheers

    Matt