Modification of overall dimension code

Modification of overall dimension code

floccipier
Advocate Advocate
1,648 Views
11 Replies
Message 1 of 12

Modification of overall dimension code

floccipier
Advocate
Advocate

http://hjalte.nl/37-auto-overall-dimension

 

Hi @JelteDeJong just checked your code for overall dimensions and this is working brilliantly. 

Instead of running this on individual views I want to run it on all views of the open drawing. if you could please modify this, that would be awesome. 

 

Thank you. 

0 Likes
Accepted solutions (1)
1,649 Views
11 Replies
Replies (11)
Message 2 of 12

floccipier
Advocate
Advocate

here is code if someone else gets a chance to find solution:-

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
End Class
0 Likes
Message 3 of 12

JelteDeJong
Mentor
Mentor
Accepted solution

try this rule it will loop over all sheets and all drawingviews.

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) 

    Sub Main()
        _doc = ThisDoc.Document
		
		For Each sheet In _doc.sheets	
			_sheet = Sheet
			For Each view In _sheet.DrawingViews
				_view = View
				_intents =  New List(Of GeometryIntent)()
				CreateIntentList()
			    createHorizontalOuterDimension()
			    createVerticalOuterDimension()
			Next
		Next



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

Message 4 of 12

floccipier
Advocate
Advocate
Thank you so much - its not much but morning coffee is on me.
Message 5 of 12

JelteDeJong
Mentor
Mentor

Thank you for the coffee I appreciate it a lot 😄

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

Message 6 of 12

robertast
Collaborator
Collaborator

@JelteDeJong 

good job, beer sent for your job

Message 7 of 12

robertast
Collaborator
Collaborator

@JelteDeJong 

Tell me, are there any holes in the details at your job? Maybe such a problem, auto size of the position of the holes, when you come up with a solution. 😉

Then I'll run for wine 😉

Message 8 of 12

JelteDeJong
Mentor
Mentor

@robertastThank you for the Beer 😄

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

Message 9 of 12

JelteDeJong
Mentor
Mentor

@robertast 
It's not completely clear what you need. Maybe you could post a screenshot of what you envision. Maybe it's a good topic for a new blog post 😉

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

Message 10 of 12

robertast
Collaborator
Collaborator

@JelteDeJong 

I drew the furniture and spent most of my time marking the dimensions of the holes. I don’t know if it can be automated, but the basics of your work thought you might succeed. If the program would add large amounts of dimensions, it would not be bad to delete them faster than to add them again.

dim hole.jpg

Message 11 of 12

benigno.martinezvaldez
Participant
Participant

Hi 
I have a rule that make 2d Drawing for all my stps in specific Path , send to print , and close the stp file.
How can i call this Class ? i made it by diferents ways but don work

 

If a run the Class directly , i dont have problem

This is my main Rule  , and i have other rules to make this into all the files in a specific Path

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports System.Windows.Forms
Dim oDrawingDoc as DrawingDocument    
Dim oPartDoc as Document
Dim oSheet As sheet
Dim oView1 as DrawingView
Dim oView2 as DrawingView
Dim oView3 as DrawingView
Dim oView4 as DrawingView

' Obtener la medida en cada eje , con precision de 2 decimales.
Medidaenx=Round(Measure.ExtentsLength,2)
Medidaeny=Round(Measure.ExtentsWidth,2)
Medidaenz=Round(Measure.ExtentsHeight,2)

' Se obtiene el nombre del STP sin la extension.
Dim name As String
name=ThisDoc.FileName(False) 

' Se evalua las 3 medidas de bloque x , y , z y se obtiene la mayor , dicha medida se divide por el factor y esa es la escala de las vistas
Escala=MaxOfMany(medidaenx, medidaeny, medidaenz)

ViewScale = 91/escala


    oPartDoc = ThisDoc.Document
       
    'Check to see if part is a sheetmetal part
    If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 
        'do nothing 
    Else
        'ensure this part has a flat pattern
        Dim oSMDef As SheetMetalComponentDefinition
        oSMDef = oPartDoc.ComponentDefinition
        If oSMDef.FlatPattern Is Nothing Then 
        'create flat pattern
        oSMDef.Unfold
        oSMDef.FlatPattern.ExitEdit
        oSMDef.FlatPattern.FlipBaseFace
        Else
        'do nothing
        End If 
    End If
    
    'Se define la ubicacion del Template
    oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "O:\Operaciones\Maquinado\OTs\FFA-01-19 Dibujo estandar.idw", True)
    oSheet = oDrawingDoc.Sheets.Item(1)
    
 ' Create a new NameValueMap object
  Dim oBaseViewOptions As NameValueMap
  oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap
 
 'True = folded view  False = flat pattern view
  oBaseViewOptions.Add("SheetMetalFoldedModel", False) 
   
'Se define el punto inferior izquierdo para cada una de las vistas
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(9, 10) ' front view
oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(9, 20) ' top view
oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(28, 10)' right view
oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(28, 20)' iso

 ' Se abre un sketch para generar los textos
    Dim oSketch As DrawingSketch
        oSketch = oDrawingDoc.ActiveSheet.Sketches.Add
    
    ' Open the sketch for edit so the text boxes can be created.
    ' This is only required for drawing sketches, not part.
    oSketch.Edit
    
    Dim oTG As TransientGeometry
        oTG = ThisApplication.TransientGeometry
        
' Se define el texto y posiciona el texto Medidas de corte
Dim sText1 As String     


    sText1 ="Medidas de corte "
    Dim oTextBox1 As inventor.TextBox
        oTextBox1 = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(36, 24), sText1)
        
' Se define y posiciona el texto con los valores de bloque
  
Dim sText As String     


    sText =" X "& medidaenx & "  Y" & medidaeny & "  Z" & medidaenz
    Dim oTextBox As inventor.TextBox
        oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(36, 23), sText)
' Se define y pocisiona el texto con el nombre del archivo   
    Dim oTextbox2 As inventor.Textbox
        oTextbox2 = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(9, 26), name)


' Se da formato a los textos
oTextbox.Formattedtext = "<StyleOverride FontSize='" & .4 & "'>" _
& oTextbox.Text & "</StyleOverride>"
oTextbox1.Formattedtext = "<StyleOverride FontSize='" & .4 & "'>" _
& oTextbox1.Text & "</StyleOverride>"
oTextbox2.Formattedtext = "<StyleOverride FontSize='" & .4 & "'>" _
& oTextbox2.Text & "</StyleOverride>"

' Se posicionan las vistas


    
oBaseView = oSheet.DrawingViews.AddBaseView(oPartDoc,oPoint1, ViewScale,kFrontViewOrientation, kHiddenLineDrawingViewStyle, "My View")
oView2 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint2, kHiddenLineDrawingViewStyle, ViewScale)
oView3 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint3, kHiddenLineDrawingViewStyle, ViewScale)  
oView4 = oSheet.DrawingViews.AddProjectedView(oBaseView,oPoint4, kHiddenLineDrawingViewStyle, (ViewScale/1.15))  

' Se cierra el Sketch
oSketch.ExitEdit

 

0 Likes
Message 12 of 12

Luis_Pacheco_3D
Advocate
Advocate

hi @JelteDeJong , i found this code in your webpage, this works.
but i would like when the rule generate the dimension, add a text.
see image:

luispacheco6P5Y8_0-1665679368976.png

 

 

i´ve been trying for a several days, but i could not do it. Can you help me? Than you.

0 Likes