Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Center Point of Arc or Circle

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
RoyWickrama_RWEI
885 Views, 4 Replies

Center Point of Arc or Circle

This rule shown below was working well (several times) last night.

Today morning, it keeps giving me an error message: Could someone help me, please.

Pop Up.png

 

Imports System.Windows.Forms


Sub Main()
'https://forums.autodesk.com/t5/inventor-customization/ilogic-move-body-from-point-to-coordinate/td-p/8222376
'https://forums.autodesk.com/t5/inventor-customization/selectionfilterenum-enumerator-for-center-of-arc-or-circle/m-p/8556328
'Dim myPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Select Point to set as origin:")

Dim iLNO As String = "0004"
Clipboard.SetText("TEST")
oDoc = ThisApplication.ActiveDocument
oCompDef = oDoc.ComponentDefinition

oMidX = 0
oMidY = 0
oMidZ = 0
oSV = "Single Vertex"
oMP = "Middle Point"
oCP = "Center point of Arc or Circle"
oCancel = "Cancel"


Dim oPoint_Type As New ArrayList
'oPoint_Type.Add(oSV)
'oPoint_Type.Add(oMP)
oPoint_Type.Add(oCP)
oPoint_Type.Add(oCancel)

oCP_Other_Y = "Yes"
oCP_Other_N = "No"
oCP_Other_YN = oCP_Other_Y
oPoint_Type_X = InputListBox("Prompt", oPoint_Type, oPoint_Type(0), Title := iLNO & ": Options", ListName := iLNO & ": List")
If oPoint_Type_X = oCP Then oCP_Other_YN = oCP_Other_N
If oPoint_Type_X = oCancel Then Exit Sub
If oPoint_Type_X = "Middle Point" Then
	oIterate = 2
	oDivider = 2
Else
	oIterate = 1
	oDivider = 1
End If

For i = 1 To oIterate
If i = 1 Then oTitle_MP = "Select Point(Vertex) - 1st"
If i = 2 Then oTitle_MP = "Select Point(Vertex) - 2nd"
	
'Dim oPoint_SV = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Select a Point (vertex)")
'Dim oPoint_MP = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, oTitle_MP)
'Dim oArc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllCircularEntities, "Select a Center Point (Arc or Circle)")
L_oPoint:

If oPoint_Type_X = oSV Then
	Dim oPoint_SV = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, "Select a Point (vertex)")
	oPoint = oPoint_SV
Else If oPoint_Type_X = oMP Then
	Dim oPoint_MP = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPointEntities, oTitle_MP)
	oPoint = oPoint_MP
End If

If oCP_Other_YN = oCP_Other_Y Then
	If IsNothing(oPoint) Then GoTo L_oPoint:
End If

If oPoint_Type_X = oCP Then
	oPoint_Str = oCP_Sub()
	'specify word splitting characters "space" and "dash"
	Dim Separators() As Char = {","c} 
	Sentence = oPoint_Str
	Words = Sentence.Split(Separators)
	i = 0
	For Each wrd In Words
'	MessageBox.Show("Word Index #" & i & " = " & Words(i))
	i += 1
	Next
	oMidX = Val(Words(0))/2.54
	oMidY = Val(Words(1))/2.54
	oMidZ = Val(Words(2))/2.54
End If
	
If oCP_Other_YN = oCP_Other_Y Then
	myPoint = oPoint.Point
	oMidX = (myPoint.X/2.54 + oMidX)
	oMidY = (myPoint.Y/2.54 + oMidY)
	oMidZ = (myPoint.Z/2.54 + oMidZ)
End If

Next i

oMidX = oMidX / oDivider
oMidY = oMidY / oDivider
oMidZ = oMidZ / oDivider
oWP_Cordinates = oMidX.ToString & " " & oMidY.ToString & " " & oMidZ.ToString

'____Create and write to a text file_________________
oWrite = System.IO.File.CreateText(ThisDoc.PathAndFileName(False) & ".txt")
oWrite.WriteLine("oMidX: " & oMidX)
oWrite.WriteLine("oMidY: " & oMidY)
oWrite.WriteLine("oMidZ: " & oMidZ)
oWrite.WriteLine(oMidX & " " & oMidY & " " & oMidZ)
oWrite.WriteLine(oWP_Cordinates)
oWrite.Close()

'open the file
ThisDoc.Launch(ThisDoc.PathAndFileName(False) & ".txt")
ThisApplication.ActiveView.Fit

oCreateWP(oMidX,oMidY,oMidZ)

oClipboard = CStr(oMidX) & "," & CStr(oMidY) & "," & CStr(oMidZ)
Clipboard.SetText(oClipboard)

End Sub

Sub oCreateWP(oMidX, oMidY, oMidZ)
oUCF = 2.54
oMidX = oMidX*oUCF
oMidY = oMidY*oUCF
oMidZ = oMidZ*oUCF

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oWorkPoint As WorkPoint

'create a workpoint
oWorkPoint = oDoc.ComponentDefinition.WorkPoints.AddFixed(oTG.CreatePoint(oMidX,oMidY,oMidZ))
'display the new workpoint's coordinates
MessageBox.Show(oWorkPoint.Point.X/2.54  &", "&  oWorkPoint.Point.Y/2.54 &", "&  oWorkPoint.Point.Z/2.54, "@ SUB oCreateWP")

End Sub

Sub oAssign_from_Clipboard()
  Dim Len_Max As Double
  Len_Max = Convert.ToDouble(Clipboard.GetText)	'To assgn clipboard value (numerical) to the variable
  Dim oMfgr As String
  oMfgr = Clipboard.GetText		'To assgn clipboard value (string) to the variable

End Sub



Function oCP_Sub()		'rivate Sub TestGetCenter()
'Function oCP_Sub(oArc)	
'https://forums.autodesk.com/t5/inventor-customization/find-center-point-coordinate-of-arc-or-circle/td-p/2630752
Dim GetCenterPoint As Point
Count_NotSelected = 0

L_oArc :

Dim InputEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllCircularEntities, "Select a Point (vertex):") 

If InputEdge Is Nothing Then
	Count_NotSelected += 1
	If Count_NotSelected > 3 Then	'To help if no crcular features to select
		Exit Function
	Else
		GoTo L_oArc :
	End If
End If

'prop = customPropertySet.Item(oCustiProperties_Array.Item(i))

Select Case InputEdge.GeometryType
Case kCircularArcCurve
	Dim arc As Arc3d
	arc = InputEdge.Geometry
	GetCenterPoint = arc.Center
Case kCircleCurve
	Dim circ As Inventor.Circle
	circ = InputEdge.Geometry
	GetCenterPoint = circ.Center
Case kEllipticalArcCurve
	Dim ellipArc As EllipticalArc
	ellipArc = InputEdge.Geometry
	GetCenterPoint = ellipArc.Center
Case kEllipseFullCurve
	Dim ellipse As EllipseFull
	ellipse = InputEdge.Geometry
	GetCenterPoint = ellipse.Center
Case Else
	GetCenterPoint = Nothing
End Select

MessageBox.Show("@ end of Function oCP_Sub", "Title")

MsgBox("Center @ oCP_Sub: " & GetCenterPoint.X/2.54 & ", " & GetCenterPoint.Y/2.54 & ", " & GetCenterPoint.Z/2.54)
Return (GetCenterPoint.X & "," & GetCenterPoint.Y & "," & GetCenterPoint.Z)
End Function
4 REPLIES 4
Message 2 of 5
JaneFan
in reply to: RoyWickrama_RWEI

Hi @RoyWickrama_RWEI, I can't see anything wrong in the rule, and it can run without error. Is there error still reproducible even after you restart inventor?



Jane Fan
Inventor QA Engineer
Message 3 of 5
RoyWickrama_RWEI
in reply to: JaneFan

Thanks for the reply. It works well (always) on my Inventor 2019 Professional home office installation.

But, at another location using Inventor 2018 Professional, it keeps giving me the error always. STILL THE SAME with this 2018 installation.

 

Same for the following rule (works in 2019, but not in 2018). Could you reply with comments.

 

Sub Main()		'rivate Sub TestGetCenter()
iLNO = "0005PA"
'https://forums.autodesk.com/t5/inventor-customization/find-center-point-coordinate-of-arc-or-circle/td-p/2630752
Dim oCenter As Point
Count_NotSelected = 0

L_oArc:
Dim InputEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllCircularEntities, "Select a Point (vertex):")

If InputEdge Is Nothing Then
	Count_NotSelected += 1
	If Count_NotSelected > 3 Then	'To help if no crcular features to select
		Exit Sub
	Else
		GoTo L_oArc :
	End If
End If

Select Case InputEdge.GeometryType
Case kCircularArcCurve
	MessageBox.Show("Message1", "Title")
	Dim arc As Arc3d
	arc = InputEdge.Geometry
	GetCenterPoint = arc.Center
Case kCircleCurve
	MessageBox.Show("Message2", "Title")
	Dim circ As Inventor.Circle
	circ = InputEdge.Geometry
	GetCenterPoint = circ.Center
Case kEllipticalArcCurve
	MessageBox.Show("Message3", "Title")
	Dim ellipArc As EllipticalArc
	ellipArc = InputEdge.Geometry
	GetCenterPoint = ellipArc.Center
Case kEllipseFullCurve
	MessageBox.Show("Message4", "Title")
	Dim ellipse As EllipseFull
	ellipse = InputEdge.Geometry
	GetCenterPoint = ellipse.Center
Case Else
	MessageBox.Show("Message5", "Title")
	GetCenterPoint = Nothing
End Select
oCenter = GetCenterPoint
MsgBox ("Center: " & oCenter.X & ", " & oCenter.Y & ", " & oCenter.Z)
End Sub

 

 

Message 4 of 5
JaneFan
in reply to: RoyWickrama_RWEI

Hey @RoyWickrama_RWEI , 

 

I see the reason now. It can be solved by adding the enum type before the value. Without adding the enum type, we can see it always went to case else and GetCenterPoint  is always nothing in inventor 2018, so that error happens when trying to output its X, Y and Z using Msgbox().
It is safe and recommended to add enum type in front anytime using enum value. Please update code like this:

Sub Main()		'rivate Sub TestGetCenter()
iLNO = "0005PA"
'https://forums.autodesk.com/t5/inventor-customization/find-center-point-coordinate-of-arc-or-circle/td-p/2630752
Dim oCenter As Point
Count_NotSelected = 0

L_oArc:
Dim InputEdge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllCircularEntities, "Select a Point (vertex):")

If InputEdge Is Nothing Then
	Count_NotSelected += 1
	If Count_NotSelected > 3 Then	'To help if no crcular features to select
		Exit Sub
	Else
		GoTo L_oArc :
	End If
End If

Select Case InputEdge.GeometryType
Case CurveTypeEnum.kCircularArcCurve
	MessageBox.Show("Message1", "Title")
	Dim arc As Arc3d
	arc = InputEdge.Geometry
	GetCenterPoint = arc.Center
Case CurveTypeEnum.kCircleCurve
	MessageBox.Show("Message2", "Title")
	Dim circ As Inventor.Circle
	circ = InputEdge.Geometry
	GetCenterPoint = circ.Center
Case CurveTypeEnum.kEllipticalArcCurve
	MessageBox.Show("Message3", "Title")
	Dim ellipArc As EllipticalArc
	ellipArc = InputEdge.Geometry
	GetCenterPoint = ellipArc.Center
Case CurveTypeEnum.kEllipseFullCurve
	MessageBox.Show("Message4", "Title")
	Dim ellipse As EllipseFull
	ellipse = InputEdge.Geometry
	GetCenterPoint = ellipse.Center
Case Else
	MessageBox.Show("Message5", "Title")
	GetCenterPoint = Nothing
End Select
oCenter = GetCenterPoint
If Not oCenter Is Nothing Then 
	MsgBox ("Center: " & oCenter.X.ToString() & ", " & oCenter.Y.ToString() & ", " & oCenter.Z.ToString())
End If 
End Sub  

 




Jane Fan
Inventor QA Engineer
Message 5 of 5
RoyWickrama_RWEI
in reply to: JaneFan

Thanks a lot. Great fix. It is working on my 2018 installation as well. 

I will continue to build up the main rule and add more functionality (e.g. to pick more points, ..)

 

Again, THANKS.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report