Programmer's Guide > Solid Edge > Environments > Draft > Working with Symbols |
Symbols are documents that contain graphic elements. You can place these documents at a specified scale, position, and orientation. The document that contains the graphic elements is the source document; the document into which the source is placed is the container document. A source document is represented in a container document by a symbol. The symbol references the source document as the COM object. Using symbols, you can store a drawing of a nut, bolt, or screw in one document and place it in several documents at a user-defined size. In addition, symbols have the following benefits:
On the Insert menu, click Object to place a symbol in the interactive environment. When using Solid Edge though automation, you can place a symbol using the methods associated with the Symbols collection.
The Symbols collection object provides methods that enable you to place new symbols and to query for information about existing ones. The Symbol2d object provides methods and properties to enable you to review or manipulate the symbol geometry, the attachment between the symbol and the source document, and the user properties. You can also move and copy symbols.
You can place a symbol from any source document that is implemented as an ActiveX object. For example, a source document could be a Microsoft Word file, an Excel spreadsheet, or a Solid Edge document.
When you place a symbol, you must specify an insertion type. The insertion type affects the way the symbol is updated. Three options are available:
See Handling 'Application is Busy' and 'Call was Rejected By Callee' errors for information regarding the use of OleMessageFilter. |
Symbols in Visual Basic .NET |
Copy Code
|
---|---|
Imports SolidEdgeConstants Imports SolidEdgeDraft Imports System.Runtime.InteropServices Module Program <STAThread()> _ Sub Main() Dim objApplication As SolidEdgeFramework.Application = Nothing Dim objDocuments As SolidEdgeFramework.Documents = Nothing Dim objDraft As SolidEdgeDraft.DraftDocument = Nothing Dim objSheet As SolidEdgeDraft.Sheet = Nothing Dim objSymbols As SolidEdgeFramework.Symbols = Nothing Dim objSymbol1 As SolidEdgeFramework.Symbol2d = Nothing Dim objSymbol2 As SolidEdgeFramework.Symbol2d = Nothing Dim objSymbol3 As SolidEdgeFramework.Symbol2d = Nothing Dim x As Double Dim y As Double Dim strSourceDoc As String Dim objWordDoc As Object = Nothing Dim objWordApp As Object = 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 ' Add a Draft document objDraft = objDocuments.Add("SolidEdge.DraftDocument") ' Get a reference to the active sheet objSheet = objDraft.ActiveSheet ' Get a reference to the symbols collection objSymbols = objSheet.Symbols ' Create a linked symbol objSymbol1 = objSymbols.Add( _ OLEInsertionTypeConstant.igOLELinked, _ "C:\MyFile.doc", 0.1, 0.1) ' Create a embedded symbol objSymbol2 = objSymbols.Add( _ OLEInsertionTypeConstant.igOLEEmbedded, _ "C:\MyFile.doc", 0.1, 0.2) ' Create a shared embedded symbol objSymbol3 = objSymbols.Add( _ OLEInsertionTypeConstant.igOLESharedEmbedded, _ "C:\MyFile.doc", 0.1, 0.3) ' Retrieve the origin of the first symbol objSymbol1.GetOrigin(x, y) ' Modify the first symbol's origin objSymbol1.SetOrigin(x + 0.1, y + 0.1) ' Set the angle of rotation of the first symbol to 45 degrees ' (in radians) objSymbol1.Angle = 45 * (Math.PI / 180) ' Find the path to the linked document If objSymbol1.OLEType = OLEInsertionTypeConstant.igOLELinked Then strSourceDoc = objSymbol1.SourceDoc End If ' Open the source document to modify it objSymbol1.DoVerb( _ SolidEdgeConstants.StandardOLEVerbConstants.igOLEOpen) ' In this case, we know that we're dealing with a word document ' Get a reference the source document dispatch interface ' At this point, you can use the Word API to manipulate the document objWordDoc = objSymbol1.Object ' Get a reference to the word application object objWordApp = objWordDoc.Application ' Save and close the word document objWordDoc.Save() objWordDoc.Close() ' Quit word objWordApp.Quit() Catch ex As Exception Console.WriteLine(ex.Message) Finally OleMessageFilter.Revoke() End Try End Sub End Module |
Symbols 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; SolidEdgeFramework.Documents documents = null; SolidEdgeDraft.DraftDocument draft = null; SolidEdgeDraft.Sheet sheet = null; SolidEdgeFramework.Symbols symbols = null; SolidEdgeFramework.Symbol2d symbol1 = null; SolidEdgeFramework.Symbol2d symbol2 = null; SolidEdgeFramework.Symbol2d symbol3 = null; double x = 0; double y = 0; string strSouceDoc; object wordDoc = null; object wordApp = 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; // Add a Draft document draft = (SolidEdgeDraft.DraftDocument) documents.Add("SolidEdge.DraftDocument", Missing.Value); // Get a reference to the active sheet sheet = draft.ActiveSheet; // Get a reference to the symbols collection symbols = (SolidEdgeFramework.Symbols)sheet.Symbols; // Create a linked symbol symbol1 = symbols.Add( (int)OLEInsertionTypeConstant.igOLELinked, @"C:\MyFile.doc", 0.1, 0.1, Missing.Value); // Create a embedded symbol symbol2 = symbols.Add( (int)OLEInsertionTypeConstant.igOLEEmbedded, @"C:\MyFile.doc", 0.1, 0.2, Missing.Value); // Create a shared embedded symbol symbol3 = symbols.Add( (int)OLEInsertionTypeConstant.igOLESharedEmbedded, @"C:\MyFile.doc", 0.1, 0.3, Missing.Value); // Retrieve the origin of the first symbol symbol1.GetOrigin(out x, out y); // Modify the first symbol's origin symbol1.SetOrigin(x + 0.2, y + 0.2); // Set the angle of rotation of the first symbol to 45 degrees // (in radians) symbol1.Angle = 45 * (Math.PI / 180); // Find the path to the linked document if (symbol1.OLEType == OLEInsertionTypeConstant.igOLELinked) { strSouceDoc = symbol1.SourceDoc; } // Open the source document to modify it symbol1.DoVerb( SolidEdgeConstants.StandardOLEVerbConstants.igOLEOpen); // In this case, we know that we're dealing with a word document // Get a reference the source document dispatch interface // At this point, you can use the Word API to manipulate the document wordDoc = symbol1.Object; // Get a reference to the word application object wordApp = wordDoc.GetType().InvokeMember( "Application", BindingFlags.GetProperty, null, wordDoc, null); // Save and close the word document wordDoc.GetType().InvokeMember( "Save", BindingFlags.InvokeMethod, null, wordDoc, null); wordDoc.GetType().InvokeMember( "Close", BindingFlags.InvokeMethod, null, wordDoc, null); // Quit word wordApp.GetType().InvokeMember( "Quit", BindingFlags.InvokeMethod, null, wordApp, null); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { OleMessageFilter.Revoke(); } } } } |