Reply
Solved! Go to solution

Open assembly and edit occurence

I have a programmer who open an assembly, read the occurence, then open each occurence.

 

Problem is some of the occurence has inter-part copy so when we open them we are being ask to open the top assembly as well to resolve the inter-part copy.

 

 

What we are looking to achieve is to open the top assembly, read occurence then edit in place each of them so we can inspect part's pathfinder to look for feature with a custome name and retrieve that name.

 

 

So if someone could share some code or give pointers what we need to do that would be appreciate.

 

Thank you

 

 

2 REPLIES
Solution
Solution
Accepted by topic author SolidDNA
‎08-26-2015 04:32 AM

Luc, if you only want to read the feature names of each (...

Luc,

if you only want to read the feature names of each (sub)part in the active assembly, you don't need to in-place activate each document. The API allows to access the features of the (sub)parts directly:

'----------------------------------------------------------------------
' PAR: Dump the feature name of all occurrences in active assembly
'----------------------------------------------------------------------
Dim objDoc As AssemblyDocument = objApp.ActiveDocument
For Each objOcc As Occurrence In objDoc.Occurrences
  DumpFeatures(objOcc)
Next

...

Sub DumpFeatures(ByVal objOcc As Occurrence)
  If objOcc.Subassembly Then
    Dim objDoc As AssemblyDocument = objOcc.OccurrenceDocument
    For Each objOcc2 As Occurrence In objDoc.Occurrences
      DumpFeatures(objOcc2)
    Next
  Else
    Console.WriteLine("Occurrence:  {0} [{1}]", objOcc.Name, objOcc.OccurrenceFileName)
    Dim objDoc As PartDocument = objOcc.OccurrenceDocument
    For Each objFeat In objDoc.DesignEdgebarFeatures
      Dim featName As String = objFeat.GetType().InvokeMember("EdgebarName", Reflection.BindingFlags.GetProperty, Nothing, objFeat, Nothing)
      Console.WriteLine("   Feature:  {0}", featName)
    Next
  End If
End Sub

 If you really need to IPA the (sub)occurrences, then you would do the following:

Dim objDoc As AssemblyDocument = objApp.ActiveDocument
For Each objOcc As Occurrence In objDoc.Occurrences
  objOcc.Select(True)
  objApp.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyEditActivateembeddedorlinkedobject)
  objApp.DoIdle()
  Dim objDocType As Integer = objApp.ActiveDocumentType
  If objDocType = DocumentTypeConstants.igPartDocument Then
    Dim objPartDoc As PartDocument = objApp.ActiveDocument
    Console.WriteLine("Document:  {0}", objPartDoc.FullName)
    For Each objFeat In objDoc.DesignEdgebarFeatures
      Dim featName As String = objFeat.GetType().InvokeMember("EdgebarName", Reflection.BindingFlags.GetProperty, Nothing, objFeat, Nothing)
      Console.WriteLine("   Feature:  {0}", featName)
    Next
  Else
    ' Call it recursively on all subassemblies... (TO BE DONE)
  End If
  objApp.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyFileCloseandReturn)
  objApp.DoIdle()
Next

 

Re: Open assembly and edit occurence

Follow up on this question, We now need to copy that assembly to another location. However since we have inter-part copy a new window pop-up asking ..what do you want to do with the inter-part copy ( three choice) then we need to press OK to continue performing the action.

So the question now is.. what code do we need to use to copy that assembly using the rev manager ( this section is being resolve) and not having the inter-part link window pop-up. (the new question :-) )