-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh8_Linking&Embedding_Ex.ipy
More file actions
90 lines (82 loc) · 2.95 KB
/
Copy pathCh8_Linking&Embedding_Ex.ipy
File metadata and controls
90 lines (82 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# Ch8_Linking&Embedding_Ex.ipy v.0.1
# The original examples writen in VB.NET and C# can be found in
# Solid Edge Programmer's Guide or in .NET Programmer's Guide
# for Solid Edge (Solid_Edge_API_tcm78-125829.pdf).
#
# Author: Rlee13
# This file is part of IronPython Examples for Solid Edge ST6.
# An up to date version of the software is to be found at:
# https://github.com/Rlee13/
#
# Freeware. For educational purposes only, use it at your own risk.
#
# The program requires Interop.SolidEdge.dll to be copied in its
# folder. The DLL is part of Jason Hewell's project and can be
# downloaded from http://solidedgeinterop.codeplex.com/
# Tested with IronPython 2.7.4 on .NET 4.0 and Solid Edge ST6.
#
# The file has the extension .ipy which is a personal preference,
# feel free to changed it to any other extension.
# Simply run:
# ipy.exe filename.ipy
#
# History:
# 11.12.13 - Ch8_Linking&Embedding_Ex.ipy v.0.1
#
import clr
clr.AddReference("Interop.SolidEdge")
clr.AddReference("System.Runtime.InteropServices")
import SolidEdgeDraft as SEDraft
import System.Runtime.InteropServices as SRI
# It is not really required one can use #print#
from System import Console
objApplication = None
objDocuments = None
objDraft = None
objSheet = None
objSmartFrames2d = None
objSmartFrame2d = None
try:
# Connect to a running instance of Solid Edge
objApplication = SRI.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 smart frames 2d collection
objSmartFrames2d = objSheet.SmartFrames2d
# Create a SmartFrame2d object by two points.
objSmartFrame2d = objSmartFrames2d.AddBy2Points( "", 0.05, 0.05, 0.1, 0.1)
# Add a description to the SmartFrame
objSmartFrame2d.Description = "My SmartFrame2d"
# Embed document within the SmartFrame
# It needs a fully qualified path
# Check your Firewall permissions
objSmartFrame2d.CreateEmbed("C:\MyFile.doc")
# or
# Link document within the SmartFrame
#objSmartFrame2d.CreateLink("C:\MyFile.doc")
except Exception, ex:
Console.WriteLine(ex)
finally:
if objSmartFrame2d is not None:
SRI.Marshal.ReleaseComObject(objSmartFrame2d)
objSmartFrame2d = None
if objSmartFrames2d is not None:
SRI.Marshal.ReleaseComObject(objSmartFrames2d)
objSmartFrames2d = None
if objSheet is not None:
SRI.Marshal.ReleaseComObject(objSheet)
objSheet = None
if objDraft is not None:
SRI.Marshal.ReleaseComObject(objDraft)
objDraft = None
if objDocuments is not None:
SRI.Marshal.ReleaseComObject(objDocuments)
objDocuments = None
if objApplication is not None:
SRI.Marshal.ReleaseComObject(objApplication)
objApplication = None