Message 1 of 14
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Please help, this is a massive time saver.
I have had a section of code which has been running for years, today it stopped working?
What is does:
In the drawing view I select a curved line
Step 1 - Add an Angle dimension to the curve
Step 2 - Add an Arc Length dimension to the line
Step 3 - Overwrite the Angle Dimension with the Arc Length dimension value
Step 4- Place the Arc Length dimension on a hidden layer
This still works for a model edge, however it has stopped working for sketch lines
In other words, when generating drawings I used sketches in the view and add dimension to the sketch lines.
This has stopped working.
Code:
'Revision 2
'Change the Dimension location to a fixed value
'
'IDW_Angle_and Arc_Length Dimension
'This code will automatically create an arclength dimension, as well as add an agle equivalent dimension.
'on the selected curve. It will automatically place it on the Hidden Layer.
'Once again, a time saving
'NOTE:
'Refer the code IDW_ArcLength Dimension which is identical, It only does arc length
'*** NB***
'The Angular dimension MUST be edited before exporting.
'I cannot explain why, but it will not format the export correctly
'Reg Hasell
'Rev 1 18.07.19
Sub main()
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oCurveSeg As DrawingCurveSegment
oCurveSeg = ThisApplication.CommandManager.Pick(kDrawingCurveSegmentFilter, "Select an arc drawing curve")
If oCurveSeg Is Nothing Then
Exit Sub
End If
Dim oCurve As DrawingCurve
oCurve = oCurveSeg.Parent
If oCurve.CurveType <> kCircularArcCurve Then
MessageBox.Show("The selected drawing curve is not an arc curve!", "Title")
Exit Sub
End If
Dim dPosX As Double, dPosY As Double
''If oCurve.MidPoint.X <= oCurve.CenterPoint.X Then
'' dPosX = oCurve.MidPoint.X * 3 / 2 - oCurve.CenterPoint.X / 2
''Else
'' dPosX = oCurve.MidPoint.X / 2 + oCurve.CenterPoint.X / 2
dPosX = oCurve.MidPoint.X 'Rev 2
''End If
''If oCurve.MidPoint.Y <= oCurve.CenterPoint.Y Then
'' dPosY = oCurve.MidPoint.Y * 3 / 2 - oCurve.CenterPoint.Y / 2
''Else
'' dPosY = oCurve.MidPoint.Y / 2 + oCurve.CenterPoint.Y / 2
dPosY = oCurve.MidPoint.Y +1 'Rev 2
''End If
Dim oPos As Point2d
oPos = ThisApplication.TransientGeometry.CreatePoint2d(dPosX, dPosY)
Dim oIntent As GeometryIntent
oIntent = oSheet.CreateGeometryIntent(oCurve)
Dim oArcLayer = oDoc.StylesManager.Layers("1_Dim_hidden")
Dim oArcLenDim As LinearGeneralDimension
oArcLenDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPos, oIntent, , kArcLengthDimensionType, , , oArcLayer)
'oArcLenDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPos, oIntent, , kArcLengthDimensionType)
ArcLength = Round(oArcLenDim.ModelValue, 1)
'oArcLenDim.Delete 'Removed because I can do both in one step
'Dim oLayer = oDoc.StylesManager.Layers("Dimension")
Dim oDimStyle = oDoc.StylesManager.DimensionStyles("Default")
'oArcLenDim = oSheet.DrawingDimensions.GeneralDimensions.AddAngular(oPos, oIntent)
'oAngleDim = oSheet.DrawingDimensions.GeneralDimensions.AddAngular(oPos, oIntent, , , , False) ' This line works
'oAngleDim = oSheet.DrawingDimensions.GeneralDimensions.AddAngular(oPos, oIntent, , , , , , oDimStyle, oLayer)
oAngleDim = oSheet.DrawingDimensions.GeneralDimensions.AddAngular(oPos, oIntent, , , , , , oDimStyle)
oAngleDim.HideValue = True
'Define colour
'Note: The export to Autocad was not formatting the Text correctly.
Dim oColor As Color
'set color to black
oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 0)
oColor.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource
Dim oDimensionText As DimensionText = oAngleDim.Text
oSym = "<StyleOverride Font='AIGDT' FontSize='0.25'>" & Chr(94) & "</StyleOverride>"
Dim oValue=ArcLength * 10
oDimensionText.LineSpacingType = (29185) ' this is the correct string to format the line for "Exact"
oDimensionText.HorizontalJustification = (19969) ' this is the correct string to format the line for "Center Justifictaion"
oDimensionText.LineSpacing = ("0.25") ' This will set the dimension text to Multiple of 0.1\
oDimensionText.Color = oColor
'oAngleDim.Text.FormattedText = ArcLength * 10
oAngleDim.Text.FormattedText = oSym & "<br/>" & oValue
sAgain()
End Sub
Sub sAgain()
oAgain = MessageBox.Show("Again", "Rinse and Repeat", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If oAgain = vbYes
Main()
End If
End Sub
Reg
2026.1
2026.1
Solved! Go to Solution.