iLogic for overall measurements of multiple parts on a drawing.

iLogic for overall measurements of multiple parts on a drawing.

iUser
Advocate Advocate
586 Views
4 Replies
Message 1 of 5

iLogic for overall measurements of multiple parts on a drawing.

iUser
Advocate
Advocate

@JelteDeJong - Firstly I just want to thank you for this amazing iLogic code you wrote, it will definitely save me some time when creating certain drawings. I am still new to iLogic, but I was hoping you or someone could modify the code a bit? Our company places all the plasma profiles on a single sheet and I would like to be able to run your code so that it automatically puts overall measurements on all views on a single sheet. Currently you have to select each view individually and then run the code.  

 

Public Class ThisRule
	' This code was written by Jelte de Jong
	' and published on www.hjalte.nl
    Private _doc As DrawingDocument
    Private _sheet As Sheet
    Private _view As DrawingView
    Private _intents As List(Of GeometryIntent) = New List(Of GeometryIntent)()

    Sub Main()
        _doc = ThisDoc.Document
        _sheet = _doc.ActiveSheet
        _view = ThisApplication.CommandManager.Pick(
                       SelectionFilterEnum.kDrawingViewFilter, 
                       "Select a drawing view")

        CreateIntentList()
        createHorizontalOuterDimension()
        createVerticalOuterDimension()
    End Sub

    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

    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

    ' Copyright 2021
    ' 
    ' This code was written by Jelte de Jong, and published on www.hjalte.nl
	'
	' Permission Is hereby granted, free of charge, to any person obtaining a copy of this 
    ' software And associated documentation files (the "Software"), to deal in the Software 
    ' without restriction, including without limitation the rights to use, copy, modify, merge, 
    ' publish, distribute, sublicense, And/Or sell copies of the Software, And to permit persons 
    ' to whom the Software Is furnished to do so, subject to the following conditions:
    '
    ' The above copyright notice And this permission notice shall be included In all copies Or
    ' substantial portions Of the Software.
    ' 
    ' THE SOFTWARE Is PROVIDED "AS IS", WITHOUT WARRANTY Of ANY KIND, EXPRESS Or IMPLIED, 
    ' INCLUDING BUT Not LIMITED To THE WARRANTIES Of MERCHANTABILITY, FITNESS For A PARTICULAR 
    ' PURPOSE And NONINFRINGEMENT. In NO Event SHALL THE AUTHORS Or COPYRIGHT HOLDERS BE LIABLE 
    ' For ANY CLAIM, DAMAGES Or OTHER LIABILITY, WHETHER In AN ACTION Of CONTRACT, TORT Or 
    ' OTHERWISE, ARISING FROM, OUT Of Or In CONNECTION With THE SOFTWARE Or THE USE Or OTHER 
    ' DEALINGS In THE SOFTWARE.
End Class

 

0 Likes
587 Views
4 Replies
Replies (4)
Message 2 of 5

JelteDeJong
Mentor
Mentor

You can try the following. Replace the sub main with the following sub main.

Public Sub Main()
    _doc = ThisDoc.Document
    _sheet = _doc.ActiveSheet

    For Each view As DrawingView In _sheet.DrawingViews
        _view = view
        _intents = New List(Of GeometryIntent)()

        CreateIntentList()
        createHorizontalOuterDimension()
        createVerticalOuterDimension()
    Next
End Sub

I have not tested the code. If it doesn't work let me know and I will have a better look when I have more time.

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
Message 3 of 5

iUser
Advocate
Advocate

@JelteDeJong - You are amazing! Thank you! I am trying to add this into another code you wrote, but it gives an error. Are you able to look into this too please? I would like to run your code (http://www.hjalte.nl/40-hole-position-dimensions) for all the views on the sheet:

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 _centerPointIntents As List(Of GeometryIntent) = New List(Of GeometryIntent)()

    ' Some settings here for you to change. 
    Private _stackedDimensions As Boolean = True
    Private _firstOffset As Double = 1.2 'Cm
    Private _offsetDimension As Double = 0.6 'Cm

    Public Sub Main()
        _doc = ThisDoc.Document
        _sheet = _doc.ActiveSheet
        _view = ThisApplication.CommandManager.Pick(
                       SelectionFilterEnum.kDrawingViewFilter,
                       "Select a drawing view")

        Dim transaction As Transaction = ThisApplication.TransactionManager.StartTransaction(_doc, "Generate dimensions")
        CreateIntentList()

        ' Comment out features that you dont want/need!
        CreateHorizontalDimensions()
        CreateVerticalDimensions()
        CreateMarks()
        'AddDiameterDimensionToCircles()
         'CreateHorizontalOuterDimension()
         'createVerticalOuterDimension()

        transaction.End()
    End Sub


    Public Sub CreateHorizontalDimensions()
        Dim orderedIntents = _intents.OrderBy(Function(s) s.PointOnSheet.X)
        Dim orderedCenterIntents = _centerPointIntents.OrderBy(Function(s) s.PointOnSheet.X)

        Dim pointLeft = orderedIntents.First
        Dim pointRight = Nothing
        Dim lastX = pointLeft.PointOnSheet.X
        Dim offset As Double = _firstOffset
        For Each intent As GeometryIntent In orderedCenterIntents
            pointRight = intent
            If (AreEqual(pointRight.PointOnSheet.X, lastX)) Then
                Continue For
            End If
            CreateHorizontalDimension(pointLeft, pointRight, offset)
            If _stackedDimensions Then
                offset = offset + _offsetDimension
            Else
                pointLeft = pointRight
            End If
            lastX = pointRight.PointOnSheet.X
        Next
        pointRight = orderedIntents.Last

        CreateHorizontalDimension(pointLeft, pointRight, offset)

    End Sub
    Private Sub CreateHorizontalDimension(pointLeft As GeometryIntent,
                                          pointRight As GeometryIntent,
                                          distanceFromView As Double)
        Dim textX = pointLeft.PointOnSheet.X +
                (pointRight.PointOnSheet.X - pointLeft.PointOnSheet.X) / 2
        Dim textY = _view.Position.Y + _view.Height / 2 + distanceFromView

        Dim pointText = ThisApplication.TransientGeometry.CreatePoint2d(textX, textY)
        _sheet.DrawingDimensions.GeneralDimensions.AddLinear(
            pointText, pointLeft, pointRight, DimensionTypeEnum.kHorizontalDimensionType)
    End Sub
    Private Sub CreateHorizontalOuterDimension()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.X)

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

        CreateHorizontalDimension(pointLeft, pointRight, _firstOffset - _offsetDimension)
    End Sub

    Public Sub CreateVerticalDimensions()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.Y)
        Dim orderedCenterIntents = _centerPointIntents.OrderByDescending(Function(s) s.PointOnSheet.Y)

        Dim pointLeft = orderedIntents.First
        Dim pointRight = Nothing
        Dim lastY = pointLeft.PointOnSheet.Y
        Dim offset As Double = _firstOffset
        For Each intent As GeometryIntent In orderedCenterIntents
            pointRight = intent
            If (AreEqual(pointRight.PointOnSheet.Y, lastY)) Then
                Continue For
            End If
            CreateVerticalDimension(pointLeft, pointRight, offset)
            If _stackedDimensions Then
                offset = offset + _offsetDimension
            Else
                pointLeft = pointRight
            End If
            lastY = pointRight.PointOnSheet.Y
        Next
        pointRight = orderedIntents.Last

        CreateVerticalDimension(pointLeft, pointRight, offset)

    End Sub

    Private Sub CreateMarks()
        Dim done As List(Of GeometryIntent) = New List(Of GeometryIntent)()
        Dim orderedCenterIntents = _centerPointIntents.OrderByDescending(Function(s) s.PointOnSheet.Y)
        Dim firstIntent = orderedCenterIntents(0)
        Dim secondIntent = Nothing
        For i = 1 To orderedCenterIntents.Count - 1
            secondIntent = orderedCenterIntents(i)
            If (AreEqual(firstIntent.PointOnSheet.Y, secondIntent.PointOnSheet.Y)) Then
                CreateCenterLine(firstIntent, secondIntent)
                done.Add(firstIntent)
                done.Add(secondIntent)
            End If
            firstIntent = secondIntent
        Next

        orderedCenterIntents = _centerPointIntents.OrderByDescending(Function(s) s.PointOnSheet.X)
        firstIntent = orderedCenterIntents(0)
        secondIntent = Nothing
        For i = 1 To orderedCenterIntents.Count - 1
            secondIntent = orderedCenterIntents(i)
            If (AreEqual(firstIntent.PointOnSheet.X, secondIntent.PointOnSheet.X)) Then
                CreateCenterLine(firstIntent, secondIntent)
                done.Add(firstIntent)
                done.Add(secondIntent)
            End If
            firstIntent = secondIntent
        Next

        For Each intent As GeometryIntent In orderedCenterIntents
            If (done.Contains(intent)) Then
                Continue For
            End If
            _sheet.Centermarks.Add(intent)
        Next

    End Sub
    Public Sub CreateCenterLine(pointLeft As GeometryIntent, pointRight As GeometryIntent)
        Dim collection = ThisApplication.TransientObjects.CreateObjectCollection()
        collection.Add(pointLeft)
        collection.Add(pointRight)
        _sheet.Centerlines.Add(collection)
    End Sub

    Private Sub CreateVerticalDimension(pointLeft As GeometryIntent,
                                        pointRight As GeometryIntent,
                                        distanceFromView As Double)

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

        Dim pointText = ThisApplication.TransientGeometry.CreatePoint2d(textX, textY)
        _sheet.DrawingDimensions.GeneralDimensions.AddLinear(
            pointText, pointLeft, pointRight, DimensionTypeEnum.kVerticalDimensionType)
    End Sub
    Private Sub CreateVerticalOuterDimension()
        Dim orderedIntents = _intents.OrderByDescending(Function(s) s.PointOnSheet.Y)

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

        CreateVerticalDimension(pointLeft, pointRight, _firstOffset - _offsetDimension)

    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 drawingCurve As DrawingCurve In _view.DrawingCurves
            Select Case DrawingCurve.ProjectedCurveType
                Case _
                        Curve2dTypeEnum.kCircleCurve2d,
                        Curve2dTypeEnum.kCircularArcCurve2d,
                        Curve2dTypeEnum.kEllipseFullCurve2d,
                        Curve2dTypeEnum.kEllipticalArcCurve2d

                    AddIntent(DrawingCurve, PointIntentEnum.kCircularTopPointIntent, True)
                    AddIntent(DrawingCurve, PointIntentEnum.kCircularBottomPointIntent, True)
                    AddIntent(DrawingCurve, PointIntentEnum.kCircularLeftPointIntent, True)
                    AddIntent(DrawingCurve, PointIntentEnum.kCircularRightPointIntent, True)

                    AddIntent(DrawingCurve, PointIntentEnum.kEndPointIntent, False)
                    AddIntent(DrawingCurve, PointIntentEnum.kStartPointIntent, False)

                    If (DrawingCurve.ProjectedCurveType = Curve2dTypeEnum.kCircleCurve2d) Then
                        Dim intent = _sheet.CreateGeometryIntent(DrawingCurve, PointIntentEnum.kCenterPointIntent)
                        _centerPointIntents.Add(intent)
                    End If
                Case _
                        Curve2dTypeEnum.kLineCurve2d,
                        Curve2dTypeEnum.kLineSegmentCurve2d

                    AddIntent(DrawingCurve, PointIntentEnum.kEndPointIntent, False)
                    AddIntent(DrawingCurve, PointIntentEnum.kStartPointIntent, False)

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

                    ' Unhandled curves types
                Case Else
            End Select
        Next
    End Sub


    Private Sub AddDiameterDimensionToCircles()
        For Each intent As GeometryIntent In _intents
            Dim geo = intent.Geometry
            If (geo.type <> ObjectTypeEnum.kDrawingCurveObject) Then
                Continue For
            End If
            Dim curve As DrawingCurve = geo
            If (curve.ProjectedCurveType <> Curve2dTypeEnum.kCircleCurve2d) Then
                Continue For
            End If
            Dim rangeBox = curve.Evaluator2D.RangeBox
            Dim radius = (rangeBox.MaxPoint.X - rangeBox.MinPoint.X) / 2
            Dim x = curve.CenterPoint.X + radius
            Dim y = curve.CenterPoint.Y + radius
            Dim textPoint = ThisApplication.TransientGeometry.CreatePoint2d(x, y)
            _sheet.DrawingDimensions.GeneralDimensions.AddDiameter(textPoint, intent)
        Next
    End Sub

    Private Function AreEqual(d1 As Double, d2 As Double)
        Return (Math.Abs(d1 - d2) < 0.000001)
    End Function

    ' Copyright 2021
    ' 
    ' This code was written by Jelte de Jong, and published on www.hjalte.nl
    '
    ' Permission Is hereby granted, free of charge, to any person obtaining a copy of this 
    ' software And associated documentation files (the "Software"), to deal in the Software 
    ' without restriction, including without limitation the rights to use, copy, modify, merge, 
    ' publish, distribute, sublicense, And/Or sell copies of the Software, And to permit persons 
    ' to whom the Software Is furnished to do so, subject to the following conditions:
    '
    ' The above copyright notice And this permission notice shall be included In all copies Or
    ' substantial portions Of the Software.
    ' 
    ' THE SOFTWARE Is PROVIDED "AS IS", WITHOUT WARRANTY Of ANY KIND, EXPRESS Or IMPLIED, 
    ' INCLUDING BUT Not LIMITED To THE WARRANTIES Of MERCHANTABILITY, FITNESS For A PARTICULAR 
    ' PURPOSE And NONINFRINGEMENT. In NO Event SHALL THE AUTHORS Or COPYRIGHT HOLDERS BE LIABLE 
    ' For ANY CLAIM, DAMAGES Or OTHER LIABILITY, WHETHER In AN ACTION Of CONTRACT, TORT Or 
    ' OTHERWISE, ARISING FROM, OUT Of Or In CONNECTION With THE SOFTWARE Or THE USE Or OTHER 
    ' DEALINGS In THE SOFTWARE.
End Class

 

0 Likes
Message 4 of 5

JelteDeJong
Mentor
Mentor

Change the main sub to this:

    Public Sub Main()
        _doc = ThisDoc.Document
        _sheet = _doc.ActiveSheet

        For Each view As DrawingView In _sheet.DrawingViews
            _view = view
            _intents = New List(Of GeometryIntent)()
            CreateIntentList()

            ' Comment out features that you dont want/need!
            CreateHorizontalDimensions()
            CreateVerticalDimensions()
            CreateMarks()
            'AddDiameterDimensionToCircles()
            'CreateHorizontalOuterDimension()
            'createVerticalOuterDimension()
        Next
    End Sub

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
Message 5 of 5

GosponZ
Collaborator
Collaborator

Great rule. How about ordinate dimensions. Can that be possible? Thanks

0 Likes