Naming a FaceProxy Source

Naming a FaceProxy Source

ndillner343SKL
Enthusiast Enthusiast
319 Views
2 Replies
Message 1 of 3

Naming a FaceProxy Source

ndillner343SKL
Enthusiast
Enthusiast

Hello, 

 

I'm working within the assembly level. I'm looking to grab a FaceProxy, find the source of the FaceProxy, and name the source surface. 

The code below, appears to work just fine. But the changes aren't being pushed through to the part document. 

It appears to grab the correct surface. But the name does not appear within the entities list within the .ipt and when closing and re-opening the assembly it can no longer find the named entity.

 

ndillner343SKL_0-1665504111053.png

Sub Main
	Dim x As Integer = 0
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oConsts As AssemblyConstraints = oADef.Constraints

	For Each oConst As AssemblyConstraint In oConsts
		Dim oEnt1 As Object = oConst.EntityOne
		Dim oEnt2 As Object = oConst.EntityTwo
		
		x = x + 1

		Dim oSourceFace1 As Face = Nothing
		Dim oFace1 As Face = Nothing
		Dim oSourceFace2 As Face = Nothing
		Dim oFace2 As Face = Nothing
		
		oSource1 = oEnt1
		oSourceFace1 = oSource1.GetSourceFace
	    If oSourceFace1 Is Nothing Then
	        oFace1 = oSource1.NativeObject
	    Else
	        oFace1 = oSourceFace1
	    End If
		
		oSource2 = oEnt2
		oSourceFace2 = oSource2.GetSourceFace
	    If oSourceFace2 Is Nothing Then
	        oFace2 = oSource2.NativeObject
	    Else
	        oFace2 = oSourceFace2
	    End If
			
		oName = "Entity1:" & x
		Call AssignNameToEntity(oFace1, oName)
		Dim EntityOne As String = GetEntityName(oFace1)
		MsgBox(EntityOne)

		oName = "Entity2:" & x
		Call AssignNameToEntity(oFace2, oName)
		Dim EntityTwo As String = GetEntityName(oFace2)
		MsgBox(EntityTwo)
	Next
End Sub

 

0 Likes
Accepted solutions (1)
320 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @ndillner343SKL.  It looks like you are not updating or saving the parts or the main assembly at any point within the code.  That is most likely why the names are not staying put.  I would assume that you could save the main assembly, using something like oADoc.Save or oADoc.Save2(True), and it would automatically also save all referenced documents that have been 'dirtied' in the process, which should save any changes that have been made.  Maybe give that a try and see if that fixes the situation.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @ndillner343SKL.  I don't know if this will help you along your project journey or not, but since you seem to be possibly having problems retrieving true native/source objects from proxy objects, I created a fairly simple little custom Function named "GetProxySource" just for returning the native/source object that a proxy object represents.  If the input object is not a proxy type object, it will simply return that same input object.  It is recursive too, which means that if the proxy object's NativeObject is still another proxy type object, it will automatically dig another step deeper attempting to find the version of that object that is no longer a proxy.  Since every proxy type object has a NativeObject property, and the TypeName of every proxy type object ends with "Proxy", I used those two key bits of info about them to create this simple, yet handy little function just for digging down to the true source of any proxy type object, and return its true source object.  And to help prove that it works, I included a bit of code within the Sub Main area that is similar to your own, but shows you not only the TypeName of the object returned by the AssemblyConstraint.EntityOne, but also the TypeName of its 'native/source' object which has been returned from this custom function, so you can see the results.  It seemed to work OK in my testing so far.

Here is the code:

 

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	Dim oConsts As AssemblyConstraints = oADef.Constraints
	For Each oConst As AssemblyConstraint In oConsts
		Dim oEnt1 As Object = oConst.EntityOne
		Dim oEnt1Native As Object = Nothing 'making sure it gets re-set
		If oEnt1 IsNot Nothing Then
			oEnt1Native = GetProxySource(oEnt1)
			MsgBox("TypeName(oEnt1) = " & TypeName(oEnt1) _
			& vbCrLf & "TypeName(oEnt1Native) = " & TypeName(oEnt1Native), vbInformation, "")
		Else
			MsgBox("oEnt1 was Nothing", vbInformation, "")
		End If
		Dim oEnt2 As Object = oConst.EntityTwo
		Dim oEnt2Native As Object = Nothing 'making sure it gets re-set
		If oEnt2 IsNot Nothing Then
			oEnt2Native = GetProxySource(oEnt2)
			MsgBox("TypeName(oEnt2) = " & TypeName(oEnt2) _
			& vbCrLf & "TypeName(oEnt2Native) = " & TypeName(oEnt2Native), vbInformation, "")
		Else
			MsgBox("oEnt2 was Nothing", vbInformation, "")
		End If
	Next
	MsgBox("Done with all constraints.", vbInformation, "")
End Sub

Function GetProxySource(oProxyObj As Object) As Object
	If IsNothing(oProxyObj) Then Return Nothing
	Dim oNativeObject As Object = Nothing
	If TypeName(oProxyObj).EndsWith("Proxy") = False Then
		oNativeObject = oProxyObj
	Else
		oNativeObject = GetProxySource(oProxyObj.NativeObject)
	End If
	Return oNativeObject
End Function

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes