Programmer's Guide > Solid Edge > Environments > Assembly > Working with References |
When you work with an assembly document interactively, you can work directly with occurrences and part geometry in subassemblies. For example, you can place relationships between occurrences nested in subassemblies, you can measure distances between faces of occurrences in subassemblies, you can in-place-activate an occurrence within a sub-assembly, and you can apply face styles to occurrences within subassemblies.
Because you can use the Occurrences collection to access occurrences nested in subassemblies, and because you can access the OccurrenceDocument representing a PartDocument and access geometry within the part, it appears simple to use the automation interface to work with occurrences in subassemblies just as you would through the graphical user interface. However, this appearance is deceptive. When you work with occurrences in subassemblies, and when you work with geometry of parts in occurrences (however deeply nested), use the Reference object to create references to part geometry and to nested occurrences from the top-level assembly. Then use the Reference object to place relationships, measure distances, in-placeactivate nested occurrences, apply face styles, and so forth.
You can create Reference objects with the AssemblyDocument.CreateReference method. This method has two input parameters: an occurrence (which must be an Occurrence object), and an entity, which can be one of several different types of objects.
When interactively placing parts in an assembly, you define relationships between parts to control their relative positions. Using the automation interface for the Assembly environment, you can access and modify properties of the assembly relationships.
Relationship objects are accessible through two collections: Relations3d on the AssemblyDocument object and Relations3d on each Part object. The Relations3d collection on the AssemblyDocument allows you to iterate through all relationships in the document. The Relations3d collection on each Part object allows you to iterate through the relationships defined for that specific part.
There are five types of 3-D relationships: AngularRelation3d, AxialRelation3d, GroundRelation3d, PlanarRelation3d, and PointRelation3d. These do not directly correlate to the interactive commands that place relationships. The relationships are as follows:
The following example shows how to use some of these relationship objects. This sample finds all of the PlanarRelation3d objects that define mates and modifies their offset values.
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter. |
Analyzing Assembly Relationships in Visual Basic .NET |
Copy Code
|
---|---|
Imports System.Runtime.InteropServices Module Program <STAThread()> _ Sub Main() Dim objApplication As SolidEdgeFramework.Application = Nothing Dim objAssembly As SolidEdgeAssembly.AssemblyDocument = Nothing Dim objRelations3d As SolidEdgeAssembly.Relations3d = Nothing Dim objRelation3d As Object = Nothing Dim objAngularRelation3d As SolidEdgeAssembly.AngularRelation3d = Nothing Dim objAxialRelation3d As SolidEdgeAssembly.AxialRelation3d = Nothing Dim objGroundRelation3d As SolidEdgeAssembly.GroundRelation3d = Nothing Dim objPointRelation3d As SolidEdgeAssembly.PointRelation3d = Nothing Dim objPlanarRelation3d As SolidEdgeAssembly.PlanarRelation3d = Nothing Try OleMessageFilter.Register() ' Connect to a running instance of Solid Edge objApplication = Marshal.GetActiveObject("SolidEdge.Application") ' Get a reference to the active document objAssembly = objApplication.ActiveDocument ' Get a reference to the relations 3d collection objRelations3d = objAssembly.Relations3d ' Loop through the relations 3d objects For Each objRelation3d In objRelations3d ' Determine the relation type Select Case objRelation3d.Type Case SolidEdgeFramework.ObjectType.igAngularRelation3d objAngularRelation3d = objRelation3d Case SolidEdgeFramework.ObjectType.igAxialRelation3d objAxialRelation3d = objRelation3d Case SolidEdgeFramework.ObjectType.igGroundRelation3d objGroundRelation3d = objRelation3d Case SolidEdgeFramework.ObjectType.igPointRelation3d objPointRelation3d = objRelation3d Case SolidEdgeFramework.ObjectType.igPlanarRelation3d objPlanarRelation3d = objRelation3d End Select Next Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub End Module |
Analyzing Assembly Relationships in C# |
Copy Code
|
---|---|
using SolidEdgeFramework; using System; using System.Reflection; using System.Runtime.InteropServices; namespace SolidEdge.SDK { class Program { [STAThread] static void Main(string[] args) { SolidEdgeFramework.Application application = null; SolidEdgeAssembly.AssemblyDocument assembly = null; SolidEdgeAssembly.Relations3d relations3d = null; object relation3d = null; SolidEdgeAssembly.AngularRelation3d angularRelation3d = null; SolidEdgeAssembly.AxialRelation3d axialRelation3d = null; SolidEdgeAssembly.GroundRelation3d groundRelation3d = null; SolidEdgeAssembly.PointRelation3d pointRelation3d = null; SolidEdgeAssembly.PlanarRelation3d planarRelation3d = null; try { OleMessageFilter.Register(); // Connect to a running instance of Solid Edge application = (SolidEdgeFramework.Application) Marshal.GetActiveObject("SolidEdge.Application"); // Get a reference to the active document assembly = (SolidEdgeAssembly.AssemblyDocument) application.ActiveDocument; // Get a reference to the relations 3d collection relations3d = assembly.Relations3d; // Loop through the relations 3d objects for (int i = 1; i <= relations3d.Count; i++) { relation3d = relations3d.Item(i); Type type = relation3d.GetType(); // Get the value of the Type proprety via Reflection SolidEdgeFramework.ObjectType objectType = (SolidEdgeFramework.ObjectType)type.InvokeMember( "Type", BindingFlags.GetProperty, null, relation3d, null); // Determine the relation type switch (objectType) { case SolidEdgeFramework.ObjectType.igAngularRelation3d: angularRelation3d = (SolidEdgeAssembly.AngularRelation3d) relation3d; break; case SolidEdgeFramework.ObjectType.igAxialRelation3d: axialRelation3d = (SolidEdgeAssembly.AxialRelation3d) relation3d; break; case SolidEdgeFramework.ObjectType.igGroundRelation3d: groundRelation3d = (SolidEdgeAssembly.GroundRelation3d) relation3d; break; case SolidEdgeFramework.ObjectType.igPointRelation3d: pointRelation3d = (SolidEdgeAssembly.PointRelation3d) relation3d; break; case SolidEdgeFramework.ObjectType.igPlanarRelation3d: planarRelation3d = (SolidEdgeAssembly.PlanarRelation3d) relation3d; break; } } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { OleMessageFilter.Revoke(); } } } } |
There are five methods to define assembly relationships through the automation interface: AddAngular, AddAxial, AddGround, AddPlanar, and AddPoint. These do not exactly correspond with the assembly relationship commands that are available interactively. However, they do correspond to the relationships that the interactive commands create.
For example, the AddPlanar method can be used to create either a Mate or an Align. The inputs to the AddPlanar method are two reference objects which are described below (but they correspond to the faces being mated or aligned), a Boolean that specifies whether or not the normals to the faces are aligned (this determines whether the faces are mated or aligned), and constraining points on each face (that correspond to the locations where you would click to locate the faces when you work interactively).
The following sample demonstrates the AddAxial method. This produces the same relationship that the interactive Align command produces when you align cylindrical faces. The inputs to this method are similar to those for the AddPlanar method. The first two inputs are reference objects that represent the cylindrical faces being aligned, and the third input is the Boolean that specifies whether normals to these faces are aligned. This method does not have input parameters for the constraining points the AddPlanar method uses.
To programmatically create the relationships that the Insert interactive command creates, you would use the AddPlanar and AddAxial methods. This would define the two cylindrical faces whose axes are aligned, and it would define the two planar faces that are mated. To remove the final degree of freedom, you would edit the axial relationship and set its FixedRotate property to True.
To create a Connect relationship, use the AddPoint method. The first input parameter is a reference object corresponding to the face or edge on the first part; the second input parameter is a constant that defines which key point from the input geometry defines the connection point (for example, CenterPoint, EndPoint, MidPoint, and so forth); and the third and fourth input parameters describe the same characteristics of the second part.
Within this general description, there are some important refinements. The methods previously described refer to reference objects, which correspond to part geometry. Each Assembly relationship must store a means of retrieving the geometric Part information that defines it. When using the AddPlanar method, for example, you need to pass in references to two planar faces (or reference planes).
The AssemblyDocument object has a CreateReference method whose job is to create the reference objects. The CreateReference method takes as input an Occurrence (an object that represents a member document of the assembly—which in this case would be a part document) and an Entity. The Entity can be an Edge, Face, or RefPlane object from the Occurrence document. The Reference object stores a path to the geometric representations necessary to construct the relationships.
To create assembly relationships via the automation interface, Occurrence objects (the Part and Subassembly models that comprise the assembly) must be placed in the Assembly document. You do this with the AssemblyDocument.Occurrances.AddByFilename method. This places the Occurrence in the assembly with a ground relationship. Therefore, (except for the first Occurrence added to the assembly) before any other relationships can be applied between this Occurrence and others in the assembly, the ground relationship must be deleted.
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter. |
Adding New Assembly Relationship in Visual Basic .NET |
Copy Code
|
---|---|
Imports SolidEdgeGeometry 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 objOccurrence1 As SolidEdgeAssembly.Occurrence = Nothing Dim objOccurrence2 As SolidEdgeAssembly.Occurrence = Nothing Dim objPart As SolidEdgePart.PartDocument = Nothing Dim objModels As SolidEdgePart.Models = Nothing Dim objModel As SolidEdgePart.Model = Nothing Dim objRevolvedProtrusions As SolidEdgePart.RevolvedProtrusions = Nothing Dim objRevolvedProtrusion As SolidEdgePart.RevolvedProtrusion = Nothing Dim objRevolvedCutouts As SolidEdgePart.RevolvedCutouts = Nothing Dim objRevolvedCutout As SolidEdgePart.RevolvedCutout = Nothing Dim objFaces As SolidEdgeGeometry.Faces = Nothing Dim objFace As SolidEdgeGeometry.Face = Nothing Dim objGeometry As Object = Nothing Dim objScrewConicalFace As SolidEdgeGeometry.Face = Nothing Dim objNutConicalFace As SolidEdgeGeometry.Face = Nothing Dim objRefToCylinderInScrew As SolidEdgeFramework.Reference = Nothing Dim objRefToConeInNut As SolidEdgeFramework.Reference = Nothing Dim objRelations3d As SolidEdgeAssembly.Relations3d = Nothing Dim objGroundRel As SolidEdgeAssembly.GroundRelation3d = Nothing Dim objRelNuttoScrew As SolidEdgeAssembly.AxialRelation3d = 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 occurrence objOccurrence1 = objOccurrences.AddByFilename("C:\Screw.par") ' Get a reference to the occurrence document objPart = objOccurrence1.OccurrenceDocument ' Get a reference to the models collection objModels = objPart.Models ' Get a reference to the one and only model objModel = objModels.Item(1) ' Get a reference to the revolved protrusions collection objRevolvedProtrusions = objModel.RevolvedProtrusions ' Get a reference to the first revolved protrusion objRevolvedProtrusion = objRevolvedProtrusions.Item(1) ' Get a reference to the side faces collection objFaces = objRevolvedProtrusion.SideFaces ' Loop through the faces For Each objFace In objFaces ' Get a reference to the geometry object objGeometry = objFace.Geometry If objGeometry.Type = GNTTypePropertyConstants.igCylinder Then objScrewConicalFace = objFace Exit For End If Next ' Create the first reference objRefToCylinderInScrew = objAssembly.CreateReference( _ objOccurrence1, objScrewConicalFace) ' Add the second occurrence objOccurrence2 = objOccurrences.AddByFilename("C:\Nut.par") ' Get a reference to the occurrence document objPart = objOccurrence2.OccurrenceDocument ' Get a reference to the models collection objModels = objPart.Models ' Get a reference to the one and only model objModel = objModels.Item(1) ' Get a reference to the revolved cutouts collection objRevolvedCutouts = objModel.RevolvedCutouts ' Get a reference to the first revolved cutout objRevolvedCutout = objRevolvedCutouts.Item(1) ' Get a reference to the side faces collection objFaces = objRevolvedCutout.SideFaces ' Loop through the faces For Each objFace In objFaces objGeometry = objFace.Geometry If objGeometry.Type = GNTTypePropertyConstants.igCone Then objNutConicalFace = objFace Exit For End If Next ' Create the second reference objRefToConeInNut = objAssembly.CreateReference( _ objOccurrence2, objNutConicalFace) ' All Occurrences placed through automation are placed "Grounded." ' You must delete the ground constraint on the second Occurrence ' before you can place other relationships. objRelations3d = objAssembly.Relations3d objGroundRel = objRelations3d.Item(2) objGroundRel.Delete() ' Rather than passing literal axes to the AddAxial method, pass ' references to conical faces, Just as you select conical faces ' when you use the interactive Align command. objRelNuttoScrew = objRelations3d.AddAxial( _ objRefToConeInNut, objRefToCylinderInScrew, False) Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub End Module |
Adding New Assembly Relationship in C# |
Copy Code
|
---|---|
using SolidEdgeFramework; using SolidEdgeGeometry; 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; SolidEdgePart.PartDocument part = null; SolidEdgePart.Models models = null; SolidEdgePart.Model model = null; SolidEdgePart.RevolvedProtrusions revolvedProtrusions = null; SolidEdgePart.RevolvedProtrusion revolvedProtrusion = null; SolidEdgePart.RevolvedCutouts revolvedCutouts = null; SolidEdgePart.RevolvedCutout revolvedCutout = null; SolidEdgeGeometry.Faces faces = null; SolidEdgeGeometry.Face face = null; object geometry = null; SolidEdgeGeometry.Face screwConicalFace = null; SolidEdgeGeometry.Face nutConicalFace = null; SolidEdgeFramework.Reference refToCylinderInScrew = null; SolidEdgeFramework.Reference refToConeInNut = null; SolidEdgeAssembly.Relations3d relations3d = null; SolidEdgeAssembly.GroundRelation3d groundRelation3d = null; SolidEdgeAssembly.AxialRelation3d relNuttoScrew = 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; // Get a reference to the active document assembly = (SolidEdgeAssembly.AssemblyDocument) documents.Add("SolidEdge.AssemblyDocument", Missing.Value); // Get a reference to the occurrences collection occurrences = assembly.Occurrences; // Add the first occurrence occurrence1 = occurrences.AddByFilename(@"C:\Screw.par", Missing.Value); // 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; // Get a reference to the active document assembly = (SolidEdgeAssembly.AssemblyDocument) documents.Add("SolidEdge.AssemblyDocument", Missing.Value); // Get a reference to the occurrences collection occurrences = assembly.Occurrences; // Add the first occurrence occurrence1 = occurrences.AddByFilename(@"C:\Screw.par", Missing.Value); // Get a reference to the one and only model model = models.Item(1); // Get a reference to the revolved cutouts collection revolvedCutouts = model.RevolvedCutouts; // Get a reference to the first revolved cutout revolvedCutout = revolvedCutouts.Item(1); // Get a reference to the side faces collection faces = (SolidEdgeGeometry.Faces)revolvedCutout.SideFaces; // Loop through the faces for (int i = 1; i <= faces.Count; i++) { // Get a reference to the face object face = (SolidEdgeGeometry.Face)faces.Item(i); // Get a reference to the geometry object geometry = face.Geometry; // Determine the face type GNTTypePropertyConstants typeProperty = (GNTTypePropertyConstants) geometry.GetType().InvokeMember( "Type", BindingFlags.GetProperty, null, geometry, null); if (typeProperty == GNTTypePropertyConstants.igCone) { nutConicalFace = face; break; } } // Create the second reference refToConeInNut = (SolidEdgeFramework.Reference) assembly.CreateReference(occurrence2, nutConicalFace); // All Occurrences placed through automation are placed "Grounded." // You must delete the ground constraint on the second Occurrence // before you can place other relationships. relations3d = assembly.Relations3d; groundRelation3d = (SolidEdgeAssembly.GroundRelation3d) relations3d.Item(2); groundRelation3d.Delete(); // Rather than passing literal axes to the AddAxial method, pass // references to conical faces, Just as you select conical faces // when you use the interactive Align command. relNuttoScrew = relations3d.AddAxial( refToConeInNut, refToCylinderInScrew, false); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { OleMessageFilter.Revoke(); } } } } |