iLogic for selecting multiple views / all views on drawing sheet and running a rule

iLogic for selecting multiple views / all views on drawing sheet and running a rule

iUser
Advocate Advocate
1,101 Views
6 Replies
Message 1 of 7

iLogic for selecting multiple views / all views on drawing sheet and running a rule

iUser
Advocate
Advocate

Can someone please help me? I'm still new to iLogic and need 2 snippets of code for a profile sheet (Our company places all the profiles on a single sheet). 

 

1. Select all views on drawing sheet and runs an external rule for the selected views.

2. Select some views on drawing sheet and runs an external rule for the selected views.

 

The external rule adds overall dimensions to each profile, but I am having to run the code for each profile (http://www.hjalte.nl/37-auto-overall-dimension). 

 

Thanks in advance!

0 Likes
1,102 Views
6 Replies
Replies (6)
Message 2 of 7

Michael.Navara
Advisor
Advisor

1) Here is snippet for run external rule for each drawing view on the active sheet

 

Dim externalRuleName As String = "MyExternalRuleForDrawingView"

Dim drw As DrawingDocument = ThisDoc.Document
Dim activeSheet As Sheet = drw.ActiveSheet

For Each drwView As DrawingView In activeSheet.DrawingViews
	Dim args As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	args.Add("DrawingView", drwView)
	
	iLogicVb.RunExternalRule(externalRuleName, args)
Next

 

 

External rule "MyExternalRuleForDrawingView" sample

 

Dim drwView As DrawingView = RuleArguments("DrawingView")
Logger.Debug(drwView.Name)

 

This snippet uses standard Inventor API for drawing views

 

2) Please specify what does it mean "some views"

Message 3 of 7

iUser
Advocate
Advocate

Hi Michael, that's great, thank you! So the code actually took care of number 2. Do you have a code that selects all views on the sheet? This code makes select "some views". I would like to be able to do both. See video attached using your code.

 

 

0 Likes
Message 4 of 7

iUser
Advocate
Advocate

@Michael.Navara see my answer above. Another question I have is, this code puts me in a loop. How do I end the code?

0 Likes
Message 5 of 7

Michael.Navara
Advisor
Advisor

My code calls external rule for each drawing view of active sheet of active drawing document. 

"Some views" can be:

  • Selected views
  • Base views only
  • Isometric views
  • etc.

I don't know, what do you mean.

0 Likes
Message 6 of 7

iUser
Advocate
Advocate

@Michael.Navara - I am using your code to run the rule below. In this code its asking me to pick a view (see code in blue below). I do not know how to change it, but its keeping the rule running. So the only way for me to end the rule is to hit the escape button on the keyboard many times (at least 5 times). Are you able to integrate your code into this code so I can select multiple views on a drawing sheet and hit escape once to end to rule? Thanks in advance.

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

JelteDeJong
Mentor
Mentor

If I'm correct this is the same question as here:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-for-overall-measurements-of-m... 

There you will find an answer on how to do it.

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