HoleThreadNotes.Add Method

HoleThreadNotes.Add Method

ralfmja
Advocate Advocate
263 Views
2 Replies
Message 1 of 3

HoleThreadNotes.Add Method

ralfmja
Advocate
Advocate

Hi,

 

I want to get the thread dimension on the section as shown in the screenshot below. 

wymiar OK.png

To achieve this, based on the description, I need to:

Opis help.png

Add True as a parameter for "Linear Diameter Type", but I don't understand what I should indicate as HoleOrThreadEdge in this case? Diameter ?? which line and how do that ??

My code looks like this:

Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
Dim oView As DrawingView = Nothing
Dim oDoc As PartDocument

' Tworzenie kolekcji dla różnych typów otworów
Dim oColCounterBore As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oColCounterSink As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oColDrilled As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oColTapped As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

' Przeszukiwanie widoków, aby znaleźć oView o typie kDrawingSectionView
For Each tempView As DrawingView In oSheet.DrawingViews
    If tempView.ViewType = kSectionDrawingViewType Then
        oView = tempView
        Exit For
    End If
Next

If oView IsNot Nothing Then
    oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

   ' Przeszukiwanie wszystkich otworów w dokumencie części
For Each oHoleFeature As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures
    For Each oFace As Face In oHoleFeature.Faces
        If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
            For Each oCurve As DrawingCurve In oView.DrawingCurves
                If oCurve.ModelGeometry Is oFace Then
                    ' Najpierw sprawdzenie, czy otwór jest gwintowany
                    If oHoleFeature.Tapped Then
                        oColTapped.Add(oCurve)
                    Else
                        ' Jeżeli nie jest gwintowany, klasyfikujemy według typu
                        Select Case oHoleFeature.HoleType
                            Case kCounterBoreHole
                                oColCounterBore.Add(oCurve)
                            Case kCounterSinkHole
                                oColCounterSink.Add(oCurve)
                            Case kDrilledHole
                                oColDrilled.Add(oCurve)
                        End Select
                    End If
                End If
            Next
        End If
    Next
Next

' Wyświetlenie liczby krawędzi gwintowanych
MsgBox("Liczba krawędzi gwintowanych: " & oColTapped.Count.ToString())

    ' Tutaj możesz kontynuować działania dla poszczególnych kolekcji, na przykład:
    ' - Wymiarowanie otworów kDrilledHole jak wcześniej.
    ' - Dodatkowe operacje dla innych typów otworów.
     ' Dodawanie notatki dla krawędzi gwintów
    Dim i As Integer
	For i = 1 To oColTapped.Count - 1 Step 2 ' -2, ponieważ korzystamy z i oraz i+1
   
	Dim oThreadCurve As DrawingCurve = oColTapped.Item(i)
    Dim nextThreadCurve As DrawingCurve = oColTapped.Item(i + 1)

    Dim oIntent As GeometryIntent = oSheet.CreateGeometryIntent(oThreadCurve)
	Dim oIntent12 As GeometryIntent = oSheet.CreateGeometryIntent(nextThreadCurve)
	
    Dim notePosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d((oThreadCurve.MidPoint.X+nextThreadCurve.MidPoint.X)/2, oView.Top + 1)
    
    Dim oNote As HoleThreadNote = oSheet.DrawingNotes.HoleThreadNotes.Add(notePosition, oIntent)
	
	Next

	
    ' Dla przykładu, wymiarowanie otworów kDrilledHole:
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
    If oColDrilled.Count >= 2 Then
        For i = 1 To oColDrilled.Count - 1 Step 2
            Dim oDim As DrawingDimension
            Dim oIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oColDrilled(i))
            Dim oIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oColDrilled(i + 1))

            Dim oCurve1 As DrawingCurve = oColDrilled(i)
            Dim oCurve2 As DrawingCurve = oColDrilled(i + 1)

            Dim midPointX As Double = (oCurve1.StartPoint.X + oCurve1.EndPoint.X + oCurve2.StartPoint.X + oCurve2.EndPoint.X) / 4
            Dim midPointY As Double = (oCurve1.StartPoint.Y + oCurve1.EndPoint.Y + oCurve2.StartPoint.Y + oCurve2.EndPoint.Y) / 4

            Dim midPoint As Point2d = oTG.CreatePoint2d(midPointX, midPointY + 1)

            oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(midPoint, oIntent1, oIntent2, DimensionTypeEnum.kAlignedDimensionType)
        Next
    End If

Else
    MsgBox("Nie znaleziono widoku przekroju.")
End If

And the result of its execution is either adding a dimension as shown below:

wymiar NOK.png

Or (when Linear Diameter Type = true Line66) an error as in the screenshot below:

blad_przekrój.png

Can someone tell me what I'm doing wrong and what should I change??

 

Regards,

ralfmja

Accepted solutions (1)
264 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Hi @ralfmja 

 

A quick check with a manual selected curve shows the Add note worked so the challenge was to figure out why the code wasn't selecting the projected curve of the threaded hole. 

AAcheson_0-1696563483337.png

 

 

	    '[Manually select cuve to test Method
		Dim curveSegment As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a Line")
		Dim curve As DrawingCurve = curveSegment.Parent
	 	Dim oNote As HoleThreadNote = oSheet.DrawingNotes.HoleThreadNotes.Add(notePosition, curve,True)
		']

 

It turns out that filtering only for object type of face object was the issue. The correct type is an edge type object and this will allow the linear dim style to be shown.

AAcheson_1-1696563959076.png

Logger.Info("AllObjects: " & oCurve.ModelGeometry.Type.ToString)
               'If oCurve.ModelGeometry Is oFace Then                 '******************** Object Type Face
					'Logger.Info("FaceTypeObject: " & oCurve.ModelGeometry.Type.ToString)
				If oCurve.ModelGeometry.Type = ObjectTypeEnum.kEdgeObject Then '******************** Object Type Edge
					Logger.Info("EdgeTypeObject: " & oCurve.ModelGeometry.Type.ToString)

Working Rule

Dim oSheet As Sheet = ThisApplication.ActiveDocument.ActiveSheet
Dim oView As DrawingView = Nothing
Dim oDoc As PartDocument

' Tworzenie kolekcji dla różnych typów otworów
Dim oColCounterBore As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oColCounterSink As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oColDrilled As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim oColTapped As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

' Przeszukiwanie widoków, aby znaleźć oView o typie kDrawingSectionView
For Each tempView As DrawingView In oSheet.DrawingViews
    If tempView.ViewType = kSectionDrawingViewType Then
        oView = tempView
        Exit For
    End If
Next

If oView IsNot Nothing Then
    oDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

   ' Przeszukiwanie wszystkich otworów w dokumencie części
For Each oHoleFeature As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures
    For Each oFace As Face In oHoleFeature.Faces
        If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
            For Each oCurve As DrawingCurve In oView.DrawingCurves
				Logger.Info("AllObjects: " & oCurve.ModelGeometry.Type.ToString)
               'If oCurve.ModelGeometry Is oFace Then                 '******************** Object Type Face
					'Logger.Info("FaceTypeObject: " & oCurve.ModelGeometry.Type.ToString)
				If oCurve.ModelGeometry.Type = ObjectTypeEnum.kEdgeObject Then '******************** Object Type Edge
					Logger.Info("EdgeTypeObject: " & oCurve.ModelGeometry.Type.ToString)
                    ' Najpierw sprawdzenie, czy otwór jest gwintowany
                    If oHoleFeature.Tapped Then
                        oColTapped.Add(oCurve)
                    Else
                        ' Jeżeli nie jest gwintowany, klasyfikujemy według typu
                        Select Case oHoleFeature.HoleType
                            Case kCounterBoreHole
                                oColCounterBore.Add(oCurve)
                            Case kCounterSinkHole
                                oColCounterSink.Add(oCurve)
                            Case kDrilledHole
                                oColDrilled.Add(oCurve)
                        End Select
                    End If
                End If
            Next
        End If
    Next
Next

' Wyświetlenie liczby krawędzi gwintowanych
MsgBox("Liczba krawędzi gwintowanych: " & oColTapped.Count.ToString())

    ' Tutaj możesz kontynuować działania dla poszczególnych kolekcji, na przykład:
    ' - Wymiarowanie otworów kDrilledHole jak wcześniej.
    ' - Dodatkowe operacje dla innych typów otworów.
     ' Dodawanie notatki dla krawędzi gwintów
    Dim i As Integer
	For i = 1 To oColTapped.Count - 1 Step 2 ' -2, ponieważ korzystamy z i oraz i+1
   
		Dim oThreadCurve As DrawingCurve = oColTapped.Item(i)
	    Dim nextThreadCurve As DrawingCurve = oColTapped.Item(i + 1)

	    Dim oIntent As GeometryIntent = oSheet.CreateGeometryIntent(oThreadCurve)
		Dim oIntent12 As GeometryIntent = oSheet.CreateGeometryIntent(nextThreadCurve)
		
	    Dim notePosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d((oThreadCurve.MidPoint.X+nextThreadCurve.MidPoint.X)/2, oView.Top + 1)
	    '[Manually select cuve to test Method
		'Dim curveSegment As DrawingCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a Line")
		'Dim curve As DrawingCurve = curveSegment.Parent
	 	'Dim oNote As HoleThreadNote = oSheet.DrawingNotes.HoleThreadNotes.Add(notePosition, curve,True)
		']
	    Try
			Dim oNote As HoleThreadNote = oSheet.DrawingNotes.HoleThreadNotes.Add(notePosition, oIntent, True)
		Catch
			MessageBox.Show("Error adding Note","iLogic")
		End Try
	
	Next

	
    ' Dla przykładu, wymiarowanie otworów kDrilledHole:
    Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
    If oColDrilled.Count >= 2 Then
        For i = 1 To oColDrilled.Count - 1 Step 2
            Dim oDim As DrawingDimension
            Dim oIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oColDrilled(i))
            Dim oIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oColDrilled(i + 1))

            Dim oCurve1 As DrawingCurve = oColDrilled(i)
            Dim oCurve2 As DrawingCurve = oColDrilled(i + 1)

            Dim midPointX As Double = (oCurve1.StartPoint.X + oCurve1.EndPoint.X + oCurve2.StartPoint.X + oCurve2.EndPoint.X) / 4
            Dim midPointY As Double = (oCurve1.StartPoint.Y + oCurve1.EndPoint.Y + oCurve2.StartPoint.Y + oCurve2.EndPoint.Y) / 4

            Dim midPoint As Point2d = oTG.CreatePoint2d(midPointX, midPointY + 1)

            oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(midPoint, oIntent1, oIntent2, DimensionTypeEnum.kAlignedDimensionType)
        Next
    End If

Else
    MsgBox("Nie znaleziono widoku przekroju.")
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3

ralfmja
Advocate
Advocate

Hi @A.Acheson ,

 

Thanks 🙂

 

Regards,

ralfmja

0 Likes