Access Work Surfaces in Assembly

Access Work Surfaces in Assembly

nooraldeen_saleem_JF6Y866E8DSM
Community Visitor Community Visitor
143 Views
2 Replies
Message 1 of 3

Access Work Surfaces in Assembly

nooraldeen_saleem_JF6Y866E8DSM
Community Visitor
Community Visitor

Im trying to do this 

	'Check through each surface in the part and see if it uses the special appearances
	For Each oWrkSurf As WorkSurface In oPartDoc.ComponentDefinition.WorkSurfaces
		For Each oSrfBody As SurfaceBody In oWrkSurf.SurfaceBodies
			For Each oFace As Face In oSrfBody.Faces

I'm aware that SurfaceBodies cannot be created within an assembly. However, I'm trying to access SurfaceBodies that have already been created in a part within the assembly I'm working on. Is this possible, or should I approach this problem differently?

0 Likes
144 Views
2 Replies
Replies (2)
Message 2 of 3

nstevelmans
Advocate
Advocate

Hi,

 

I think you have to go first through each part of the assembly something like this.

 

 ' Get the active assembly.
        Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
        ' Get all of the referenced documents.
        Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments

        ' Iterate through the list of documents.
        Dim oRefDoc As Document
        For Each oRefDoc In oRefDocs
            'Check through each surface in the part and see if it uses the special appearances
            For Each oWrkSurf As WorkSurface In oRefDoc.ComponentDefinition.WorkSurfaces
                For Each oSrfBody As SurfaceBody In oWrkSurf.SurfaceBodies
                    For Each oFace As Face In oSrfBody.Faces
                        Dim ofaceName As String = oFace.InternalName
                        MsgBox(ofaceName)
                    Next
                Next
            Next
        Next

 

If a response answers your question, please use  ACCEPT SOLUTION  to assist other users later.

Also be generous with Likes!  Thank you and enjoy!

 

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Hi @nooraldeen_saleem_JF6Y866E8DSM.  Just to clarify...where was this 'special appearance' applied to the WorkSurface(s)...while editing the part directly, or from within the assembly environment?  If it was applied to those WorkSurface(s) while directly editing each part, then some code similar to the previous example may work OK (with an additional DocumentType check in there to avoid the error of trying to access WorkSurfaces of sub assembly documents).  But if the appearance you are looking for was applied to those WorkSurface(s) from within the assembly environment, then you will need to get access to the 'WorkSurfaceProxy' copy of it that exists within the context of whichever assembly document you were editing directly in when you applied the appearances originally.  If the part was in a sub assembly, and that sub assembly is in your main assembly, and you applied the appearance to it from the top assembly, then you will have to step up two levels of proxy copies to get the one you want (first proxy copy is in the sub assembly, second proxy copy is in the main assembly).  Just so you are aware.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes