[Connect C#] Dimension Value Parameters

I have successfully followed Yongan.Fu's example on creating dimension elements.  My question is; how do you modify the dimension value similar to the way MicroStation Connect does with the following command:

Linear Dimension -> Location -> Manual

For reference, the example I am following is below:

using System.Resources;
using BG = Bentley.GeometryNET;
using BD = Bentley.DgnPlatformNET;
using BDE = Bentley.DgnPlatformNET.Elements;
using BM = Bentley.MstnPlatformNET;

…...

class CreateDimCallback : BDE.DimensionCreateData
        {
        private BD.DimensionStyle      m_dimStyle;
        private BD.DgnTextStyle        m_textStyle;
        private BD.Symbology           m_symbology;
        private BD.LevelId             m_levelId;
        private BD.DirectionFormatter  m_directionFormatter;

        public CreateDimCallback(BD.DimensionStyle dimStyle, BD.DgnTextStyle textStyle, BD.Symbology symb, BD.LevelId levelId, BD.DirectionFormatter formatter)
            {
            m_dimStyle = dimStyle;
            m_textStyle = textStyle;
            m_symbology = symb;
            m_levelId = levelId;
            m_directionFormatter = formatter;
            }
        public override BD.DimensionStyle GetDimensionStyle()
            {
            return m_dimStyle;
            }
        public override BD.DgnTextStyle GetTextStyle()
            {
            return m_textStyle;
            }
        public override BD.Symbology GetSymbology()
            {
            return m_symbology;
            }
        public override BD.LevelId GetLevelId()
            {
            return m_levelId;
            }
        public override BD.DirectionFormatter GetDirectionFormatter()
        {
            return m_directionFormatter;
        }
        public override int GetViewNumber ()
            {
            return 0;
            }
        public override BG.DMatrix3d GetDimensionRotation()
            {
            return BG.DMatrix3d.Identity;
            }
        public override BG.DMatrix3d GetViewRotation()
            {
                return BG.DMatrix3d.Identity;
            }
        }
private void CreateDimElem()
        {
            BD.DgnFile dgnFile = BM.Session.Instance.GetActiveDgnFile();
            BD.DgnModel dgnModel = BM.Session.Instance.GetActiveDgnModel();

            BD.DimensionStyle dimStyle = BD.DimensionStyle.GetSettings(dgnFile); //Get Active Dimension Style
            BD.DgnTextStyle txtStyle = BD.DgnTextStyle.GetSettings(dgnFile);   //Get Active Text Style

            BD.Symbology symb = new BD.Symbology();
            symb.Color = symb.Weight = 0;
            symb.Style = 0;

            BD.FileLevelCache fileLvlCache = dgnFile.GetLevelCache();
            BD.LevelHandle lvlHandle = fileLvlCache.GetLevelByName("Default");
            BD.DirectionFormatter dirFormatter = new BD.DirectionFormatter(dgnModel);

            CreateDimCallback callback = new CreateDimCallback(dimStyle, txtStyle, symb, lvlHandle.LevelId, dirFormatter);

            BDE.DimensionElement dimElem = new BDE.DimensionElement(dgnModel, callback, BD.DimensionType.SizeArrow);
            dimElem.InsertPoint(new BG.DPoint3d(0, 0, 0), null, dimStyle, 0);
            dimElem.InsertPoint(new BG.DPoint3d(5000000, 0, 0), null, dimStyle, 1);
            dimElem.InsertPoint(new BG.DPoint3d(15000000, 0, 0), null, dimStyle, 2);
            dimElem.SetHeight(5000000);
            dimElem.ApplyDimensionStyle(dimStyle, true);

            dimElem.AddToModel();
        }

I have tried inserting the following code but cannot get it to work:

            int segmentNumber = new int();
            segmentNumber = 0;           

            DPoint2d p2 = new DPoint2d();

           …………..

            p2.Y = p2.Y + 10000;
            dimElem.SetTextOffset(segmentNumber, p2);

Thanks in advance,

Larry

  • Hi Larry,

    I have successfully followed Yongan.Fu's example on creating dimension elements.

    It would be nice to provide a link to example you used, so it will be clear what code you used as a basis.

    My question is; how do you modify the dimension value similar to the way MicroStation Connect does with the following command:

    What do you mean by "dimension value". Unfortunately I have to say I do not understand what you are asking about, because you mentioned "dimension value" (what is it?) but in your code you try to use SetTextOffset.

    Maybe dgn file or screen capture how you want to modify a dimension would help.

    With regards,

      Jan

  • Jan,

    The example program above outputs the following:

    My question is, how do I move the dimension value of 10 (dimension text?) as shown below:

    Thanks,

    Larry

  • I have also found a VBA example that modifies the dimension in the manner shown above.  But the problem I have with this example is that it uses a keyin command and I was taught not to use these if at all possible.  Does anyone know of a C# method that can accomplish the same thing?

    Sub OffsetDimensionInfo()
        Dim oDim As DimensionElement
        Dim p1 As Point3d
        Dim p2 As Point3d
    
    
        Set ee = ActiveModelReference.GraphicalElementCache.Scan
        Do While ee.MoveNext
            If ee.Current.IsDimensionElement Then
                Set oDim = ee.Current
                Set ee = oDim.Drop
                
                Do While ee.MoveNext
                  If ee.Current.Type = msdElementTypeText Then
                     p1 = ee.Current.AsTextElement.Origin
                     p2 = p1
                     p2.Y = p2.Y - 10
                  End If
                Loop
                CadInputQueue.SendKeyin "modify dimension loc"
                CadInputQueue.SendDragPoints p1, p2
                CommandState.StartDefaultCommand
    
            End If
        Loop

  • it uses a keyin command and I was taught not to use these if at all possible

    To be more precise: Don't queue a key-in in your procedural code.  The key-in is placed in MicroStation's input queue.  That won't be executed until MicroStation reaches an idle state.  That won't occur until your current procedural code has terminated and all other queued commands have finished.  In other words, you can't  tell when that key-in will execute.  What you can predict is that it won't happen when you think it ought to happen.

    There are 'synchronized' versions of the key-in commands which may avoid that problem.

     
    Regards, Jon Summers
    LA Solutions

  • Thank you Jon for your response.  Below is an update on the progress I've made on this so far.  The code below was added to the example above.  It does move the textblock as needed but I still need to figure out how to modify the dimension extension line.  Any suggestions on how to simplify this code?  

                ModelElementsCollection elementsCollection = dgnModel.GetGraphicElements();
                ModelElementsEnumerator elementEnumerator = (ModelElementsEnumerator)(elementsCollection.GetEnumerator());
                ElementId eleId = dimEle.ElementId;
                TextEdit textEdit = dimEle.AsTextEdit();
                TextPartIdCollection textParts = textEdit.GetTextPartIds(new TextQueryOptions());
                int textCount = textParts.Count;
                Bentley.DgnPlatformNET.TextBlock textBlock = textEdit.GetTextPart(textParts[0]);
    
    
                //Use the COM element to get ActualValue from dimension element
                BIM.DimensionElement comDimElement = comModel.GetElementByID64(eleId).AsDimensionElement();  
                double dSegmentLength = comDimElement.ActualValue[1];
                Caret startCaret = textBlock.CreateStartCaret();
                Caret endCaret = textBlock.CreateEndCaret();
                textBlock.ReplaceText(dSegmentLength.ToString(), startCaret, endCaret);
    
                // Transform the textblock to desired location
                TextHandlerBase txtHandlerBase = TextHandlerBase.CreateElement(null, textBlock);
                DTransform3d trans = DTransform3d.Identity;
                trans.Translation = new DVector3d(12 * UorPerMas, 0 * UorPerMas, 0 * UorPerMas);
                TransformInfo transInfo = new TransformInfo(trans);
                txtHandlerBase.ApplyTransform(transInfo);
                txtHandlerBase.AddToModel();

    Thanks for everyone's help,

    Larry