Edit dimension in template drawing

Edit dimension in template drawing

Anonymous
Not applicable
593 Views
8 Replies
Message 1 of 9

Edit dimension in template drawing

Anonymous
Not applicable

Hi..

 

I'm new and trying to do some automation on autocad with VBA.

I need to modify some of the dimensions (text only) in a standard template of outline drawing for different cases.

 

I tried to identify the dimensions which need modification by using handle.

But after that i have no idea how to change the text in it.

 

Hope can get some suggestion and help here.

Thanks.

 

 

 

 

 

 

 

0 Likes
594 Views
8 Replies
Replies (8)
Message 2 of 9

Hallex
Advisor
Advisor

Here is a code that will you override the dimension text

Is there  what you need?

Option Explicit

Sub OverrideDimension()

Dim oEnt As AcadEntity
Dim oDim As AcadDimension
Dim oDimAl As AcadDimAligned
Dim oDimRot As AcadDimRotated
Dim oSset As AcadSelectionSet
Dim sizeStr As String
Dim dblStep As Double
Dim dblDim As Double
Dim iCount As Integer
Dim dimStr As String
Dim ftype(0) As Integer
Dim fdata(0) As Variant
Dim dimPrec As Integer
dimPrec = ThisDrawing.GetVariable("dimdec")

sizeStr = InputBox("Enter a size" & vbCr & _
"(50,100,150,200,250,300) :", "Parameter Input", "200.0")

dblStep = Val(Replace(sizeStr, ",", ".", 1, -1, vbTextCompare))

 
          With ThisDrawing.SelectionSets
               While .Count > 0
                    .Item(0).Delete
               Wend
               Set oSset = .Add("$Dim$")
          End With
          
      ftype(0) = 0: fdata(0) = "DIMENSION"
     oSset.SelectOnScreen ftype, fdata
     For Each oEnt In oSset

     If TypeOf oEnt Is AcadDimAligned Then
     Set oDimAl = oEnt
     dblDim = oDimAl.Measurement
     iCount = CInt(dblDim / dblStep)
     dimStr = CStr(Round(dblStep, dimPrec))
     oDimAl.TextOverride = dimStr
     ElseIf TypeOf oEnt Is AcadDimRotated Then
     Set oDimRot = oEnt
     dblDim = oDimRot.Measurement
          iCount = CInt(dblDim / dblStep)
     dimStr = CStr(Round(dblStep, dimPrec))
     oDimRot.TextOverride = dimStr

     End If
     
     Next oEnt
End Sub

 

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 9

Anonymous
Not applicable

Dear Hallex,

 

Thank you very much for your reply.

 

But i dont think it is something in my mind.

 

The senario is, i have a template drawing with the outline of let say a square box.

 

i dimension the length = A, width = B, height =C

 

Using VBA, i create a form to key in the value of A, B and C to override into three of the dimension.

 

The problem i facing is i cannot figure out how to override the dimension without manually select the dimension itself.

The actual case is the dimension need to be override is approximatte 50~60. So i cant afford to select one by one...

 

 

 

 

0 Likes
Message 4 of 9

Hallex
Advisor
Advisor

In this case create template with box  where dimensions are: 1x1x1

and add all three dimensions in there

then in the form you have to add new dimensions

and scale template using scale by X,Y and Z

and set dimension text size and arrowhead size to

your suit after, sorry, just a hint :)\

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 5 of 9

Anonymous
Not applicable

Thanks Hallex for replying

 

The box is an example. As i mentioned in my previous post, the actual case i need to modify 50~60 dimensions.

 

My idea is, i dont change any thing on the title block and drawing itself.

Just wanted to change the text on the dimension.

 

Hope anyone out here can advise.

0 Likes
Message 6 of 9

Hallex
Advisor
Advisor

Do you want to scale all of the dimensions by the same scale factor?

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 7 of 9

Hallex
Advisor
Advisor

Not sure about if this a right way, just a try

Option Explicit

Sub test()
     Dim oDim As AcadDimension
     Dim oDimRot As AcadDimRotated
     Dim oDimAlg As AcadDimAligned
     '' add other dim types here
     Dim oEnt As AcadEntity
     Dim scl As Double

     Dim oSset As AcadSelectionSet
     Dim setColl As AcadSelectionSets

     Dim setName As String
     Dim selMod As Long

     Dim gpCode(0) As Integer
     Dim dataValue(0) As Variant
     Dim dxfcode, dxfdata

          scl = Val(InputBox("Enter a scale: ", "Parameter Input", 0.25))

     On Error GoTo SayMeOnError
     gpCode(0) = 0
     dataValue(0) = "DIM*"
     dxfcode = gpCode: dxfdata = dataValue
     setName = "$Dims$"

     With ThisDrawing
          Set setColl = .SelectionSets
          For Each oSset In setColl
               If oSset.Name = setName Then
                    .SelectionSets.Item(setName).Delete
                    Exit For
               End If
          Next
          Set oSset = .SelectionSets.Add(setName)
     End With
    
     selMod = AcSelect.acSelectionSetAll
     
     oSset.Select selMod, dxfcode, dxfdata
     
     If oSset.Count = 0 Then Exit Sub
     
     oSset.Highlight True
     
     ' >> do your stuffs here
          Dim minpt As Variant
          Dim maxpt As Variant
          
     For Each oEnt In oSset
          If TypeOf oEnt Is AcadDimRotated Or _
          TypeOf oEnt Is AcadDimAligned Then 'Or etc...
          Set oDim = oEnt
          oDim.GetBoundingBox minpt, maxpt
          oDim.ScaleEntity minpt, scl
          oDim.Update
          
          End If
     Next
ThisDrawing.Regen acActiveViewport
Set oSset = Nothing
SayMeOnError:
          If Err.Number <> 0 Then
     MsgBox Err.Description
          End If

End Sub

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 8 of 9

Anonymous
Not applicable
Hi , Code given does help a lot. However, can you advise me how to identify/select the dimension with more specific criteria? For example: 1) Either by diemsnion's handle or ID 2) By text value (I'll preset the dimension which need to be change to something like X1,X2,X3...X40, then the code will replace these X1,X2... to the value i need) Btw, i do not need to scale the drawing or dimension.. It is a non scale drawing for outline dimension purpose only. Hope to get some advise. Thanks.
0 Likes
Message 9 of 9

Hallex
Advisor
Advisor

Sorry for the belating, but I have no idea about,

 

Smiley Sad

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes