Open assembly and edit occurence

PLM World Member Genius PLM World Member Genius
PLM World Member Genius

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

 

 

4 REPLIES

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

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

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

PLM World Member Genius PLM World Member Genius
PLM World Member Genius
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 :-) )

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

Pioneer
Pioneer

Hi Martin,

 

How to stop displaying the IPA action to the user ? 

Also how to insert the occurrences in subassembly ? As I am facing the issues while selecting the occurrence object for the same.

 

I don't want to show the user that what I am doing for inserting components.

 

Thanks,

Onkar

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

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

If you need to insert new occurrences in a subassembly, you don't need to IPA that subassembly, but can simply add a new occurrence to the Occurrences collection of the subassembly document.

  '----------------------------------------------------------------------
  ' ASM: Create a 2-level simplified car assembly without IPA
  ' NOTE: Make sure that the folder "C:\TEMP\Car" exists and is empty 
  '       on your computer!
  '----------------------------------------------------------------------
  Dim strTempFolder As String = "C:\TEMP\Car\"
  Dim strAsmTemplate As String = objApp.GetDefaultTemplatePath(DocumentTypeConstants.igAssemblyDocument)
  Dim strParTemplate As String = objApp.GetDefaultTemplatePath(DocumentTypeConstants.igPartDocument)
  ' Hide Solid Edge
  'objApp.Visible = False
  'objApp.Interactive = False
  ' Create the CAR assembly
  Dim objCarDoc As AssemblyDocument = objApp.Documents.Add("SolidEdge.AssemblyDocument")
  Dim objFrontAxleOcc As Occurrence = objCarDoc.Occurrences.AddByTemplate(strTempFolder + "Axle.asm", strAsmTemplate)
  objFrontAxleOcc.Move(1.5, 0, 0.25)
  Dim objBackAxleOcc As Occurrence = objCarDoc.Occurrences.AddWithTransform(strTempFolder + "Axle.asm", -1.5, 0, 0.25, 0, 0, 0)
  ' Create the AXLE assembly
  Dim objAxleDoc As AssemblyDocument = objFrontAxleOcc.OccurrenceDocument
  Dim objLeftWheelOcc As Occurrence = objAxleDoc.Occurrences.AddByTemplate(strTempFolder + "Wheel.par", strParTemplate)
  objLeftWheelOcc.Move(0, 1, 0)
  Dim objRightWheelOcc As Occurrence = objAxleDoc.Occurrences.AddWithTransform(strTempFolder + "Wheel.par", 0, -1, 0, 0, 0, 0)
  Dim objAxOcc As Occurrence = objAxleDoc.Occurrences.AddByTemplate(strTempFolder + "Axle.par", strParTemplate)
  ' Create the WHEEL part (as a simple cylinder)
  Dim objWheelDoc As PartDocument = objLeftWheelOcc.OccurrenceDocument
  objWheelDoc.ModelingMode = ModelingModeConstants.seModelingModeOrdered
  Dim objProfileSet As ProfileSet = objWheelDoc.ProfileSets.Add()
  Dim objProfile As Profile = objProfileSet.Profiles.Add(objWheelDoc.RefPlanes.Item(3))
  objProfile.Circles2d.AddByCenterRadius(0, 0, 0.25)
  objProfile.End(ProfileValidationType.igProfileClosed)
  objProfile.Visible = False
  Dim objProfiles() As Profile = {objProfile}
  objWheelDoc.Models.AddFiniteExtrudedProtrusion(1, objProfiles, FeaturePropertyConstants.igSymmetric, 0.2)
  ' Create the AXLE part (as a simple cylinder)
  Dim objAxDoc As PartDocument = objAxOcc.OccurrenceDocument
  objAxDoc.ModelingMode = ModelingModeConstants.seModelingModeOrdered
  Dim objProfileSet2 = objAxDoc.ProfileSets.Add()
  Dim objProfile2 As Profile = objProfileSet2.Profiles.Add(objAxDoc.RefPlanes.Item(3))
  objProfile2.Circles2d.AddByCenterRadius(0, 0, 0.05)
  objProfile2.End(ProfileValidationType.igProfileClosed)
  objProfile2.Visible = False
  Dim objProfiles2() As Profile = {objProfile2}
  objAxDoc.Models.AddFiniteExtrudedProtrusion(1, objProfiles2, FeaturePropertyConstants.igSymmetric, 1.8)
  ' Show Solid Edge again
  objApp.Interactive = True
  objApp.Visible = True
  ' Fit the view
  objApp.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyViewFit)