-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh7_CreatingReferenceElements_Ex.ipy
More file actions
119 lines (107 loc) · 3.87 KB
/
Copy pathCh7_CreatingReferenceElements_Ex.ipy
File metadata and controls
119 lines (107 loc) · 3.87 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#
# Ch7_CreatingReferenceElements_Ex.ipy.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 - Ch7_CreatingReferenceElements_Ex.ipy v.0.1
#
import clr
clr.AddReference("Interop.SolidEdge")
clr.AddReference("System.Runtime.InteropServices")
import SolidEdgeDraft as SEDraft
import SolidEdgeFramework as SEFramework
import SolidEdgeConstants as SEConstants
import SolidEdgePart as SEPart
import System.Runtime.InteropServices as SRI
# Console it is not really required as one can use "print"
from System import Console
import math
objApplication = None
objDocuments = None
objAssembly = None
objAsmRefPlanes = None
objAsmRefPlane = None
objPPlane = None
objPart = None
objRefPlanes = None
objRefPlane = None
try:
# Connect to a running instance of Solid Edge
objApplication = SRI.Marshal.GetActiveObject("SolidEdge.Application")
# Access the Documents collection object
objDocuments = objApplication.Documents
# Add an Assembly document
objAssembly = objDocuments.Add("SolidEdge.AssemblyDocument")
# Access the AsmRefPlanes collection object
objAsmRefPlanes = objAssembly.AsmRefPlanes
# Create a reference plane at an angle to a
# principal reference plane
objPPlane = objAsmRefPlanes.Item(2)
# Add a new reference plane
objAsmRefPlane = objAsmRefPlanes.AddAngularByAngle(
objPPlane,
(2 * math.pi / 3),
objAsmRefPlanes.Item(1),
SEConstants.ReferenceElementConstants.igPivotEnd,
SEConstants.ReferenceElementConstants.igNormalSide,
True)
objAsmRefPlane.Name = "NewPlaneName"
# Add a Part document
objPart = objDocuments.Add("SolidEdge.PartDocument")
# Access the RefPlanes collection object
objRefPlanes = objPart.RefPlanes
# Create a global reference plane parallel to the top reference plane
objRefPlane = objRefPlanes.AddParallelByDistance(
objRefPlanes.Item(1),
0.1,
SEConstants.ReferenceElementConstants.igNormalSide,
False)
except Exception, ex:
Console.WriteLine(ex)
finally:
if objRefPlane is not None:
SRI.Marshal.ReleaseComObject(objRefPlane)
objRefPlane = None
if objRefPlanes is not None:
SRI.Marshal.ReleaseComObject(objRefPlanes)
objRefPlanes = None
if objPart is not None:
SRI.Marshal.ReleaseComObject(objPart)
objPart = None
if objPPlane is not None:
SRI.Marshal.ReleaseComObject(objPPlane)
objPPlane = None
if objAsmRefPlane is not None:
SRI.Marshal.ReleaseComObject(objAsmRefPlane)
objAsmRefPlane = None
if objAsmRefPlanes is not None:
SRI.Marshal.ReleaseComObject(objAsmRefPlanes)
objAsmRefPlanes = None
if objAssembly is not None:
SRI.Marshal.ReleaseComObject(objAssembly)
objAssembly = None
if objDocuments is not None:
SRI.Marshal.ReleaseComObject(objDocuments)
objDocuments = None
if objApplication is not None:
SRI.Marshal.ReleaseComObject(objApplication)
objApplication = None