Need Assistance with gathering Workpoints from an Assembly

Need Assistance with gathering Workpoints from an Assembly

W_Barnett
Enthusiast Enthusiast
376 Views
3 Replies
Message 1 of 4

Need Assistance with gathering Workpoints from an Assembly

W_Barnett
Enthusiast
Enthusiast

For starters, here's the code:

Private Function FindPoints(oView As DrawingView, dimPoint As String)
	Dim oAssyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim occ As Object
	Dim oDef As Document = Nothing
	
	For Each oOcc As ComponentOccurrence In oAssyDoc.ComponentDefinition.Occurrences
		oDef = oOcc.Definition.Document
		For Each oWorkpoint As WorkPoint In oDef.ComponentDefinition.WorkPoints
			If oWorkpoint.Name = dimPoint Then
				occ = oOcc
			End If
		Next
	Next
	Return occ
End Function

Essentially, oView is pointing to a targeted Section View (it's created this way so I could use the same code to target other drawing views if I need), and dimPoint is passing off the name of a Workpoint in the Assembly to try and target.  I'm iterating through a list of names by calling this function in a FOR loop:

 

Dim wpNames As New List(Of String) From {"WP_1", "WP_1-1", "WP_1-2", "WP_2", "WP_2-1", "WP_3", "WP_4" }
Dim oOcc(wpNames.Count - 1) As Object 
	
For i As Integer = 1 To wpNames.Count
	oOcc(i-1) = FindPoints(iView, wpNames(i))
Next i   

 The FindPoints code is supposed to reference the assembly used in my Section View, iterate through all of the workpoints listed in the referenced assembly, and if it matches up to my provided name (dimPoint), return the Workpoint so I can collected in my oOcc variable.  This variable will be used to create dimensions down the road...however I can't get the iLogic code working correctly.

 

Here are my issues:

  1. The FOR Loop in my FindPoints function is not collecting any of my workpoints.  It collects 1 object called Center Point, however, the name doesn't match up to the name of the Center Point that I'm using in my assembly.
    1. How do I correctly collect all of my WorkPoints from the Assembly so that I can iterate through them?
  2. DimPoint should pass the String "WP_1" from the wpNames List, but it adds a "-1" behind it.  I checked this during debugging and found that prior to calling the FindPoints function, wpNames(0) returns the name "WP_1" correctly, but when checked inside the FindPoints function (i.e. directly after it's called), dimPoint returns "WP_1-1".  Any ideas as to why?
0 Likes
377 Views
3 Replies
Replies (3)
Message 2 of 4

basautomationservices
Advocate
Advocate

Hi William,

 

Your findpoints function is not returning any points because your setting the object occ to oOcc and not to oWorkpoint. Your function is returning occurrences. 

 

SEcond point is that lists are 0 index based. You'd be better off using a foreach loop to iterate through the list. If you don't want to, start your for loop at 0 instead of 1.

Contact me for custom app development info@basautomationservices.com. Follow below links to view my Inventor appstore apps.

Free apps: Smart Leader | Part Visibility Utility | Mate Origins

Paid apps: Frame Stiffener Tool | Constrain Plane Toggle | Property Editor Pro


0 Likes
Message 3 of 4

W_Barnett
Enthusiast
Enthusiast

Hey, thanks for the response.  I went back and really broke down the code.  Turns out I didn't need to gather all of the points like I thought I did.  I was originally trying to gather the points so that I could easily refer to them from a single variable, however it turns out, I needed to pretty much hardcode them in anyways.

 

For anyone that is looking to reference a named Workpoint in an Drawing View of an assembly, you just have to make sure that you reference the assembly used in whichever view you want and use the following code:

 

   Dim oAssyDoc As AssemblyDocument = oView.ReferencedDocumentDescriptor.ReferencedDocument 
Dim workPoints = oAssyDoc.ComponentDefinition.WorkPoints
'*** Create Workpoint Objects based dimPt Strings fed to function.
Dim oWP1 As WorkPoint
Dim oWP2 As WorkPoint
oWP1 = workPoints.Item(dimPt1

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @W_Barnett.  I don't know if you got it figured out yet or not, but here is some code you can test with and modify as needed.  I just used the Pick method to specify which view to work with for now.  Were all of those named WorkPoints created within the main assembly itself, and not down within any of the components or sub assemblies?  If any of the points are within components or sub assemblies, you will need a lot more code to dig down to them, and then you will have to deal with WorkPointProxy objects for those, instead of regular WorkPoints.

Sub Main
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	oSheet = oDDoc.ActiveSheet
	Dim oView As DrawingView = PickDrawingView
	Dim wpNames As New List(Of String) From {"WP_1", "WP_1-1", "WP_1-2", "WP_2", "WP_2-1", "WP_3", "WP_4"}
	Dim oWPoints As New List(Of WorkPoint)
	For Each wpName In wpNames
		Dim oNamedWPoint As WorkPoint = GetNamedWPoint(oView, wpName)
		If IsNothing(oNamedWPoint) Then
			MsgBox("Named WorkPoint Not Found.", , "")
		Else
			'MsgBox("Named WorkPoint Was Found.", , "")
			oWPoints.Add(oNamedWPoint)
		End If
	Next
	MsgBox("Found " & oWPoints.Count & " named WorkPoints.",,"")
End Sub

Function PickDrawingView(Optional oPrompt As String = vbNullString) As DrawingView
	If oPrompt = "" Then oPrompt = "Select a Drawing View."
	oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, oPrompt)
	If IsNothing(oObj) OrElse (TypeOf oObj Is DrawingView = False) Then Return Nothing
	Dim oView As DrawingView = oObj
	Return oView
End Function

Function GetNamedWPoint(oDView As DrawingView, oWPointName As String) As WorkPoint
	Dim oModelDoc As Document = oDView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oWPs As WorkPoints = oModelDoc.ComponentDefinition.WorkPoints
	For Each oWP As WorkPoint In oWPs
		If oWP.Name = oWPointName Then Return oWP
	Next
	Return Nothing 'it was not found
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes