How to get coordinates of a WorkPoint

How to get coordinates of a WorkPoint

anavazquez5LRNJ
Enthusiast Enthusiast
386 Views
5 Replies
Message 1 of 6

How to get coordinates of a WorkPoint

anavazquez5LRNJ
Enthusiast
Enthusiast

Get coordinates of a WorkPoint that is located on an assembly component within a view of a drawing.

I have an assembly inside a view in a drawing, this assembly has n number of components, each one of these has a WorkPoint (the WorkPoint is called the same in all the components of the assembly and the only thing that changes is the name of the parent component), what I want is to know if with the name of the component and the name of the WorkPoint you can have the coordinates of each one of the WorkPoint when you select a component.

 

0 Likes
387 Views
5 Replies
Replies (5)
Message 2 of 6

FINET_Laurent
Advisor
Advisor

Hi @anavazquez5LRNJ,


ASSUMING the active document is a drawing document, that the correct sheet is active, that there is only one view, that the said workpoint (here named 1) is present in every part, also asuming the view is made from an assembly model that contains only parts, HERE is a small code that does the job :

Dim doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim v As Inventor.DrawingView = doc.ActiveSheet.DrawingViews.Item(1)

Dim refdoc As Inventor.Document = v.ReferencedDocumentDescriptor.ReferencedDocument	
Dim def As Inventor.AssemblyComponentDefinition = refdoc.ComponentDefinition

For Each occ As Inventor.ComponentOccurrence In def.Occurrences
	Dim occDoc As Inventor.Document = occ.ReferencedDocumentDescriptor.ReferencedDocument	
	Dim name As String = occDoc.DisplayName
	
	Dim occDef As Inventor.ComponentDefinition = occDoc.ComponentDefinition
	
	Dim wp As Inventor.WorkPoint = occDef.WorkPoints.Item("1")
	MsgBox(name & " : " & wp.Point.X & " / " & wp.Point.Y & " / " & wp.Point.Z)
	
Next

Does this suits your needs ?

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 6

Michael.Navara
Advisor
Advisor

You need to specify what is the coordinates of workpoint. Here is the sample how to obtain them

 

 

Sub Main

	Dim drawingDocument As DrawingDocument = ThisDoc.Document
	oSheet = drawingDocument.Sheets(1)
	oDrawingView = oSheet.DrawingViews(1)

	Dim asm As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument

	'Get WorkPoints in assembly context
	ProcessOccurrences(asm.ComponentDefinition.Occurrences.OfType(Of ComponentOccurrence))

End Sub

Private oSheet As Sheet
Private oDrawingView As DrawingView

Sub ProcessOccurrences(occurrences As IEnumerable(Of ComponentOccurrence))
	For Each occ As ComponentOccurrence In occurrences
		Dim occWorkPoints As WorkPoints = GetWorkPoints(occ)
		If occWorkPoints Is Nothing Then Continue For

		Logger.Debug(occ.Name)
		For Each occWorkPoint As WorkPoint In occWorkPoints
			Logger.Debug(" {0}", occWorkPoint.Name)

			'Occurrence local coordinate system
			Logger.Debug("{1}Local coords: {0}", PointCoords(occWorkPoint.Point), "  ")

			'Assembly coordinate system
			Dim occWorkPointProxyObj As Object
			occ.CreateGeometryProxy(occWorkPoint, occWorkPointProxyObj)
			Dim occWorkPointProxy = TryCast(occWorkPointProxyObj, WorkPointProxy)
			Logger.Debug("{1}Assembly coords: {0}", PointCoords(occWorkPointProxy.Point), "  ")


			'Drawing sheet coordinate system
			Dim sheetPoint = oDrawingView.ModelToSheetSpace(occWorkPointProxy.Point)
			Logger.Debug("{1}Sheet coords: {0}", PointCoords(sheetPoint), "  ")

			'Drawing sheet coordinate system
			Dim drawingViewPoint = oDrawingView.ModelToDrawingViewSpace(occWorkPointProxy.Point)
			Logger.Debug("{1}View coords: {0}", PointCoords(drawingViewPoint), "  ")

		Next

		If occ.SubOccurrences.Count > 0 Then
			ProcessOccurrences(occ.SubOccurrences.OfType(Of ComponentOccurrence))
		End If


	Next

End Sub



Function GetWorkPoints(occ As ComponentOccurrence) As WorkPoints
	Dim asmDef As AssemblyComponentDefinition = TryCast(occ.Definition, AssemblyComponentDefinition)
	If Not asmDef Is Nothing Then Return asmDef.WorkPoints

	Dim prtDef As PartComponentDefinition = TryCast(occ.Definition, PartComponentDefinition)
	If Not prtDef Is Nothing Then Return prtDef.WorkPoints

	Return Nothing
End Function

Function PointCoords(pt As Point) As String
	Return String.Format("[{0:N2}, {1:N2}, {2:N2}]", pt.X, pt.Y, pt.Z)

End Function

Function PointCoords(pt As Point2d) As String
	Return String.Format("[{0:N2}, {1:N2}]", pt.X, pt.Y)
End Function

 

 

Message 4 of 6

anavazquez5LRNJ
Enthusiast
Enthusiast

Thank you very much @Michael.Navara @FINET_Laurent , I tried it in a separate iLogic rule, and it works fine, I just don't know how to implement it in my code.

0 Likes
Message 5 of 6

Michael.Navara
Advisor
Advisor

 We can help you, but you need to describe what do you want to do with point coordinates and which are relevant for your needs. In my code on lines 27, 33, 38 and 42 I have a relevant point objects which are useful for anything you want.

0 Likes
Message 6 of 6

anavazquez5LRNJ
Enthusiast
Enthusiast

Hi @Michael.Navara ,

With the WorkPoint coordinates I want to distinguish where the occurrence is that is selected (right, left, up and down), but I still don't know very well how to implement it in my code when I tried, I couldn't make it work.

 

 

0 Likes