What is the best way to modify a dimension that is being put in by a VBA?

I need to modify the placement of a dimension based on certain criteria. This would be just moving the text part of the dimension.

Parents
  • Modify, Element (7,1) will allow you to grab just the text from the dimension and move it. It also allows you to move the dimension line if you click on it rather than the text.

    I'm not clear if you are trying to move the text after it was put in by VBA or trying to use VBA to move it. I've not tried moving the text of a dimension via VBA but I believe it would be straightforward. The difficult part would be the "based on certain criteria". I'm guessing that means something like not overlapping other elements which is possible but would take a lot more code and thought to get working.

    If you clarify what you are trying to accomplish we might have more suggestions.

  • Yes, I'm doing it by means of VBA. The criteria is coming from the database, so that not a problem. If the dimension is smaller then 2', then is would be leader out .

    Larry Wilson
    LWilson@LJBinc.com
     

  • Hi Larry,

    Would you mind reviewing the code in this first topic "VBA - V8i) Set Dimension Offset" from the search I performed: vba AND dimension AND text AND (move OR offset); and see if it helps?  If not, would you mind attaching a simplified standalone version of a .mvba project for others to possibly help contribute to directly?

    Thank you and HTH,
    Bob



  • I did do a search and did find that page. The problem I ran into was that all the links on that page produces a oops page, page had been moved or is no longer available. The mvba reads an excel file, so I would be had for someone to run. Here is the code in use, the modify works sometimes


    CadInputQueue.SendKeyin "DIMCREATE LINEAR MODE SIZE"
    CadInputQueue.SendCommand "DIMCREATE LINEAR " 'dim vertical X

    If fLJB_InsertLocations.TBV.Value < 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION OUTSIDE " 'outside dimensions
    CadInputQueue.SendCommand "DIMCREATE LINEAR "


    ElseIf fLJB_InsertLocations.TBV.Value >= 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION INSIDE " 'inside dimensions

    End If
    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION RIGHTEXTENSION ON " 'right extension off
    CadInputQueue.SendCommand "DIMSTYLESET SIZEARROW RIGHTEXTENSION ON "
    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION LEFTEXTENSION ON " 'left extension off
    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION LEFTEXTENSION ON "
    CadInputQueue.SendCommand "DIMSTYLESET EXTENSIONLINES OFFSET .5"

    CadInputQueue.SendDataPoint RB
    CadInputQueue.SendDataPoint R1
    CadInputQueue.SendDataPoint VD
    CadInputQueue.SendReset




    CadInputQueue.SendKeyin "ac=440" 'Place Cell
    CadInputQueue.SendDataPoint L2, 1
    CadInputQueue.SendDataPoint R2, 1
    CadInputQueue.SendReset

    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION RIGHTEXTENSION ON " 'right extension off
    CadInputQueue.SendCommand "DIMSTYLESET SIZEARROW RIGHTEXTENSION ON "
    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION LEFTEXTENSION ON " 'left extension on
    CadInputQueue.SendCommand "DIMSTYLESET SIZEARROW LEFTEXTENSION ON "
    CadInputQueue.SendCommand "DIMSTYLESET EXTENSIONLINES OFFSET 0"

    EL.x = L2.x 'math for EL @ L2
    EL.Y = L2.Y + 1
    EL.Z = L2.Z

    If fLJB_InsertLocations.TBW.Value < 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION OUTSIDE " 'outside dimensions
    CadInputQueue.SendCommand "DIMCREATE LINEAR "


    ElseIf fLJB_InsertLocations.TBW.Value >= 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION INSIDE " 'inside dimensions

    End If
    CadInputQueue.SendKeyin "DIMCREATE LINEAR MODE SIZE"
    CadInputQueue.SendCommand "DIMCREATE LINEAR "
    CadInputQueue.SendDataPoint L2
    CadInputQueue.SendDataPoint L1
    CadInputQueue.SendDataPoint EL
    CadInputQueue.SendReset




    EL.x = R2.x 'math for EL @ R2
    EL.Y = R2.Y + 1
    EL.Z = R2.Z

    If fLJB_InsertLocations.TBW.Value < 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION OUTSIDE " 'outside dimensions
    CadInputQueue.SendCommand "DIMCREATE LINEAR "


    ElseIf fLJB_InsertLocations.TBW.Value >= 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION INSIDE " 'inside dimensions


    End If

    CadInputQueue.SendKeyin "DIMCREATE LINEAR MODE SIZE"
    CadInputQueue.SendCommand "DIMCREATE LINEAR "
    CadInputQueue.SendDataPoint R2
    CadInputQueue.SendDataPoint R1
    CadInputQueue.SendDataPoint EL
    CadInputQueue.SendReset



    R4.x = R2.x
    R4.Y = R2.Y
    R4.Z = R2.Z



    R4 = R1

    Dim vd1 As Point3d

    CadInputQueue.SendKeyin "DIMCREATE LINEAR MODE SIZE"
    CadInputQueue.SendCommand "DIMCREATE LINEAR " 'dim vertical Z

    If fLJB_InsertLocations.TBW.Value < 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION OUTSIDE " 'outside dimensions
    CadInputQueue.SendCommand "DIMCREATE LINEAR "


    ElseIf fLJB_InsertLocations.TBW.Value >= 3 Then
    CadInputQueue.SendCommand "DIMSTYLESET FITOPTIONS FITOPTION INSIDE " 'inside dimensions

    End If

    ActiveSettings.DimensionStyle.PrimaryAccuracy = msdDimAccuracy16th
    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION RIGHTEXTENSION ON " 'right extension off
    CadInputQueue.SendCommand "DIMSTYLESET SINGLELOCATION LEFTEXTENSION ON " 'left extension off
    CadInputQueue.SendCommand "DIMSTYLESET EXTENSIONLINES OFFSET .5" 'set off set to .5


    Dim TempPt As Point3d

    TempPt.x = VD.x
    TempPt.Y = RT.Y
    TempPt.Z = RT.Z



    CadInputQueue.SendDataPoint R1
    CadInputQueue.SendDataPoint RT
    CadInputQueue.SendDataPoint TempPt
    CadInputQueue.SendReset

    If fLJB_InsertLocations.TBW.Value < 3 Then
    point1.x = VD.x - RT.x - 1
    point1.Y = VD.Y - RT.Y + 1
    point2.x = RT.x + 0.5
    point2.Y = RT.Y
    CadInputQueue.SendCommand "MODIFY ELEMENT"
    CadInputQueue.SendDataPoint point1, 1
    CadInputQueue.SendDataPoint point2, 1
    CommandState.StartDefaultCommand
    CadInputQueue.SendReset
    CadInputQueue.SendReset

    End If

    Larry Wilson
    LWilson@LJBinc.com
     

  • Unknown said:

    I did do a search and did find that page. The problem I ran into was that all the links on that page produces a oops page, page had been moved or is no longer available.

    Those have been fixed... apologies for the inconvenience (and thanks for pointing that out).

      

  • Thanks Phil, the examples are not really what I'm looking for. I need some code that will take the last dimension placed and modify the text placement.

    Larry Wilson
    LWilson@LJBinc.com
     

  • Below is some sample code showing how to offset dimension text. Select one or more dimension elements and run TEST_DimTextOffset.  Note: you may need to apply additional rotations if needed.

    Sub TEST_DimTextOffset()
        
        DimTextOffset 0.5, True
    
    End Sub
    
    Sub DimTextOffset(dOffsetX As Double, bInside As Boolean)
        
        Dim eE As ElementEnumerator
        Dim eE2 As ElementEnumerator
        Dim p1 As Point3d
        Dim p2 As Point3d
        Dim dimEle As DimensionElement
        Dim dimStyle As DimensionStyle
        
        ' Exit if no elements selected:
        Set eE = ActiveModelReference.GetSelectedElements
        If Not eE.MoveNext Then
            MsgBox "No elements selected"
            Exit Sub
        End If
        eE.Reset
        
        'process all dimension elements:
        'Dim sC As New ElementScanCriteria
        'sC.ExcludeAllTypes
        'sC.IncludeType msdElementTypeDimension
        'Set eE = ActiveModelReference.GraphicalElementCache.Scan(sc)
        
        'process selected elements:
        Do While eE.MoveNext
            Set dimEle = eE.Current
            Set dimStyle = dimEle.DimensionStyle
                    
            'terminator is in or out:
            If bInside Then
                dimStyle.TerminatorMode = msdDimTerminatorModeInside
            Else
                dimStyle.TerminatorMode = msdDimTerminatorModeOutside
            End If
            dimEle.DimensionStyle = dimStyle
            dimEle.Rewrite
                
            'search text in dimension:
            Set eE2 = dimEle.Drop
            Do While eE2.MoveNext
               If eE2.Current.Type = msdElementTypeText Then
                 p1 = eE2.Current.AsTextElement.Origin
                 p2 = p1
                 p2.X = p2.X + dOffsetX
               End If
            Loop
            
            'offset dimension text:
            CadInputQueue.SendKeyin "modify dimension loc"
            CadInputQueue.SendDragPoints p1, p2
            CommandState.StartDefaultCommand
        Loop
    End Sub
    
    

    Best regards,
    Artur

  • Is there a way to get the last dimension placed?

    Larry Wilson
    LWilson@LJBinc.com
     

  • Could you provide some criteria to define to us your definition of what the last dimension placed entails? Is your code placing the dimension, a user operation in MicroStation using MicroStation tools, last dimension updated as an auto dimension update? What information do you need about the last dimension, and what will happen next to that last dimension? Is there only one that will be affected?

    Also, please consider marking a prior response with "Verify Answer" if the primary issue was resolved by one or more responses. Second, especially if the primary issue has been resolved consider creating a new post/thread for quicker responses.  This way others will clearly see when new question(s) are being asked and not have search/read through a potentially lengthy thread to find an unanswered question remains.

    HTH,
    Bob



  • If you have placed the dimension element as last element, you may then want to use the method .GetLastValidGraphicalElement to obtain the previous placed dimension element:

    Dim Ele As element
    Set Ele = ActiveModelReference.GetLastValidGraphicalElement


    Best regards,
    Artur

Reply Children
No Data