How to use Addlinear with Thisdrawing.beginmange()

How to use Addlinear with Thisdrawing.beginmange()

andreas.jonssonF98YC
Enthusiast Enthusiast
224 Views
1 Reply
Message 1 of 2

How to use Addlinear with Thisdrawing.beginmange()

andreas.jonssonF98YC
Enthusiast
Enthusiast

Hi @JelteDeJong can you help me to convert a code that you wrote for overall dimensions 

http://www.hjalte.nl/37-auto-overall-dimension so it works with Thisdrawing.beginmange()

 

i tried to convert it according to http://hjalte.nl/24-ilogic-adds-dimensions-to-drawings but I failed

 

Private Sub createHorizontalOuterDimension()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.X)

        Dim pointLeft = orderedIntents.First
        Dim pointRight = orderedIntents.Last

        Dim textX = pointLeft.PointOnSheet.X +
                (pointRight.PointOnSheet.X - pointLeft.PointOnSheet.X) / 2
        Dim textY = _view.Position.Y - _view.Height / 2 - 2

        Dim pointText = ThisApplication.TransientGeometry.CreatePoint2d(textX, textY)



        _sheet.DrawingDimensions.GeneralDimensions.AddLinear(
            pointText, pointLeft, pointRight, DimensionTypeEnum.kHorizontalDimensionType)
	
    End Sub
	
    Private Sub createVerticalOuterDimension()
    Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.Y)

    Dim pointLeft = orderedIntents.Last
    Dim pointRight = orderedIntents.First

    Dim textY = pointLeft.PointOnSheet.Y +
            (pointRight.PointOnSheet.Y - pointLeft.PointOnSheet.Y) / 2
    Dim textX = _view.Position.X + _view.Width / 2 + 2

    Dim pointText = ThisApplication.TransientGeometry.CreatePoint2d(textX, textY)

    
    
       
			_sheet.DrawingDimensions.GeneralDimensions.AddLinear(
            pointText, pointLeft, pointRight, DimensionTypeEnum.kVerticalDimensionType)
     

      

    
End Sub

 

 

 

 

0 Likes
225 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

Try it like this:

Public Class ThisRule
    Private _doc As DrawingDocument
    Private _sheet As Sheet
    Private _view As DrawingView
    Private _intents As List(Of GeometryIntent) = New List(Of GeometryIntent)()
	Private _generalDimensions As IManagedGeneralDimensions
	Private _managedView As IManagedDrawingView 
	
    Sub Main()
        _doc = ThisDoc.Document
        _sheet = _doc.ActiveSheet
        _view = ThisApplication.CommandManager.Pick(
                       SelectionFilterEnum.kDrawingViewFilter, 
                       "Select a drawing view")

		_managedView = ThisDrawing.ActiveSheet.View(_view.Name)
		_generalDimensions = ThisDrawing.ActiveSheet.DrawingDimensions.GeneralDimensions
		
        CreateIntentList()
		
		ThisDrawing.BeginManage()
        createHorizontalOuterDimension()
        createVerticalOuterDimension()
		ThisDrawing.EndManage()
    End Sub

    Private Sub createHorizontalOuterDimension()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.X)

        Dim pointLeft = orderedIntents.First
        Dim pointRight = orderedIntents.Last
		
		_generalDimensions.AddLinear(_view.Name & "Horizontal", _managedView.SheetPoint(0, 1.1), 
			pointLeft, pointRight, dimensionType := DimensionTypeEnum.kHorizontalDimensionType)

    End Sub
    Private Sub createVerticalOuterDimension()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.Y)

        Dim pointLeft = orderedIntents.Last
        Dim pointRight = orderedIntents.First
		
		_generalDimensions.AddLinear(_view.Name & "Vertical", _managedView.SheetPoint(-0.1, 0), 
			pointLeft, pointRight, dimensionType := DimensionTypeEnum.kVerticalDimensionType)
    End Sub

    Private Sub addIntent(Geometry As DrawingCurve, IntentPlace As Object, onLineCheck As Boolean)
        Dim intent As GeometryIntent = _sheet.CreateGeometryIntent(Geometry, IntentPlace)
        If intent.PointOnSheet Is Nothing Then Return

        If onLineCheck Then
            If (IntentIsOnCurve(intent)) Then
                _intents.Add(intent)
            End If
        Else
            _intents.Add(intent)
        End If
    End Sub

    Private Function IntentIsOnCurve(intent As GeometryIntent) As Boolean
        Dim Geometry As DrawingCurve = intent.Geometry
        Dim sp = intent.PointOnSheet

        Dim pts(1) As Double
        Dim gp() As Double = {}
        Dim md() As Double = {}
        Dim pm() As Double = {}
        Dim st() As SolutionNatureEnum = {}
        pts(0) = sp.X
        pts(1) = sp.Y

        Try
            Geometry.Evaluator2D.GetParamAtPoint(pts, gp, md, pm, st)
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function

    Private Sub CreateIntentList()

        For Each oDrawingCurve As DrawingCurve In _view.DrawingCurves
            Select Case oDrawingCurve.ProjectedCurveType
                Case _
                        Curve2dTypeEnum.kCircleCurve2d,
                        Curve2dTypeEnum.kCircularArcCurve2d,
                        Curve2dTypeEnum.kEllipseFullCurve2d,
                        Curve2dTypeEnum.kEllipticalArcCurve2d

                    addIntent(oDrawingCurve, PointIntentEnum.kCircularTopPointIntent, True)
                    addIntent(oDrawingCurve, PointIntentEnum.kCircularBottomPointIntent, True)
                    addIntent(oDrawingCurve, PointIntentEnum.kCircularLeftPointIntent, True)
                    addIntent(oDrawingCurve, PointIntentEnum.kCircularRightPointIntent, True)

                    addIntent(oDrawingCurve, PointIntentEnum.kEndPointIntent, False)
                    addIntent(oDrawingCurve, PointIntentEnum.kStartPointIntent, False)

                Case _
                        Curve2dTypeEnum.kLineCurve2d,
                        Curve2dTypeEnum.kLineSegmentCurve2d

                    addIntent(oDrawingCurve, PointIntentEnum.kEndPointIntent, False)
                    addIntent(oDrawingCurve, PointIntentEnum.kStartPointIntent, False)

                Case _
                    Curve2dTypeEnum.kPolylineCurve2d,
                    Curve2dTypeEnum.kBSplineCurve2d,
                    Curve2dTypeEnum.kUnknownCurve2d

                    ' Unhandled curves types
                Case Else
            End Select
        Next
    End Sub
End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes