Programmer's Guide > Solid Edge > Environments > Assembly > Working with Occurrences |
The Occurrence object represents an instance of a part or subassembly within an assembly. It is an OLE link to a part or assembly document. An Occurrence object can only be added to an assembly through an Occurrences collection object.
The automation interface for the assembly environment allows you to place parts and subassemblies into an assembly. This is handled by the AddByFilename method, which is provided on the Occurrences collection object. Parts and subassemblies are differentiated by the Subassembly property on each Occurrence object. The following example shows how to place a part into an assembly.
Parts or subassemblies are initially placed into the assembly at the same location and position they maintain in their original files. The following illustration shows a block and its position relative to the three initial global reference planes. The block is positioned so its corner is at the coordinate (0,0,0). When this part is placed into an assembly using the AddByFilename method, it is placed in the same location and orientation in the assembly file as it existed in the original part file. Subassemblies follow the same rules.
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter. |
Adding a new Occurrence in Visual Basic .NET |
Copy Code
|
---|---|
Imports SolidEdgeConstants Imports System.Runtime.InteropServices Module Program <STAThread()> _ Sub Main() Dim objApplication As SolidEdgeFramework.Application = Nothing Dim objDocuments As SolidEdgeFramework.Documents = Nothing Dim objAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing Try OleMessageFilter.Register() ' Connect to a running instance of Solid Edge objApplication = Marshal.GetActiveObject("SolidEdge.Application") ' Get a reference to the documents collection objDocuments = objApplication.Documents ' Create a new assembly document objAssembly = objDocuments.Add("SolidEdge.AssemblyDocument") ' Get a reference to the occurrences collection objOccurrences = objAssembly.Occurrences ' Add a part document to the assembly objOccurrence = objOccurrences.AddByFilename("C:\Part1.par") Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub End Module |
Adding a new Occurrence in C# |
Copy Code
|
---|---|
using System; using System.Reflection; using System.Runtime.InteropServices; namespace SolidEdge.SDK { class Program { [STAThread] static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeAssembly.AssemblyDocument assembly = null; SolidEdgeAssembly.Occurrences occurrences = null; SolidEdgeAssembly.Occurrence occurrence = null; try { OleMessageFilter.Register(); // Connect to a running instance of Solid Edge application = (SolidEdgeFramework.Application) Marshal.GetActiveObject("SolidEdge.Application"); // Get a reference to the documents collection documents = application.Documents; // Create a new assembly document assembly = (SolidEdgeAssembly.AssemblyDocument) documents.Add("SolidEdge.AssemblyDocument", Missing.Value); // Get a reference to the occurrences collection occurrences = assembly.Occurrences; // Add a part document to the assembly occurrence = occurrences.AddByFilename(@"C:\Part1.par", Missing.Value); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { OleMessageFilter.Revoke(); } } } } |
Because occurrences are placed in the same relative location and orientation in which they were initially created, you will typically change the part or subassembly’s position and orientation after placement. These methods apply only to grounded occurrences. Occurrences that are placed with relationships to other occurrences have their location and orientation defined by their relationships to the other occurrences.
To show how to use these methods, consider a block with dimensions of 100 mm in the x axis, 100 mm in the y axis, and 50 mm in the z axis. Assume that you need to place three of these parts to result in the following assembly:
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter. |
Manipulating Occurrences in Visual Basic .NET |
Copy Code
|
---|---|
Imports SolidEdgeConstants Imports System.Runtime.InteropServices Module Program <STAThread()> _ Sub Main() Dim objApplication As SolidEdgeFramework.Application = Nothing Dim objDocuments As SolidEdgeFramework.Documents = Nothing Dim objAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing Dim objOccurrences As SolidEdgeAssembly.Occurrences = Nothing Dim objOccurrence As SolidEdgeAssembly.Occurrence = Nothing Dim objOccurrence1 As SolidEdgeAssembly.Occurrence = Nothing Dim objOccurrence2 As SolidEdgeAssembly.Occurrence = Nothing Dim objOccurrence3 As SolidEdgeAssembly.Occurrence = Nothing Try OleMessageFilter.Register() ' Connect to a running instance of Solid Edge objApplication = Marshal.GetActiveObject("SolidEdge.Application") ' Get a reference to the documents collection objDocuments = objApplication.Documents ' Create a new assembly document objAssembly = objDocuments.Add("SolidEdge.AssemblyDocument") ' Get a reference to the occurrences collection objOccurrences = objAssembly.Occurrences ' Add the first block to the assembly objOccurrence1 = objOccurrences.AddByFilename("C:\Part1.par") ' Add the second block to the assembly objOccurrence2 = objOccurrences.AddByFilename("C:\Part1.par") ' It is currently in the same position and orientation as the first ' block, so reposition it objOccurrence2.Move(0, 0, 0.05) ' Add the third block to the assembly objOccurrence3 = objOccurrences.AddByFilename("C:\Part1.par") ' Rotate the third block to a vertical position. objOccurrence3.Rotate(0, 0, 0, 0, 1, 0, -Math.PI / 2) ' Reposition the third block. objOccurrence3.Move(-0.049, 0, 0.049) Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub End Module |
Manipulating Occurrences in C# |
Copy Code
|
---|---|
using System; using System.Reflection; using System.Runtime.InteropServices; namespace SolidEdge.SDK { class Program { [STAThread] static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeFramework.Documents documents = null; SolidEdgeAssembly.AssemblyDocument assembly = null; SolidEdgeAssembly.Occurrences occurrences = null; SolidEdgeAssembly.Occurrence occurrence1 = null; SolidEdgeAssembly.Occurrence occurrence2 = null; SolidEdgeAssembly.Occurrence occurrence3 = null; try { OleMessageFilter.Register(); // Connect to a running instance of Solid Edge application = (SolidEdgeFramework.Application) Marshal.GetActiveObject("SolidEdge.Application"); // Get a reference to the documents collection documents = application.Documents; // Create a new assembly document assembly = (SolidEdgeAssembly.AssemblyDocument) documents.Add("SolidEdge.AssemblyDocument", Missing.Value); // Get a reference to the occurrences collection occurrences = assembly.Occurrences; // Add the first block to the assembly occurrence1 = occurrences.AddByFilename(@"C:\Part1.par", Missing.Value); // Add the second block to the assembly occurrence2 = occurrences.AddByFilename(@"C:\Part1.par", Missing.Value); // It is currently in the same position and orientation as the first // block, so reposition it occurrence2.Move(0, 0, 0.05); // Add the third block to the assembly occurrence3 = occurrences.AddByFilename(@"C:\Part1.par", Missing.Value); // Rotate the third block to a vertical position. occurrence3.Rotate(0, 0, 0, 0, 1, 0, -Math.PI / 2); // Reposition the third block. occurrence3.Move(-0.049, 0, 0.049); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { OleMessageFilter.Revoke(); } } } } |
The following illustration shows the assembly after placing the second block and moving it into place:
And after placing the third block, rotating it, and moving it into place, the assembly is as follows:
This example positions the blocks using the Move method. You can also use the SetOrigin method, which is available on the Occurrence object, to move occurrences. SetOrigin works together with GetOrigin; GetOrigin returns the coordinates of the occurrence origin with respect to the assembly origin, and SetOrigin positions the occurrence's origin relative to the assembly's origin.