Finding feature name from a view in an idw

Finding feature name from a view in an idw

MichaelLockhart3046
Participant Participant
513 Views
4 Replies
Message 1 of 5

Finding feature name from a view in an idw

MichaelLockhart3046
Participant
Participant

Hi all,

 

I've got iLogic code working such that I can loop through all the holes in my idw. I was wondering if there was a way to find the feature name of a specific hole in a drawing.

 

For example: This hole would tell you its part of the "Hole3" feature

MichaelLockhart3046_0-1628724232753.png

 

Any help would be appreciated

0 Likes
Accepted solutions (1)
514 Views
4 Replies
Replies (4)
Message 2 of 5

A.Acheson
Mentor
Mentor

Can you post the code your working with? 

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

MichaelLockhart3046
Participant
Participant
Sub Main()
	
	oDocument = ThisDoc.Document
	ShNum  = Mid(oDocument.ActiveSheet.Name, InStr(1, oDocument.ActiveSheet.Name, ":") + 1)

	Dim oDrawDoc As DrawingDocument
		oDrawDoc = ThisApplication.ActiveDocument

	Dim oSketch As DrawingSketch
		oSketch = oDrawDoc.ActiveSheet.Sketches.Add

	oSketch.Edit

	Dim oTG As TransientGeometry
		oTG = ThisApplication.TransientGeometry

	Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing View")
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oScale As Double = oView.Scale

	For Each oCurve As DrawingCurve In oView.DrawingCurves
		Try
			If oCurve.CurveType = kCircleCurve Then
				Dim oDia As Double = oCurve.Segments.Item(1).Geometry.Radius * 2 * 10 / oScale
				
				If IsEqual(oDia, 4)
					x = oCurve.CenterPoint.X
					y = oCurve.CenterPoint.Y
					txtbx = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(x-0.3, y + 0.35), "S12")
					txtbx.Style.FontSize = 0.23
					
				End If
				
			End If
		Catch
			'MsgBox("Error")
		End Try
	
	Next
	
	' Exit the sketch from the edit environment.
	oSketch.ExitEdit
	
End Sub

Function IsEqual(Value1 As Double, Value2 As Double, _
	Optional Tolerance As Double = 0.000001) As Boolean
	If Abs(Value1 - Value2) < Tolerance Then
		IsEqual = True
	Else
		IsEqual = False
	End If
End Function

 

I am trying to change the IsEqual function with matching a feature name instead

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @MichaelLockhart3046 

I don't know if you want the code to write the feature name in the holes or if you just want to compare the feature name to a string with your IsEqual-function. I've edited the code for both scenarios.

 

Write name of feature in hole:

Sub Main()


Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oSketch As DrawingSketch
oSketch = oDrawDoc.ActiveSheet.Sketches.Add

oSketch.Edit

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing View")
For Each oCurve As DrawingCurve In oView.DrawingCurves
	Try
		If oCurve.CurveType = kCircleCurve Then
			Dim oEdge As Edge = oCurve.ModelGeometry
			If oEdge IsNot Nothing
				For Each oFace As Face In oEdge.Faces
					If TypeOf (oFace.CreatedByFeature) Is HoleFeature
						x = oCurve.CenterPoint.X
						y = oCurve.CenterPoint.Y
						txtbx = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(x, y), oFace.CreatedByFeature.Name)
						txtbx.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
						txtbx.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
						txtbx.Style.FontSize = 0.23
					End If
				Next
			End If
		End If
	Catch
		'MsgBox("Error")
	End Try

Next

' Exit the sketch from the edit environment.
oSketch.ExitEdit

End Sub

Compare feature name to string with function:

Sub Main()


Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

Dim oSketch As DrawingSketch
oSketch = oDrawDoc.ActiveSheet.Sketches.Add

oSketch.Edit

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing View")

For Each oCurve As DrawingCurve In oView.DrawingCurves
	Try
		If oCurve.CurveType = kCircleCurve Then
			Dim oEdge As Edge = oCurve.ModelGeometry
			If oEdge IsNot Nothing
				If IsEqual(oEdge, "Hole1")
					x = oCurve.CenterPoint.X
					y = oCurve.CenterPoint.Y
					txtbx = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(x, y), "S12")
					txtbx.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
					txtbx.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
					txtbx.Style.FontSize = 0.23

				End If
			End If
		End If
	Catch
		'MsgBox("Error")
	End Try

Next

' Exit the sketch from the edit environment.
oSketch.ExitEdit

End Sub

Function IsEqual(oEdge As Edge, fName As String) As Boolean
	For Each oFace As Face In oEdge.Faces
		If oFace.CreatedByFeature.Name = fName Then Return True
	Next
	Return False
End Function

 

I hope one of them is what youre looking for 🙂

0 Likes
Message 5 of 5

MichaelLockhart3046
Participant
Participant

This is exactly what I needed! Works amazing, thanks