iLogic - Selection of workpoints for CSV export

iLogic - Selection of workpoints for CSV export

r.claus
Contributor Contributor
1,456 Views
17 Replies
Message 1 of 18

iLogic - Selection of workpoints for CSV export

r.claus
Contributor
Contributor


Hi everyone, I would be very grateful for your help. I was able to create the below rule for exporting workpoints.

 

  1. However, now I would like to export only certain group of workpoints created with a certain feature, for example "Rectangular Pattern Workpoints1". It should also be noted that the number of workpoints is always different, because we are working with a dynamic model. Therefore, the names of the workpoints cannot be used to differentiate between them. It would also be conceivable to set workpoints within a feature to invisible to be able to differentiate which workpoints are exported. Also, other possibilities for the selection of the workpoints, e.g., folders, can be suggested.

 

  1. Besides, the CSV file should always have the same size. So e.g., 100 columns, even if there are only 60 workpoints. Is this possible? The blanks can then be filled with a given value, e.g., "f".

Thank you very much for your support.

 

'Export Workpoints

Dim oDoc = ThisDoc.Document
Dim partDoc = ThisApplication.ActiveDocument
Dim partDef = partDoc.ComponentDefinition

Dim dlmtr As String = ";" 'or vbTab
Dim filePath As String
Dim fileName As String
Dim i As Integer

filePath = ThisDoc.Path & "\" 
fileName = "CSV Name" & " " & Number & ".csv"

expFile = System.IO.File.CreateText(filePath + fileName)

		expFile.Write("Name" & dlmtr)
	
For i = 1 To partDef.WorkPoints.Count

	If partDef.WorkPoints.Item(i).Visible = True
	expFile.Write(partDef.WorkPoints.Item(i).Name & dlmtr)
		Else expFile.Write("f" & dlmtr)
	End If
Next
	
		expFile.Write("Number" & dlmtr)
		expFile.Write("Customer" & dlmtr)
		expFile.Write("Type" & dlmtr)	
	
	expFile.Write(vbCrLf & "X" & dlmtr)		
			
For i = 1 To partDef.WorkPoints.Count
			
	If partDef.WorkPoints.Item(i).Visible = True Then
	expFile.Write(Round(partDef.WorkPoints.Item(i).Point.X * 10,1) & dlmtr)
		Else expFile.Write("f" & dlmtr)
	End If
Next

		expFile.Write(Number & dlmtr)
		expFile.Write(Customer & dlmtr)
		expFile.Write(Type & dlmtr)
				
	expFile.Write(vbCrLf & "Y" & dlmtr)
						
For i = 1 To partDef.WorkPoints.Count
			
	If partDef.WorkPoints.Item(i).Visible = True Then
	expFile.Write(Round(partDef.WorkPoints.Item(i).Point.Y * 10 -5,1) & dlmtr)
		Else expFile.Write("f" & dlmtr)
	End If
Next
			
	expFile.Write(vbCrLf & "Z" & dlmtr)

For i = 1 To partDef.WorkPoints.Count
	If partDef.WorkPoints.Item(i).Visible = True Then
	expFile.Write(Round(partDef.WorkPoints.Item(i).Point.Z * 10 -100,1) & dlmtr)
		Else expFile.Write("f" & dlmtr)
	End If	
Next

expFile.Close

ThisDoc.Launch(filePath + fileName)

 

0 Likes
Accepted solutions (1)
1,457 Views
17 Replies
Replies (17)
Message 2 of 18

Ralf_Krieg
Advisor
Advisor

Hello

 

Folders are until now not available in parts. So this option is not possible. Make all workpoints invisible that shall not be exported is possible, if you select nothing. Then all visible workpoints will be exported. In addition to the visibility, origins of (user) coordinate systems are excluded too.

If you select one or more workpoints or one or more patterns with workpoints or a combination of workpoints and patterns, it should export the selected points.

The file has always 100 columns now.

Maybe I missed some constellations.

 

 

 

 

Option Explicit on
Class ThisRule
	
	Private GetPoints As ObjectCollection

	Private Sub Main

	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oSelSet As SelectSet = oDoc.SelectSet

	If oSelSet.Count = 0 Then
	    If MsgBox ("Nothing selected, export all Workpoints?",MsgBoxStyle.YesNo ,"iLogic Export selected Workpoints to CSV") = vbNo Then
	    	Exit Sub
		Else
			Dim oWP As WorkPoint
			For Each oWP In oDoc.ComponentDefinition.WorkPoints
				oSelSet.Select(oWP)
			Next
		End If
	End If

	GetPoints = ThisApplication.TransientObjects.CreateObjectCollection

	Dim oSel As Object
	For Each oSel In oSelSet
	    Select Case oSel.Type
	        Case kRectangularPatternFeatureObject:
	            Call GetPointsRect(oSel)
	        Case kCircularPatternFeatureObject:
	            Call GetPointsCirc(oSel)
	        Case kWorkPointObject:
	            If oSel.Visible = True Then
	                If oSel.IsCoordinateSystemElement = False Then
	                    Call GetPoints.Add(oSel)
	                End If
	            End If
	        Case kBrowserFolderObject:  ' Nope, no folders in parts
	    End Select
	Next

	ExportWorkpoints(GetPoints)
	End Sub

	Private Sub GetPointsRect(ByVal oPatternFeature As RectangularPatternFeature)
	    
	    Dim i As Integer
	    Dim j As Integer
	    Dim oParentFeatures As ObjectCollection= oPatternFeature.ParentFeatures
	    
	    For i = 1 To oParentFeatures.Count
	        If TypeOf oParentFeatures(i) Is WorkPoint Then
	            If oParentFeatures(i).Visible = True Then
	                If oParentFeatures(i).IsCoordinateSystemElement = False Then
	                    Call GetPoints.Add(oParentFeatures(i))
	                End If
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                Call GetPointsRect(oParentFeatures(i))
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                Call GetPointsCirc(oParentFeatures(i))
	            End If
	        End If
	    Next
	    
	    Dim oPatternElements As FeaturePatternElements= oPatternFeature.PatternElements
	    For i = 1 To oPatternElements.Count
	        Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
	        If Not oResultFeatures Is Nothing Then
	            For j = 1 To oResultFeatures.Count
	                If TypeOf oResultFeatures(j) Is WorkPoint Then
	                    If oResultFeatures(j).Visible = True Then
	                        If oResultFeatures(j).IsCoordinateSystemElement = False Then
	                            Call GetPoints.Add(oResultFeatures(j))
	                        End If
	                    End If
	                End If
	            Next
	        End If
	    Next
	End Sub

	Private Sub GetPointsCirc(ByVal oPatternFeature As CircularPatternFeature)
	    
	    Dim i As Integer
	    Dim j As Integer
	    Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures
	    
	    For i = 1 To oParentFeatures.Count
	        If TypeOf oParentFeatures(i) Is WorkPoint Then
	            If oParentFeatures(i).Visible = True Then
	                If oParentFeatures(i).IsCoordinateSystemElement = False Then
	                    Call GetPoints.Add(oParentFeatures(i))
	                End If
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                Call GetPointsRect(oParentFeatures(i))
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                Call GetPointsCirc(oParentFeatures(i))
	            End If
	        End If
	    Next
	    
	    Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
	    For i = 1 To oPatternElements.Count
	        Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
	        If Not oResultFeatures Is Nothing Then
	            For j = 1 To oResultFeatures.Count
	                If TypeOf oResultFeatures(j) Is WorkPoint Then
	                    If oResultFeatures(j).Visible = True Then
	                        If oResultFeatures(j).IsCoordinateSystemElement = False Then
	                            Call GetPoints.Add(oResultFeatures(j))
	                        End If
	                    End If
	                End If
	            Next
	        End If
	    Next
	End Sub

	Private Sub ExportWorkpoints(ByVal oWorkPointColl As ObjectCollection)

		Dim oDoc = ThisDoc.Document
		Dim partDoc = ThisApplication.ActiveDocument
		Dim partDef = partDoc.ComponentDefinition

		Dim dlmtr As String = ";" 'or vbTab
		Dim filePath As String
		Dim fileName As String
		Dim i As Integer
		Dim j As Integer 

		filePath = ThisDoc.Path & "\" 
		fileName = "CSV Name" & " " & Number & ".csv"

		Dim expfile As System.IO.StreamWriter = System.IO.File.CreateText(filePath + fileName)

		Dim aFileData(3, 100) As String
		afiledata(0, 0) = "Name"
		afiledata(1, 0) = "X"
		afiledata(2, 0) = "Y"
		afiledata(3, 0) = "Z"

		For i = 1 To 100
			Try
				afiledata(0, i) = oWorkPointColl(i).Name
				afiledata(1, i) = Round(oWorkPointColl(i).Point.X * 10, 1)
				afiledata(2, i) = Round(oWorkPointColl(i).Point.Y * 10, 1)
				afiledata(3, i) = Round(oWorkPointColl(i).Point.Z * 10, 1)
			Catch
				afiledata(0, i) = "f"
				afiledata(1, i) = "f"
				afiledata(2, i) = "f"
				afiledata(3, i) = "f"
			End Try
		Next

		expfile.Write("Number" & dlmtr & Number & vbCrLf)
		expfile.Write("Customer" & dlmtr & Customer & vbCrLf)
		expfile.Write("Type" & dlmtr & Type & vbCrLf)	

		For i = 0 To 3
			For j = 0 To 100
				expfile.Write(afiledata(i,j) & dlmtr)
			Next
				expfile.Write(vbCrLf)
		Next

		expfile.Close

		ThisDoc.Launch(filePath + fileName)
		
	End Sub

End Class

 

 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 18

r.claus
Contributor
Contributor

Thank you very much for your help. Your code works very well.

Sorry, but I forgotten some information’s. It would be important that the workpoints do not always have to be selected manually. Is it possible to select certain patterns, e.g., pattern "Workpoints1" and pattern "Workpoints2" (and others) in the code? Besides the patterns, there are also some single workpoints to export. As an example: Workpoint_Head_1, Workpoint_Head_2, Workpoint_Head_3, Workpoint_Head_4 (and others). However, these have a fixed name and should line up behind the workpoints from the patterns.

Can the values "Number", "Customer" and "Type" also be set in the same row as the workpoints? Gladly at the beginning of the CSV file. In the first row the name and in the second the value.

Furthermore, the CSV must have a constant size and the blanks must be filled with "f".

Thanks again for your help. You really help me.

0 Likes
Message 4 of 18

r.claus
Contributor
Contributor

🙂

0 Likes
Message 5 of 18

Ralf_Krieg
Advisor
Advisor

Hello

 

You can create a multivalue fx-parameter named "WP_Export" and fill in the names of the workpoints and patterns. Or you comment out this line of code and use the hardcoded list above. As an alternative way, you can also select some workpoints/patterns and run the rule. Maybe this is useful for one time exports to avoid editing the standard list.

I've resorted Number, Customer and Type. Can you prove it is correct? Otherwise, can you sort the cells a needed in the CSV file and post a screenshot?

The CSV file always contains 100 columns for workpoint data. Empty columns will be filled with "f".

 

Option Explicit on
Class ThisRule
	
	Private GetPoints As ObjectCollection

	Private Sub Main
	
	'###################################################################################
	'###################################################################################
	' define the patternfeatures and/or workpoints here, use the name from model browser
'	Dim Features As New List(Of String) From { _
'	"WorkPoints1", _
'	"WorkPoints4", _
'	"Workpoint_Head_1", _
'	"Workpoint_Head_2", _
'	"Workpoint_Head_3", _
'	"Workpoint_Head_4" _
'	}
	
	
	' or define the patternfeatures and/or workpoints as a multivalue fx-parameter "WP_Export"
	' use the name from model browser
	Dim Features = MultiValue.List("WP_Export").Cast(Of String)().ToList()
	'###################################################################################
	'###################################################################################
	
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oSelSet As SelectSet = oDoc.SelectSet

	If oSelSet.Count = 0 Then
		' use the predefined list of named workpoints and features with workpoints
		' compare every rectangularpatternfeature, circularpatternfeature and workpoint
		' with all names Of the given list, if match add to selectset, remove mtached
		' item from list To shorten Next search
		Dim oRPF As RectangularPatternFeature
		Dim oCPF As CircularPatternFeature
		Dim oWP As WorkPoint
		For Each oRPF In oDoc.ComponentDefinition.Features.RectangularPatternFeatures
			If Features.Find(Function(x) x.ToUpper = oRPF.Name.ToUpper) IsNot Nothing Then
				oSelSet.Select(oRPF)
				Features.Remove(Features.Find(Function(x) x.ToUpper = oRPF.Name.ToUpper))
			End If
		Next
		For Each oCPF In oDoc.ComponentDefinition.Features.CircularPatternFeatures
			If Features.Find(Function(x) x.ToUpper = oCPF.Name.ToUpper) IsNot Nothing Then
				oSelSet.Select(oCPF)
				Features.Remove(Features.Find(Function(x) x.ToUpper = oCPF.Name.ToUpper))
			End If
		Next
		For Each oWP In oDoc.ComponentDefinition.WorkPoints 
			If Features.Find(Function(x) x.ToUpper = oWP.Name.ToUpper) IsNot Nothing Then
				oSelSet.Select(oWP)
				Features.Remove(Features.Find(Function(x) x.ToUpper = oWP.Name.ToUpper))
			End If
		Next
		' Features should now be empty
		If Features.Count>0 Then
			MsgBox("Features NOT empty.", MsgBoxStyle.Critical, "iLogic ExportWorkPoints")
			For Each item As String In Features
				Logger.Debug(item)
			Next
		End If
		
	End If

	GetPoints = ThisApplication.TransientObjects.CreateObjectCollection

	Dim oSel As Object
	For Each oSel In oSelSet
	    Select Case oSel.Type
	        Case kRectangularPatternFeatureObject:
	            Call GetPointsRect(oSel)
	        Case kCircularPatternFeatureObject:
	            Call GetPointsCirc(oSel)
	        Case kWorkPointObject:
	            If oSel.Visible = True Then
	                If oSel.IsCoordinateSystemElement = False Then
	                    Call GetPoints.Add(oSel)
	                End If
	            End If
	        Case kBrowserFolderObject:  ' Nope, no folders in parts
	    End Select
	Next

	oSelSet.Clear
	
	ExportWorkpoints(GetPoints)
	End Sub

	Private Sub GetPointsRect(ByVal oPatternFeature As RectangularPatternFeature)
	    
	    Dim i As Integer
	    Dim j As Integer
	    Dim oParentFeatures As ObjectCollection= oPatternFeature.ParentFeatures
	    
	    For i = 1 To oParentFeatures.Count
	        If TypeOf oParentFeatures(i) Is WorkPoint Then
	            If oParentFeatures(i).Visible = True Then
	                If oParentFeatures(i).IsCoordinateSystemElement = False Then
	                    GetPoints.Add(oParentFeatures(i))
	                End If
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsRect(oParentFeatures(i))
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsCirc(oParentFeatures(i))
	            End If
	        End If
	    Next
	    
	    Dim oPatternElements As FeaturePatternElements= oPatternFeature.PatternElements
	    For i = 1 To oPatternElements.Count
	        Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
	        If Not oResultFeatures Is Nothing Then
	            For j = 1 To oResultFeatures.Count
	                If TypeOf oResultFeatures(j) Is WorkPoint Then
	                    If oResultFeatures(j).Visible = True Then
	                        If oResultFeatures(j).IsCoordinateSystemElement = False Then
	                            GetPoints.Add(oResultFeatures(j))
	                        End If
	                    End If
	                End If
	            Next
	        End If
	    Next
	End Sub

	Private Sub GetPointsCirc(ByVal oPatternFeature As CircularPatternFeature)
	    
	    Dim i As Integer
	    Dim j As Integer
	    Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures
	    
	    For i = 1 To oParentFeatures.Count
	        If TypeOf oParentFeatures(i) Is WorkPoint Then
	            If oParentFeatures(i).Visible = True Then
	                If oParentFeatures(i).IsCoordinateSystemElement = False Then
	                    GetPoints.Add(oParentFeatures(i))
	                End If
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsRect(oParentFeatures(i))
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsCirc(oParentFeatures(i))
	            End If
	        End If
	    Next
	    
	    Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
	    For i = 1 To oPatternElements.Count
	        Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
	        If Not oResultFeatures Is Nothing Then
	            For j = 1 To oResultFeatures.Count
	                If TypeOf oResultFeatures(j) Is WorkPoint Then
	                    If oResultFeatures(j).Visible = True Then
	                        If oResultFeatures(j).IsCoordinateSystemElement = False Then
	                            GetPoints.Add(oResultFeatures(j))
	                        End If
	                    End If
	                End If
	            Next
	        End If
	    Next
	End Sub

	Private Sub ExportWorkpoints(ByVal oWorkPointColl As ObjectCollection)

		Dim partDoc = ThisApplication.ActiveDocument
		Dim partDef = partDoc.ComponentDefinition

		Dim dlmtr As String = ";" 'or vbTab
		Dim filePath As String
		Dim fileName As String
		Dim i As Integer
		Dim j As Integer 

		filePath = ThisDoc.Path & "\" 
		fileName = "CSV Name" & " " & ".csv"

		Dim expfile As System.IO.StreamWriter = System.IO.File.CreateText(filePath + fileName)

		Dim aFileData(3, 103) As String
		afiledata(0, 0) = "Number"
		afiledata(1, 0) = Number
		afiledata(0, 1) = "Customer"
		afiledata(1, 1) = Customer
		afiledata(0, 2) = "Type"
		afiledata(1, 2) = Type
		afiledata(0, 3) = "Name"
		afiledata(1, 3) = "X"
		afiledata(2, 3) = "Y"
		afiledata(3, 3) = "Z"

		For i = 4 To 103
			Try
				afiledata(0, i) = oWorkPointColl(i-3).Name
				afiledata(1, i) = Round(oWorkPointColl(i-3).Point.X * 10, 1)
				afiledata(2, i) = Round(oWorkPointColl(i-3).Point.Y * 10, 1)
				afiledata(3, i) = Round(oWorkPointColl(i-3).Point.Z * 10, 1)
			Catch
				afiledata(0, i) = "f"
				afiledata(1, i) = "f"
				afiledata(2, i) = "f"
				afiledata(3, i) = "f"
			End Try
		Next

		For i = 0 To 3
			For j = 0 To 103
				expfile.Write(afiledata(i,j) & dlmtr)
			Next
				expfile.Write(vbCrLf)
		Next

		expfile.Close

		ThisDoc.Launch(filePath + fileName)
		
	End Sub

End Class

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 6 of 18

r.claus
Contributor
Contributor
Thank you very much for your help. I am very grateful to you for that.

Your code works perfectly and also provides very good selection options. Great work.
The sorting of the cells is also correct.

Really super nice of you.
0 Likes
Message 7 of 18

r.claus
Contributor
Contributor

Hello,

unfortunately the requirements have changed a bit and I need your help again.

For a better overview I have attached a CSV file how the result should look like.

The individual workpoints and the patterns are to be exported one after the other at fixed positions. An assignment of the positions (i,j) of the individual workpoints and patterns should be possible. In addition, the workpoints in the pattern are to be numbered consecutively and thus have fixed names. The patterns have a maximum but different number of points. The number should be adjustable (in the code).

As an example:

4 to 20 single workpoints with selectable names

20 points in pattern 1

10 points in pattern 2

90 points in pattern 3

Important: If the selected workpoints (multivalue fx-parameter) are not visible or the value is empty, there should be an "f" instead of the value (X, Y, Z). So the points (column) should not be removed and the csv file must still have a constant size.

 

Maybe work with "oWorkPointColl" for each group of workpoints to distinguish them?


I hope you can help me for one more time?

Thank you very much again

0 Likes
Message 8 of 18

Ralf_Krieg
Advisor
Advisor

Hello

 

I need to think about it a bit. I have some questions.

1. You said 4 to 20 single workpoints. If the output file should always had a constant count of columns, we must always take 20 and fill the empty places with "f", right?

 

2. Is it possible that a workpoint, selected as single workpoint for export, is also the base point of a rectangular pattern? If so, list it twice? Once as single workpoint and second as first point of rectangular pattern?

 

3. If the Workpoints and pattern should be sorted, we need something which defines the order. In the fx-parameter list, it can be the order of entries.

 

Maybe there are more questions in further progress.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 9 of 18

r.claus
Contributor
Contributor

Hello,

very nice to hear from you.

Regarding your questions:
1. Yes, the empty places must always be filled with "f". The names should stay in the first line. The same is true for the patterns. Maybe it is better to work with 4 to 30 workpoints.

2. The base workpoint of a rectangular pattern is a single workpoint or sometimes more workpoints, but it is selected only with the pattern. The base workpoint(s) should be listed only as the first point(s) of a rectangular pattern and not twice.

3. Yes, we can use the order of entries in the fx-parameter list. It is also possible to set them once.

 

Maybe better as example:

4 to 30 single workpoints with selectable names

0 to 10 points in pattern 1 (single workpoint as base point)

0 to 90 points in pattern 2 (pattern 1 as base pattern)

0 to 10 points in pattern 3 (single workpoint as base)

0 to 20 points in pattern 4 (3 single workpoints as base)

 

Feel free to ask me more questions.

Thank you

0 Likes
Message 10 of 18

Ralf_Krieg
Advisor
Advisor

Hello

 

First, I've noticed that multivalue parameters are always alphabetical sorted. That may be no problem with single workpoints. But for the pattern is the correct order of the patterns is necessary. You could always rename the patterns to "reorder" them, but I would prefer to create fx parameters for each pattern. For each pattern a pair of paramters. In the text parameter "PatternNameX" (where X is the order number) is the value the name of the pattern. In the numeric, unitless parameter "PatternFields" is the value the maximum number of pattern elements. This way, you can add more patterns and remove patterns and change the maximum field numbers. The picture shows the parameters for a scenario with workpoints 4 pattern features.

 

 

Hope all is as expected.

 

fx_Parameters_2021-11-21.jpg

 

 

Option Explicit on

Class ThisRule

	Private Structure UWorkPoint
		Dim Name As String
		Dim Parent As String
		Dim X As String
		Dim Y As String
		Dim Z As String
	End Structure

	Private uWP As UWorkPoint
	Private uWorkPointList As List(Of UWorkPoint)
	Private uPatternList As List(Of UWorkPoint)

	Private sCaption As String


	Public Sub Main()

		Dim oDoc As PartDocument = ThisDoc.Document
		Dim fxNumber As String = String.Empty
		Dim fxCustomer As String = String.Empty
		Dim fxType As String = String.Empty


		Dim oWPs As New List(Of String)
		Dim iWPCount As Integer
		Dim oUserParam As UserParameter
		Dim iMaxCount As Integer = oDoc.ComponentDefinition.Parameters.UserParameters.Count
		Dim i As Integer
		Dim oPatternNames As New List(Of String)
		Dim oPatternNumbers As New List(Of String)
		uWorkPointList = New List(Of UWorkPoint)
		uPatternList = New List(Of UWorkPoint)
		sCaption = "iLogic Export Workpoints 2 CSV"

		For i = 1 To iMaxCount
			For Each oUserParam In oDoc.ComponentDefinition.Parameters.UserParameters
				Select Case oUserParam.Name.ToUpper
					Case "PATTERNNAME" & i : oPatternNames.Add(oUserParam.Value)
					Case "PATTERNFIELDS" & i : oPatternNumbers.Add(oUserParam.Value)
					Case "WP_FIELDS" : iWPCount = oUserParam.Value
					Case "WP_EXPORT"
						oWPs = SortList(MultiValue.List("WP_Export").Cast(Of String)().ToList())
						If oWPs.Count = 0 Then
							oWPs = New List(Of String)
							oWPs.Add(oUserParam.Value.ToString)
						End If
					Case "NUMBER" : fxNumber = oUserParam.Value
					Case "CUSTOMER" : fxCustomer = oUserParam.Value
					Case "TYPE" : fxType = oUserParam.Value
				End Select
			Next
		Next

		For Each item As String In oWPs
			IsWorkpoint(item, oDoc)
		Next

		Do While uWorkPointList.Count < iWPCount
			uWP = CreateuWP("SINGLE_Work Point")
			uWorkPointList.Add(uWP)
		Loop


		'search all patterns for the names in pattern list
		For i = 0 To oPatternNames.Count - 1
			IsRectPattern(oPatternNames.Item(i), oPatternNumbers.Item(i), oDoc)
			IsCircPattern(oPatternNames.Item(i), oPatternNumbers.Item(i), oDoc)
		Next

		ExportWorkpoints(uWorkPointList, fxNumber, fxCustomer, fxType)

	End Sub

	Private Sub IsWorkpoint(ByVal item As String, ByVal oDoc As PartDocument)
		Dim oWP As WorkPoint
		For Each oWP In oDoc.ComponentDefinition.WorkPoints
			If (item.ToUpper = oWP.Name.ToUpper) And (oWP.Visible = True) Then
				If oWP.IsCoordinateSystemElement = False Then
					uWP = CreateuWP("Single", oWP)
					uWorkPointList.Add(uWP)
				End If
			End If
		Next
	End Sub

	Private Sub IsRectPattern(ByVal item As String, ByVal iColCount As Integer, ByVal oDoc As PartDocument)
		Try
			Dim oRPF As RectangularPatternFeature
			For Each oRPF In oDoc.ComponentDefinition.Features.RectangularPatternFeatures
				If item.ToUpper = oRPF.Name.ToUpper Then
					If oRPF.Suppressed = True Then
						MsgBox("Rectangular Pattern " & oRPF.Name & " is suppressed. Skipping and continue next", MsgBoxStyle.Information, sCaption)
					Else
						uPatternList.Clear()
						GetPointsRect(oRPF, oRPF.Name, iColCount)

						Do While uPatternList.Count < iColCount
							uWP = CreateuWP(oRPF.Name)
							uPatternList.Add(uWP)
						Loop

						uWorkPointList.AddRange(uPatternList)
					End If
				End If
			Next
		Catch ex As Exception
			Logger.Debug(ex.Message)
		End Try
	End Sub

	Private Sub IsCircPattern(ByVal item As String, ByVal iColCount As Integer, ByVal oDoc As PartDocument)
		Try
			Dim oCPF As CircularPatternFeature
			For Each oCPF In oDoc.ComponentDefinition.Features.CircularPatternFeatures
				If item.ToUpper = oCPF.Name.ToUpper Then
					If oCPF.Suppressed = True Then
						MsgBox("Circular Pattern " & oCPF.Name & " is suppressed. Skipping and continue next", MsgBoxStyle.Information, sCaption)
					Else
						uPatternList.Clear()
						GetPointsCirc(oCPF, oCPF.Name, iColCount)

						Do While uPatternList.Count < iColCount
							uWP = CreateuWP(oCPF.Name)
							uPatternList.Add(uWP)
						Loop

						uWorkPointList.AddRange(uPatternList)
					End If
				End If
			Next
		Catch ex As Exception
			Logger.Debug(ex.Message)
		End Try
	End Sub

	Private Sub GetPointsRect(ByVal oPatternFeature As RectangularPatternFeature, ByVal sPatternFeature As String, ByVal iColCount As Integer)

		Try
			Dim i As Integer
			Dim j As Integer
			Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures

			For i = 1 To oParentFeatures.Count
				If TypeOf oParentFeatures(i) Is WorkPoint Then
					If oParentFeatures(i).Visible = True Then
						If oParentFeatures(i).IsCoordinateSystemElement = False Then
							uWP = CreateuWP(sPatternFeature, oParentFeatures(i))
							If Not uWP.Name Is Nothing Then uPatternList.Add(uWP)
						End If
					Else
						uWP = CreateuWP(sPatternFeature)
						uPatternList.Add(uWP)
					End If
				ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
					If oParentFeatures(i).Suppressed = False Then
						GetPointsRect(oParentFeatures(i), sPatternFeature, iColCount)
					End If
				ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
					If oParentFeatures(i).Suppressed = False Then
						GetPointsCirc(oParentFeatures(i), sPatternFeature, iColCount)
					End If
				End If
			Next

			Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
			For i = 1 To oPatternElements.Count
				If oPatternElements(i).Suppressed = False Then
					Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
					If Not oResultFeatures Is Nothing Then
						For j = 1 To oResultFeatures.Count
							If TypeOf oResultFeatures(j) Is WorkPoint Then
								If oResultFeatures(j).Visible = True Then
									If oResultFeatures(j).IsCoordinateSystemElement = False Then
										uWP = CreateuWP(sPatternFeature, oResultFeatures(j))
										If Not uWP.Name Is Nothing Then uPatternList.Add(uWP)
									End If
								End If
							Else
								uWP = CreateuWP(sPatternFeature)
								uPatternList.Add(uWP)
							End If
						Next
					End If
				End If
			Next

		Catch ex As Exception
			Logger.Debug(ex.Message)
		End Try
	End Sub

	Private Sub GetPointsCirc(ByVal oPatternFeature As CircularPatternFeature, ByVal sPatternFeature As String, ByVal icolCount As Integer)

		Dim i As Integer
		Dim j As Integer
		Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures

		For i = 1 To oParentFeatures.Count
			If TypeOf oParentFeatures(i) Is WorkPoint Then
				If oParentFeatures(i).Visible = True Then
					If oParentFeatures(i).IsCoordinateSystemElement = False Then
						uWP = CreateuWP(sPatternFeature, oParentFeatures(i))
						If Not uWP.Name Is Nothing Then uPatternList.Add(uWP)
					End If
				Else
					uWP = CreateuWP(sPatternFeature)
					uPatternList.Add(uWP)
				End If
			ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
				If oParentFeatures(i).Suppressed = False Then
					GetPointsRect(oParentFeatures(i), sPatternFeature, icolCount)
				End If
			ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
				If oParentFeatures(i).Suppressed = False Then
					GetPointsCirc(oParentFeatures(i), sPatternFeature, icolCount)
				End If
			End If
		Next

		Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
		For i = 1 To oPatternElements.Count
			If oPatternElements(i).Suppressed = False Then
				Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
				If Not oResultFeatures Is Nothing Then
					For j = 1 To oResultFeatures.Count
						If TypeOf oResultFeatures(j) Is WorkPoint Then
							If oResultFeatures(j).Visible = True Then
								If oResultFeatures(j).IsCoordinateSystemElement = False Then
									uWP = CreateuWP(sPatternFeature, oResultFeatures(j))
									If Not uWP.Name Is Nothing Then uPatternList.Add(uWP)
								End If
							Else
								uWP = CreateuWP(sPatternFeature)
								uPatternList.Add(uWP)
							End If
						End If
					Next
				End If
			End If
		Next

	End Sub

	Private Sub ExportWorkpoints(ByVal uWorkPointList As List(Of UWorkPoint), ByVal fxNumber As String, ByVal fxCustomer As String, ByVal fxType As String)

		Dim partDoc = ThisApplication.ActiveDocument
		Dim partDef = partDoc.ComponentDefinition

		Dim dlmtr As String = ";"
		Dim filePath As String
		Dim fileName As String
		Dim i As Integer
		Dim j As Integer

		filePath = ThisDoc.Path & "\"
		fileName = "CSV Name" & fxNumber & ".csv"

		Dim expfile As System.IO.StreamWriter = System.IO.File.CreateText(filePath + fileName)

		Dim aFileData(3, uWorkPointList.Count + 3) As String
		aFileData(0, 0) = "Number"
		aFileData(1, 0) = fxNumber
		aFileData(0, 1) = "Customer"
		aFileData(1, 1) = fxCustomer
		aFileData(0, 2) = "Type"
		aFileData(1, 2) = fxType
		aFileData(0, 3) = "Name"
		aFileData(1, 3) = "X"
		aFileData(2, 3) = "Y"
		aFileData(3, 3) = "Z"

		For i = 4 To uWorkPointList.Count + 3
			Try
				aFileData(0, i) = uWorkPointList.Item(i - 4).Name
				aFileData(1, i) = uWorkPointList.Item(i - 4).X
				aFileData(2, i) = uWorkPointList.Item(i - 4).Y
				aFileData(3, i) = uWorkPointList.Item(i - 4).Z
			Catch
				aFileData(0, i) = "f"
				aFileData(1, i) = "f"
				aFileData(2, i) = "f"
				aFileData(3, i) = "f"
			End Try
		Next

		For i = 0 To 3
			For j = 0 To uWorkPointList.Count + 3
				expfile.Write(aFileData(i, j) & dlmtr)
			Next
			expfile.Write(vbCrLf)
		Next

		expfile.Close()

		ThisDoc.Launch(filePath + fileName)

	End Sub

	Private Function CreateuWP(ByVal sPrefix As String, Optional ByVal oWP As WorkPoint = Nothing) As UWorkPoint
		If oWP Is Nothing Then
			'create Dummy entry
			uWP.Name = sPrefix & "_f"
			uWP.X = "f"
			uWP.Y = "f"
			uWP.Z = "f"
		Else
			' Check for duplicate in uworkpointlist 
			If uWorkPointList.Exists(Function(x) x.Name = "Single_" & oWP.Name) = True Then
				Logger.Debug("Skipped duplicate workpoint " & oWP.Name)
				Return Nothing
			Else
				uWP = New UWorkPoint
				uWP.Name = sPrefix & "_" & oWP.Name
				uWP.X = Round(oWP.Point.X * 10, 2).ToString
				uWP.Y = Round(oWP.Point.Y * 10, 2).ToString
				uWP.Z = Round(oWP.Point.Z * 10, 2).ToString
			End If
		End If

		Return uWP
	End Function

	Private Function SortList(ByVal oSourceList As List(Of String)) As List(Of String)

		Dim listOfLines As New Dictionary(Of Integer, String)
		For Each line As String In oSourceList
			Dim part() As String = Line.Split(New Char() {"t"}, StringSplitOptions.RemoveEmptyEntries)
			listOfLines.Add(Integer.Parse(part(part.Length - 1)), Line)
		Next

		Dim listOfKeys As List(Of Integer) = listOfLines.Keys.ToList
		listOfKeys.Sort()

		Dim oSortedList As New List(Of String)
		For Each key As String In listOfKeys
			oSortedList.Add(listOfLines(key))
		Next

		Return oSortedList
	End Function
End Class


 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 11 of 18

r.claus
Contributor
Contributor

Hello,

 

thanks again for the help. The task is really not easy.

In line 46 I had to remove "SortList", otherwise I got an error message and I could only enter one workpoint in "WP_Export". Line 46: oWPs = (MultiValue.List("WP_Export").Cast(Of String)().ToList())

 

Since only one component with different active workpoints is being worked with, it should still be possible to make a selection. So which patterns and which individual workpoints should be exported. I would then create multiple rules that can be used for the particular case. Maybe using the fx-parameter list for selection would be better than after all or define a list like in your second code?

Besides that, it would be important that the workpoints in the CSV always keep the name (name of pattern). Without "sPrefix "_f". So, the name should be static per pattern and the point get a consecutive number (1 to max). Also, single workpoints should keep the same name from Inventor if they are invisible.

 

I noticed that invisible workpoints in the pattern are not included in the CSV. The names should remain in place, only the values should be replaced with "f".

For overview the attached CSV file. How the naming’s should be. The single workpoint 5 and the point 10 in the pattern "Workpoints_Rod" are invisible.

 

Do you think it is possible to implement these points?

 

I hope you can help me again. Thank you very much for your patience.

0 Likes
Message 12 of 18

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, I have actual no time to look at this. But I will do as fast as I can.


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 13 of 18

r.claus
Contributor
Contributor
Hi,

Thank you for message.

No problem, I look forward to hearing from you again soon.
0 Likes
Message 14 of 18

Ralf_Krieg
Advisor
Advisor

Hello

 

I rethink the program logic. I throw away the parameters for the workpoints and patterns to export. The parameters for number, customer and type remains.

All existing single Workpoints will be exported. Invisible Workpoints get an "f" in the 3 coordinate fields.

 

All patterns are exported, except they are entirely suppressed. This way we can have 2, 3, 4 or x pattern in the same file and only unsuppress the necessary. Cause of all unsuppressed patterns are exported, there's no need to define them in parameters. All Workpoints in the pattern will be exported. Invisible Workpoints within the pattern get an "f" in the 3 coordinate fields.

 

Single Workpoints that are base of a pattern will also be exported in the pattern (otherwise the number of columns vary), but get an "f" in the 3 coordinate fields. So the coordinates are not duplicated in the export file. Is this ok?

 

Can you give it a try and tell if we are closer to the solution?

 

Class ThisRule

	Private Structure UWorkPoint
		Dim Name As String
		Dim X As String
		Dim Y As String
		Dim Z As String
	End Structure

	Private iWPCount As Integer
	Private uWP As UWorkPoint
	Private uWorkPointList As List(Of UWorkPoint)
	Private uPatternList As List(Of UWorkPoint)

	Public Sub Main()

		Dim oDoc As PartDocument = ThisDoc.Document
		Dim fxNumber As String = String.Empty
		Dim fxCustomer As String = String.Empty
		Dim fxType As String = String.Empty


		Dim oWPs As New List(Of String)
		Dim oUserParam As UserParameter
		Dim oPatternNames As New List(Of String)
		Dim oPatternNumbers As New List(Of String)
		uWorkPointList = New List(Of UWorkPoint)
		uPatternList = New List(Of UWorkPoint)

		For Each oUserParam In oDoc.ComponentDefinition.Parameters.UserParameters
			Select Case oUserParam.Name.ToUpper
				Case "NUMBER" : fxNumber = oUserParam.Value
				Case "CUSTOMER" : fxCustomer = oUserParam.Value
				Case "TYPE" : fxType = oUserParam.Value
			End Select
		Next

		ProcessWorkpoints(oWPs,oDoc)
		
		Dim oFeature As Object
		For Each oFeature In oDoc.ComponentDefinition.Features
			iWPCount=1
			If TypeOf oFeature Is Inventor.RectangularPatternFeature Then
				ProcessRectPattern(oFeature, oDoc)
			ElseIf TypeOf oFeature Is Inventor.CircularPatternFeature Then
				ProcessCircPattern(oFeature, oDoc)
			End If
		Next
		
		ExportWorkpoints(uWorkPointList, fxNumber, fxCustomer, fxType)

	End Sub

	Private Sub ProcessWorkpoints(ByVal oWPs As List(Of String), ByVal oDoc As PartDocument)
		Dim oWP As WorkPoint
		For Each oWP In oDoc.ComponentDefinition.WorkPoints
			If oWP.IsPatternElement = False Then
				logger.debug(oWP.Name)
				uWP = CreateuWP(oWP, 0,"Single")
				If uWP.Name IsNot Nothing Then uWorkPointList.Add(uWP)
				logger.debug(uWP.Name)
			End If
		Next
	End Sub

	Private Sub ProcessRectPattern(ByVal oRPF As RectangularPatternFeature, ByVal oDoc As PartDocument)
		Try
			If oRPF.Suppressed = True Then
				logger.debug("Rectangular Pattern " & oRPF.Name & " is suppressed. Skipping and continue next")
			Else
				uPatternList.Clear()
				GetPointsRect(oRPF, oRPF.Name)
				uWorkPointList.AddRange(uPatternList)
			End If
		Catch ex As Exception
			Logger.Debug("ProcessRectPattern" & vbCrLf & ex.Message)
		End Try
	End Sub

	Private Sub ProcessCircPattern(ByVal oCPF As CircularPatternFeature, ByVal oDoc As PartDocument)
		Try
			If oCPF.Suppressed = True Then
				logger.debug("Circular Pattern " & oCPF.Name & " is suppressed. Skipping and continue next")
			Else
				uPatternList.Clear()
				GetPointsCirc(oCPF, oCPF.Name)
				uWorkPointList.AddRange(uPatternList)
			End If
		Catch ex As Exception
			Logger.Debug("ProcessCircPattern" & vbCrLf & ex.Message)
		End Try
	End Sub

	Private Sub GetPointsRect(ByVal oPatternFeature As RectangularPatternFeature, ByVal sPatternFeature As String)

		Try
			Dim i As Integer
			Dim j As Integer
			Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures

			For i = 1 To oParentFeatures.Count
				If TypeOf oParentFeatures(i) Is WorkPoint Then
					uWP = CreateuWP(oParentFeatures(i), iWPCount,sPatternFeature)
					If Not uWP.Name Is Nothing Then 
						uPatternList.Add(uWP)
						iWPCount += 1
					End If
				ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
					If oParentFeatures(i).Suppressed = False Then GetPointsRect(oParentFeatures(i), sPatternFeature)
				ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
					If oParentFeatures(i).Suppressed = False Then GetPointsCirc(oParentFeatures(i), sPatternFeature)
				End If
			Next

			Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
			For i = 1 To oPatternElements.Count
				If oPatternElements(i).Suppressed = False Then
					Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
					If Not oResultFeatures Is Nothing Then
						For j = 1 To oResultFeatures.Count
							If TypeOf oResultFeatures(j) Is WorkPoint Then
								uWP = CreateuWP(oResultFeatures(j), iWPCount,sPatternFeature)
								If Not uWP.Name Is Nothing Then 
									uPatternList.Add(uWP)
									iWPCount += 1
								End If
							End If
						Next
					End If
				End If
			Next

		Catch ex As Exception
			Logger.Debug("GetPointsRect" & vbCrLf & ex.Message)
		End Try
	End Sub

	Private Sub GetPointsCirc(ByVal oPatternFeature As CircularPatternFeature, ByVal sPatternFeature As String)
		
		Try
			Dim i As Integer
			Dim j As Integer
			Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures
	
			For i = 1 To oParentFeatures.Count
				If TypeOf oParentFeatures(i) Is WorkPoint Then
					uWP = CreateuWP(oParentFeatures(i), iWPCount,sPatternFeature)
					If Not uWP.Name Is Nothing Then 
						uPatternList.Add(uWP)
						iWPCount += 1
					End If
				ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
					If oParentFeatures(i).Suppressed = False Then GetPointsRect(oParentFeatures(i), sPatternFeature)
				ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
					If oParentFeatures(i).Suppressed = False Then GetPointsCirc(oParentFeatures(i), sPatternFeature)
				End If
			Next
	
			Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
			For i = 1 To oPatternElements.Count
				If oPatternElements(i).Suppressed = False Then
					Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
					If Not oResultFeatures Is Nothing Then
						For j = 1 To oResultFeatures.Count
							If TypeOf oResultFeatures(j) Is WorkPoint Then
								uWP = CreateuWP(oResultFeatures(j), iWPCount, sPatternFeature)
								If Not uWP.Name Is Nothing Then 
									uPatternList.Add(uWP)
									iWPCount += 1
								End If
							End If
						Next
					End If
				End If
			Next
		Catch ex As Exception
			Logger.Debug("GetPointsCirc" & vbCrLf & ex.Message)
		End Try

	End Sub

	Private Sub ExportWorkpoints(ByVal uWorkPointList As List(Of UWorkPoint), ByVal fxNumber As String, ByVal fxCustomer As String, ByVal fxType As String)

		Dim partDoc = ThisApplication.ActiveDocument
		Dim partDef = partDoc.ComponentDefinition

		Dim dlmtr As String = ";"
		Dim filePath As String
		Dim fileName As String
		Dim i As Integer
		Dim j As Integer

		filePath = ThisDoc.Path & "\"
		fileName = "CSV Name" & fxNumber & ".csv"

		Dim expfile As System.IO.StreamWriter = System.IO.File.CreateText(filePath + fileName)

		Dim aFileData(3, uWorkPointList.Count + 3) As String
		aFileData(0, 0) = "Number"
		aFileData(1, 0) = fxNumber
		aFileData(0, 1) = "Customer"
		aFileData(1, 1) = fxCustomer
		aFileData(0, 2) = "Type"
		aFileData(1, 2) = fxType
		aFileData(0, 3) = "Name"
		aFileData(1, 3) = "X"
		aFileData(2, 3) = "Y"
		aFileData(3, 3) = "Z"

		For i = 4 To uWorkPointList.Count + 3
			Try
				aFileData(0, i) = uWorkPointList.Item(i - 4).Name
				aFileData(1, i) = uWorkPointList.Item(i - 4).X
				aFileData(2, i) = uWorkPointList.Item(i - 4).Y
				aFileData(3, i) = uWorkPointList.Item(i - 4).Z
			Catch
			End Try
		Next

		For i = 0 To 3
			For j = 0 To uWorkPointList.Count + 3
				expfile.Write(aFileData(i, j) & dlmtr)
			Next
			expfile.Write(vbCrLf)
		Next

		expfile.Close()

		ThisDoc.Launch(filePath + fileName)

	End Sub

	Private Function CreateuWP(ByVal oWP As WorkPoint, ByVal iWPCount As Integer, Optional ByVal sPatternName As String = "") As UWorkPoint
		
		If oWP.IsCoordinateSystemElement = True Then Return Nothing
		
		Dim sPatternString As String = ""
		If sPatternName.ToUpper = "SINGLE" Then 
			sPatternString=oWP.Name
		Else
			sPatternString = "Workpoints_" & sPatternName & "_" & iWPCount
		End If
			
		If oWP.Visible = False Then
			'create Dummy entry
			uWP.Name = sPatternString '& oWP.Name
			uWP.X = "f"
			uWP.Y = "f"
			uWP.Z = "f"
			
			Return uWP
		End If
			
		If sPatternName = "" Then
			'create Dummy entry
			uWP.Name = sPatternString 'oWP.Name
			uWP.X = "f"
			uWP.Y = "f"
			uWP.Z = "f"
			
			Return uWP
		End If
		
		' Check for duplicate in uworkpointlist 
		If uWorkPointList.Exists(Function(x) x.Name = oWP.Name) = True Then
			'create as dummy, to keep column count but prevent duplicate coordinates
			uWP.Name = sPatternString '& oWP.Name
			uWP.X = "f"
			uWP.Y = "f"
			uWP.Z = "f"
			
			Return uWP
		End If
		
		uWP = New UWorkPoint
		uWP.Name = sPatternString '& oWP.Name
		uWP.X = Round(oWP.Point.X * 10, 2).ToString
		uWP.Y = Round(oWP.Point.Y * 10, 2).ToString
		uWP.Z = Round(oWP.Point.Z * 10, 2).ToString

		Return uWP
	End Function
End Class

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 15 of 18

r.claus
Contributor
Contributor

Hello,

nice to hear from you again.


It's better, but I think we misunderstood each other a little.

 

Sorry for that.

0 Likes
Message 16 of 18

r.claus
Contributor
Contributor

Hello,

 

Maybe it would be enough to use the second code from 11-12-2021 and integrate that invisible workpoints (individually and in patterns) are not removed (names remain, values become "0").


I used your second code with a rule to rename the workpoints for each pattern. Do you know a way to use a separate "oWorkPointColl" for each pattern in your code? So I hope to create for each pattern (group of workpoints) a block like below. Because I need a fixed number of workpoints for each type of pattern. (I only need the Y component for each workpoint)

 

For i = 9 To 50

			Try
				afiledata(0, i) = oWorkPointColl(i-8).Name
				'afiledata(1, i) = Round(oWorkPointColl(i-3).Point.X * 10, 1)
				afiledata(1, i) = Round(oWorkPointColl(i-8).Point.Y * 10 -5, 2)
				'afiledata(3, i) = Round(oWorkPointColl(i-3).Point.Z * 10, 1)
			Catch 
				afiledata(0, i) = "Entw" & k
				afiledata(1, i) = "0"
				'afiledata(2, i) = "0"
				'afiledata(3, i) = "0"
				k=k+1
			End Try

 

0 Likes
Message 17 of 18

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Sorry for the very late reply.

 

If I don't skip the invisible workpoints in the code of my second post (which is not a problem), you will have the alphabetical sort order of the fx-parameter multi value list and the workpoints of the patterns are not renamed. See the version below.

 

You can create a separate object collection for each pattern and another one for the single work points. Object collections don't have a name property, so all collections are anonymous. You have to find a way to identify the different collections if you want to fill it up with dummy entries to a defined limit somewhere later in your program.

 

Option Explicit on
Class ThisRule
	
	Private GetPoints As ObjectCollection

	Private Sub Main
	
	'###################################################################################
	'###################################################################################
	' define the patternfeatures and/or workpoints here, use the name from model browser
'	Dim Features As New List(Of String) From { _
'	"WorkPoints1", _
'	"WorkPoints4", _
'	"Workpoint_Head_1", _
'	"Workpoint_Head_2", _
'	"Workpoint_Head_3", _
'	"Workpoint_Head_4" _
'	}
	
	
	' or define the patternfeatures and/or workpoints as a multivalue fx-parameter "WP_Export"
	' use the name from model browser
	' use the automatic alphabetical sort order of the multi value list
	Dim Features= MultiValue.List("WP_Export").Cast(Of String)().ToList()
	
	'###################################################################################
	'###################################################################################
	
	Dim oDoc As PartDocument = ThisApplication.ActiveDocument
	Dim oSelSet As SelectSet = oDoc.SelectSet

	If oSelSet.Count = 0 Then
		' use the predefined list of named workpoints and features with workpoints
		' compare every rectangularpatternfeature, circularpatternfeature and workpoint
		' with all names Of the given list, if match add to selectset, remove mtached
		' item from list To shorten Next search
		Dim oRPF As RectangularPatternFeature
		Dim oCPF As CircularPatternFeature
		Dim oWP As WorkPoint
		For Each oRPF In oDoc.ComponentDefinition.Features.RectangularPatternFeatures
			If Features.Find(Function(x) x.ToUpper = oRPF.Name.ToUpper) IsNot Nothing Then
				oSelSet.Select(oRPF)
				Features.Remove(Features.Find(Function(x) x.ToUpper = oRPF.Name.ToUpper))
			End If
		Next
		For Each oCPF In oDoc.ComponentDefinition.Features.CircularPatternFeatures
			If Features.Find(Function(x) x.ToUpper = oCPF.Name.ToUpper) IsNot Nothing Then
				oSelSet.Select(oCPF)
				Features.Remove(Features.Find(Function(x) x.ToUpper = oCPF.Name.ToUpper))
			End If
		Next
		For Each oWP In oDoc.ComponentDefinition.WorkPoints 
			If Features.Find(Function(x) x.ToUpper = oWP.Name.ToUpper) IsNot Nothing Then
				oSelSet.Select(oWP)
				Features.Remove(Features.Find(Function(x) x.ToUpper = oWP.Name.ToUpper))
			End If
		Next
		' Features should now be empty
		If Features.Count>0 Then
			MsgBox("Features NOT empty.", MsgBoxStyle.Critical, "iLogic ExportWorkPoints")
			For Each item As String In Features
				Logger.Debug(item)
			Next
		End If
		
	End If

	GetPoints = ThisApplication.TransientObjects.CreateObjectCollection

	Dim oSel As Object
	For Each oSel In oSelSet
	    Select Case oSel.Type
	        Case kRectangularPatternFeatureObject:
	            Call GetPointsRect(oSel)
	        Case kCircularPatternFeatureObject:
	            Call GetPointsCirc(oSel)
	        Case kWorkPointObject:
	            'If oSel.Visible = True Then
	                If oSel.IsCoordinateSystemElement = False Then
	                    Call GetPoints.Add(oSel)
	                End If
	            'End If
	        Case kBrowserFolderObject:  ' Nope, no folders in parts
	    End Select
	Next

	oSelSet.Clear
	
	ExportWorkpoints(GetPoints)
	End Sub

	Private Sub GetPointsRect(ByVal oPatternFeature As RectangularPatternFeature)
	    
	    Dim i As Integer
	    Dim j As Integer
	    Dim oParentFeatures As ObjectCollection= oPatternFeature.ParentFeatures
	    
	    For i = 1 To oParentFeatures.Count
	        If TypeOf oParentFeatures(i) Is WorkPoint Then
	            If oParentFeatures(i).Visible = True Then
	                If oParentFeatures(i).IsCoordinateSystemElement = False Then
	                    GetPoints.Add(oParentFeatures(i))
	                End If
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsRect(oParentFeatures(i))
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsCirc(oParentFeatures(i))
	            End If
	        End If
	    Next
	    
	    Dim oPatternElements As FeaturePatternElements= oPatternFeature.PatternElements
	    For i = 1 To oPatternElements.Count
	        Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
	        If Not oResultFeatures Is Nothing Then
	            For j = 1 To oResultFeatures.Count
	                If TypeOf oResultFeatures(j) Is WorkPoint Then
	                    'If oResultFeatures(j).Visible = True Then
	                        If oResultFeatures(j).IsCoordinateSystemElement = False Then
	                            GetPoints.Add(oResultFeatures(j))
	                        End If
	                    'End If
	                End If
	            Next
	        End If
	    Next
	End Sub

	Private Sub GetPointsCirc(ByVal oPatternFeature As CircularPatternFeature)
	    
	    Dim i As Integer
	    Dim j As Integer
	    Dim oParentFeatures As ObjectCollection = oPatternFeature.ParentFeatures
	    
	    For i = 1 To oParentFeatures.Count
	        If TypeOf oParentFeatures(i) Is WorkPoint Then
	            If oParentFeatures(i).Visible = True Then
	                If oParentFeatures(i).IsCoordinateSystemElement = False Then
	                    GetPoints.Add(oParentFeatures(i))
	                End If
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is RectangularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsRect(oParentFeatures(i))
	            End If
	        ElseIf TypeOf oParentFeatures(i) Is CircularPatternFeature Then
	            If oParentFeatures(i).Suppressed = False Then
	                GetPointsCirc(oParentFeatures(i))
	            End If
	        End If
	    Next
	    
	    Dim oPatternElements As FeaturePatternElements = oPatternFeature.PatternElements
	    For i = 1 To oPatternElements.Count
	        Dim oResultFeatures As ObjectCollection = oPatternElements(i).ResultFeatures
	        If Not oResultFeatures Is Nothing Then
	            For j = 1 To oResultFeatures.Count
	                If TypeOf oResultFeatures(j) Is WorkPoint Then
	                    'If oResultFeatures(j).Visible = True Then
	                        If oResultFeatures(j).IsCoordinateSystemElement = False Then
	                            GetPoints.Add(oResultFeatures(j))
	                        End If
	                    'End If
	                End If
	            Next
	        End If
	    Next
	End Sub

	Private Sub ExportWorkpoints(ByVal oWorkPointColl As ObjectCollection)

		Dim partDoc = ThisApplication.ActiveDocument
		Dim partDef = partDoc.ComponentDefinition

		Dim dlmtr As String = ";" 'or vbTab
		Dim filePath As String
		Dim fileName As String
		Dim i As Integer
		Dim j As Integer 

		filePath = ThisDoc.Path & "\" 
		fileName = "CSV Name" & " " & ".csv"

		Dim expfile As System.IO.StreamWriter = System.IO.File.CreateText(filePath + fileName)

		Dim aFileData(3, 103) As String
		afiledata(0, 0) = "Number"
		afiledata(1, 0) = Number
		afiledata(0, 1) = "Customer"
		afiledata(1, 1) = Customer
		afiledata(0, 2) = "Type"
		afiledata(1, 2) = Type
		afiledata(0, 3) = "Name"
		afiledata(1, 3) = "X"
		afiledata(2, 3) = "Y"
		afiledata(3, 3) = "Z"

		For i = 4 To 103
			Try
				afiledata(0, i) = oWorkPointColl(i-3).Name
				afiledata(1, i) = Round(oWorkPointColl(i-3).Point.X * 10, 1)
				afiledata(2, i) = Round(oWorkPointColl(i-3).Point.Y * 10, 1)
				afiledata(3, i) = Round(oWorkPointColl(i-3).Point.Z * 10, 1)
			Catch
				afiledata(0, i) = "f"
				afiledata(1, i) = "f"
				afiledata(2, i) = "f"
				afiledata(3, i) = "f"
			End Try
		Next

		For i = 0 To 3
			For j = 0 To 103
				expfile.Write(afiledata(i,j) & dlmtr)
			Next
				expfile.Write(vbCrLf)
		Next

		expfile.Close

		ThisDoc.Launch(filePath + fileName)
		
	End Sub

End Class

 

 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 18 of 18

r.claus
Contributor
Contributor
Hello,

thank you very much for your reply.
I was able to find a way to separate the workpoints.

Wish you a merry christmas and a happy new year.
0 Likes