Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
RoyWickrama_RWEI
901 Views, 3 Replies

To copy dimension value (from drawing) to clipboard

I often need to copy the dimension (of maximum precision) to the clipboard. As this is not possible with the dimension text in the drawing document, once I posted this  as an idea.

I recently thought doing this with the help of a iLogic rule. I came up with a code as shown below (it works):

Sub Main()

oRule_Index = "iL0015"
oRule_Name = "COPY DIMENSION VALUE"
oRule_Description = oRule_Index & " - " & oRule_Name
MessageBox.Show("@ THE BEGINING OF: " _
& vbLf & "" & oRule_Description _
& vbLf & "", "NOW RUNNING: " & oRule_Index)

oModelDoc = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
'save text parameter "MyText" value in the string variable Value'Dim Value As String = Parameter(oModelDoc, "Length")'Note: this string Value could be read from any source (e.g., excel sheet).
Dim oDoc As DrawingDocument = ThisDrawing.Document
    Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
    Dim oView As DrawingView
    'oView = oSheet.DrawingViews.Item(1)
    Dim oGeneralDimensions As GeneralDimensions
    oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
Dim oSSet As SelectSet = oDoc.SelectSet
100:
    Dim oLWT_Array As New ArrayList    
    oLWT_Array.add("Dim-1st")
    oLWT_Array.add("Dim-2nd")
    oLWT_Array.add("Dim-3rd")
    oLWT_Array.add("Dim-4th")
    oLWT_Array.add("Cancel")
    oLWT_Array_IP = InputListBox("SELECT FROM ABOVE!", oLWT_Array, oLWT_Array.Item(0), "COPY TO CLIPBOARD", "DIMENSION")
    If oLWT_Array_IP = "Cancel" Then Exit Sub

    
    obj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingDimensionFilter, "SELECT DIMENSION FOR " & UCase(oLWT_Array_IP))
    'Modelvalue - Returns model value As a Double, In database units (cm)  (379.73 cm)
    'OverrideModelValue - Returns dimension value As a Double, In database units. (381 cm)
    '.Text.Text - Returns the actual text As it appears in the box (150 in)
    '.Text.FormattedText still shows "</DimensionValue>"
    
    If TypeOf obj Is GeneralDimension Then
        'reference to the selected dimension
        Dim oDim As GeneralDimension = obj
        'refrence to the DimensionText object
        Dim oDimensionText As DimensionText = oDim.Text
        oDim_ModelValue_mm = oLWT_Array_IP & " " & CStr(oDim.Modelvalue*10)
        Clipboard.SetText(oDim_ModelValue_mm) 
        MessageBox.Show("Modelvalue in mm (copied to clipboard) is " & oDim_ModelValue_mm, "DIMENION")
    End If
    oYN = MessageBox.Show("PASTE IN TO NOTEPAD NOW!" _
    & vbLf & "" _
    & vbLf & "Do YOU WANT To Continue? ", "Assembly SIZES", MessageBoxButtons.YesNo)
If oYN = vbYes Then Goto 100:

'Beep'ThisApplication.Documents.Open(oModelDoc_Dwg, True)

End Sub

Just sharing!