[OPM CE Update 9 C#] : Read and Append Linkage

I have to read and update the attributes to the element, on OPM CE Update 9. However, to find the way to do it, I am looking the potential in the below code, but during read, OPM crashes at the line provided in the code below.

            
                ReadDataBlock dataBlock = element.GetLinkage(linkageId);
                
                //OPM crashes here
                short[] dataArray = dataBlock.ReadInt16Array((int)dataBlock.Size);

                List<short> dataList = dataArray.ToList();

                dataList.Add(4204);
                dataList.Add(27070);

                short[] newdataArray = dataList.ToArray();

                WriteDataBlock newdataBlock = new WriteDataBlock();
                newdataBlock.WriteInt16Array(newdataArray);

                element.AppendLinkage(linkageId, newdataBlock);
      

As I was not able to find the way to see the content of linkages of the element in OPM CE Update 9. This is how I discovered the linkages of the element, in Microstation SS3.

Thanks in advance.

Parents
  • I believe the Size property of the datablock is returning the total number of bytes.   In your code, you are telling it to read that many shorts, most likely causing an index out of bounds error...

    I do similar code my self.

                // Check if the element has any linkage..
                if (_element == null || _element.GetLinkageCount(AppId) == 0)
                    return false;
    
                using (ReadDataBlock data = _element.GetLinkage(AppId))
                {
                    if (data.ReadByte() != LinkageId)
                        return false;
    
                
                    AttributeType type = (AttributeType) data.ReadInt16();
                    
                    // Check if the linkage is what we are looking for.
                    if (type != _attributeType)
                        return false;
    
                    _attributes = ProcessBytes(data.ReadByteArray((int) data.Size));
                }
                return true;



Reply
  • I believe the Size property of the datablock is returning the total number of bytes.   In your code, you are telling it to read that many shorts, most likely causing an index out of bounds error...

    I do similar code my self.

                // Check if the element has any linkage..
                if (_element == null || _element.GetLinkageCount(AppId) == 0)
                    return false;
    
                using (ReadDataBlock data = _element.GetLinkage(AppId))
                {
                    if (data.ReadByte() != LinkageId)
                        return false;
    
                
                    AttributeType type = (AttributeType) data.ReadInt16();
                    
                    // Check if the linkage is what we are looking for.
                    if (type != _attributeType)
                        return false;
    
                    _attributes = ProcessBytes(data.ReadByteArray((int) data.Size));
                }
                return true;



Children
No Data