UCS to UCS Constraint SUb-Assembly to Part

UCS to UCS Constraint SUb-Assembly to Part

Anonymous
Not applicable
527 Views
1 Reply
Message 1 of 2

UCS to UCS Constraint SUb-Assembly to Part

Anonymous
Not applicable

In the Assembly file, I wanted to make a constraint set (UcsToUcs) from a subassembly ucs to a part ucs.

When I run the code it says "Public member 'Constraints' on type 'PartComponentDefinition' not found."

Please see the snapshot and sample files in version2020.

Thank you.

 

Dim oSubAsm As AssemblyDocument = ThisAssembly.Document
Dim wfUCSs As UserCoordinateSystems

'Create a list for skUCS
For Each oRefDoc As Document In oSubAsm.ReferencedDocuments
	'Get the wireframe
	If oRefDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject AndAlso oRefDoc.DisplayName.Contains("wireframe") Then
		Dim wfDoc As PartDocument = oRefDoc	
		wfUCSs = wfDoc.ComponentDefinition.UserCoordinateSystems
	End If
Next
	
				

For Each oRefDoc As Document In oSubAsm.ReferencedDocuments
	 If oRefDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
		Dim oAsmDoc As AssemblyDocument = oRefDoc	
			For Each oPartDoc As PartDocument In oAsmDoc.ReferencedDocuments
					For Each wfUCS As UserCoordinateSystem In wfUCSs
						If oPartDoc.DisplayName.Contains(wfUCS.Name) Then
							MsgBox("Yes")
							Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
							Dim oUCS As UserCoordinateSystem = oCompDef.UserCoordinateSystems.Item("UCS_Origin")
							Dim oMate As FlushConstraint
							
							
							'Public member 'Constraints' on type 'PartComponentDefinition' not found
                                                        'Maybe because the parts are inside the sub-assembly
oMate = oCompDef.Constraints.AddFlushConstraint(oUCS, wfUCS, 0) End If Next Next End If Next

 

 

UCS MateTest.JPG

 

0 Likes
528 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

So in the Sub-Assemblies, I created a a UCS called "UCS_Origin". Those ucs will constrained with the wireframe ucs.

I use the ilogic's default 

Constraints.AddUcsToUcs("UcsToUcs1", "Part1:1", "UCS1", "Part2:1", "UCS2", 
                            xOffset := 0, yOffset := 0, zOffset := 0)

 The problem is it only worked for the last item. During iteration, it sort of created only  temporary constraint in the  other component.

 

This is the part where I need help as Im not sure what is the problem. 

I was thinking to try to make the "AddUcsToUcs" rule as sub routin but I really dont know how to do that.

Please the video and code 

below.

Thanks

 

Dim oSubAsm As AssemblyDocument = ThisAssembly.Document
Dim wfUCSs As UserCoordinateSystems
Dim wfDoc As PartDocument

'Create a list for skUCS
For Each oRefDoc As Document In oSubAsm.ReferencedDocuments
	'Get the wireframe
	If oRefDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject AndAlso oRefDoc.DisplayName.Contains("wireframe") Then
		wfDoc = oRefDoc	
		'MsgBox(wfDoc.DisplayName)
		wfUCSs = wfDoc.ComponentDefinition.UserCoordinateSystems
		
	End If
Next
	
	
For Each wfUCS As UserCoordinateSystem In wfUCSs
MsgBox(wfUCS.Name)
					
	'Create a list for asmUCS
	For Each oRefDoc As Document In oSubAsm.ReferencedDocuments
		If oRefDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
			Dim oAsmDoc As AssemblyDocument = oRefDoc
			Dim oCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
					
				For Each oUCS As UserCoordinateSystem In oCompDef.UserCoordinateSystems
					If oUCS.Name.Contains("Origin") Then
						'MsgBox(oUCS.Name)
						
						For Each oPartDoc As PartDocument In oAsmDoc.ReferencedDocuments
							If oPartDoc.DisplayName.Contains(wfUCS.Name) Then
								'MsgBox(wfUCS.Name)
								
								Dim i As Integer = 1
								Dim oMateName As String = "UcsToUcs_" & i
								Dim oComp1 As String
								oComp1 = oAsmDoc.DisplayName.Split(".").First & ":1"
								'MsgBox(oComp1)
								
								Dim oComp2 As String
								oComp2 = wfDoc.DisplayName.Split(".").First & ":1"
								'MsgBox(oComp2)

								Constraints.AddUcsToUcs(oMateName, oComp1, oUCS.Name, oComp2, wfUCS.Name, 
	                            xOffset := 0, yOffset := 0, zOffset := 0)
								
								i = i + 1
							End If		
						Next				
					End If					
				Next
		End If
	Next
Next
	

		
		
0 Likes