Convert Cell to Annotation Cell without "Can be Used As Annotation" flag being set.

Hi All,

If at the time of placement a cell is flagged as "can be used as annotation" then that cell is placed as an "Annotation Cell". If subsequently the "can be used as annotation" flag is removed in the cell library, the cell continues to behave as an "Annotation Cell".

Is it possible to convert cells to "Annotation Cells" that exist in a particular dgn but have no corresponding entry in a cell library (and hence can't be flagged as "can be used as annotation")?

The best I can come up with at the moment is writing the cell out to a temporarily cell library, flagging "can be placed as annotation", replacing the original cell with the cell in the temporary library then removing the library. Is there a more elegant solution than this?

BTW, I am using the MDL and MicroStationAPI SDK's (C++).

Thanks

Liam

Parents
  • Hi All,

    I logged this issue with Bentley, and their response is below:

    It’s possible to convert existing ordinary cells in drawing into annotation cells by setting  flags.isAnnotation property to TRUE in cell element.
    Please take a look at sample code below. It uses functions both from MDL and MicroStationAPI, so both includes are needed.

     int cell_Callback (MSElementDescrP pElD, void *callbackArg, ScanCriteriaP scP)

    {
           //Does not work with shared cells
           if (CELL_HEADER_ELM == pElD->el.ehdr.type)
           {
                  double const annotScale = 1.0;
                  Bentley::Ustn::Element::XAttributeHandlerId annotScaleXAttr (XATTRIBUTEID_AnnotationScale, 0);
                  Bentley::Ustn::Element::EditElemHandle  elHnd (pElD, false, false);
                  if (pElD->el.hdr.dhdr.props.b.is3d)
                  {
                         Cell_3d *cell = (Cell_3d *) &(pElD->el);
                         cell->flags.isAnnotation = TRUE;
                         elHnd.ScheduleWriteXAttribute(annotScaleXAttr, 0, sizeof(double), &annotScale);
                  }
                  else
                  {
                         Cell_2d *cell = (Cell_2d *) &(pElD->el);
                         cell->flags.isAnnotation = TRUE;
                         elHnd.ScheduleWriteXAttribute(annotScaleXAttr, 0, sizeof(double), &annotScale);
                  }
                  mdlElmdscr_rewrite(pElD, NULL, mdlElmdscr_getFilePos(pElD));
                  mdlElmdscr_freeAll(&pElD);
           }

            return SUCCESS;
    }

     Private void convertCells2Annotation(char *arg)
    {
           //Select all cells in current model
           ScanCriteriaP  scan = mdlScanCriteria_create();
           mdlScanCriteria_addSingleElementTypeTest (scan, CELL_HEADER_ELM);
           mdlScanCriteria_setModel(scan, ACTIVEMODEL);
           mdlScanCriteria_setElmDscrCallback(scan, cell_Callback, NULL);
           mdlScanCriteria_setReturnType (scan, MSSCANCRIT_ITERATE_ELMDSCR, FALSE,FALSE);
           mdlScanCriteria_scan(scan, NULL, NULL, NULL);
           mdlScanCriteria_free(scan);
    }

     I noticed that converted cells start to react to annotation scale change only after drawing is reopened. Let me know if you have any further questions

     

    Regards,
    Linas Burneika
    Technical Support Group
    Bentley Systems, Incorporated

    I can verify that this approach works well. The only downside is that I have to reload the file at the end, thus loosing the ability to undo.

    Thanks
    Liam

    Answer Verified By: wilks 

Reply
  • Hi All,

    I logged this issue with Bentley, and their response is below:

    It’s possible to convert existing ordinary cells in drawing into annotation cells by setting  flags.isAnnotation property to TRUE in cell element.
    Please take a look at sample code below. It uses functions both from MDL and MicroStationAPI, so both includes are needed.

     int cell_Callback (MSElementDescrP pElD, void *callbackArg, ScanCriteriaP scP)

    {
           //Does not work with shared cells
           if (CELL_HEADER_ELM == pElD->el.ehdr.type)
           {
                  double const annotScale = 1.0;
                  Bentley::Ustn::Element::XAttributeHandlerId annotScaleXAttr (XATTRIBUTEID_AnnotationScale, 0);
                  Bentley::Ustn::Element::EditElemHandle  elHnd (pElD, false, false);
                  if (pElD->el.hdr.dhdr.props.b.is3d)
                  {
                         Cell_3d *cell = (Cell_3d *) &(pElD->el);
                         cell->flags.isAnnotation = TRUE;
                         elHnd.ScheduleWriteXAttribute(annotScaleXAttr, 0, sizeof(double), &annotScale);
                  }
                  else
                  {
                         Cell_2d *cell = (Cell_2d *) &(pElD->el);
                         cell->flags.isAnnotation = TRUE;
                         elHnd.ScheduleWriteXAttribute(annotScaleXAttr, 0, sizeof(double), &annotScale);
                  }
                  mdlElmdscr_rewrite(pElD, NULL, mdlElmdscr_getFilePos(pElD));
                  mdlElmdscr_freeAll(&pElD);
           }

            return SUCCESS;
    }

     Private void convertCells2Annotation(char *arg)
    {
           //Select all cells in current model
           ScanCriteriaP  scan = mdlScanCriteria_create();
           mdlScanCriteria_addSingleElementTypeTest (scan, CELL_HEADER_ELM);
           mdlScanCriteria_setModel(scan, ACTIVEMODEL);
           mdlScanCriteria_setElmDscrCallback(scan, cell_Callback, NULL);
           mdlScanCriteria_setReturnType (scan, MSSCANCRIT_ITERATE_ELMDSCR, FALSE,FALSE);
           mdlScanCriteria_scan(scan, NULL, NULL, NULL);
           mdlScanCriteria_free(scan);
    }

     I noticed that converted cells start to react to annotation scale change only after drawing is reopened. Let me know if you have any further questions

     

    Regards,
    Linas Burneika
    Technical Support Group
    Bentley Systems, Incorporated

    I can verify that this approach works well. The only downside is that I have to reload the file at the end, thus loosing the ability to undo.

    Thanks
    Liam

    Answer Verified By: wilks 

Children
No Data