-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCh7_ManipulatingOccurrences_Ex.ipy
More file actions
93 lines (83 loc) · 3.2 KB
/
Copy pathCh7_ManipulatingOccurrences_Ex.ipy
File metadata and controls
93 lines (83 loc) · 3.2 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
#
# Ch7_ManipulatingOccurrences_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 - Ch7_ManipulatingOccurrences_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
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
# 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)
except Exception, ex:
Console.WriteLine(ex)
finally:
if objOccurrence3 is not None:
SRI.Marshal.ReleaseComObject(objOccurrence3)
objOccurrence3 = None
if objOccurrence2 is not None:
SRI.Marshal.ReleaseComObject(objOccurrence2)
objOccurrence2 = None
if objOccurrence1 is not None:
SRI.Marshal.ReleaseComObject(objOccurrence1)
objOccurrence1 = None
if objOccurrences is not None:
SRI.Marshal.ReleaseComObject(objOccurrences)
objOccurrences = 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