TopSolid'Design 7.19 Automation Guide
TopSolid'Design 7.19 Automation Guide
Automation Guide
TopSolid'Design
MASTER YOUR
MANUFACTURING PROCESS
Missler Software i
TopSolid’Design Automation Guide
The information and the software contained within this document are subject to change without prior
warning and should not be construed as a commitment by Missler Software.
The software covered by this document is supplied under license, and may only be used and duplicated
in compliance with the terms of this license.
EN v7.11.
ii Missler Software
TopSolid’Design Automation Guide
Contents
Introduction............................................................................................... 1
Contents..............................................................................................................................2
Skills....................................................................................................................................2
Tools ...................................................................................................................................2
Architecture .........................................................................................................................2
Commands..........................................................................................................................3
Getting Started.......................................................................................... 5
Visual Studio Project ...........................................................................................................6
Deployment .........................................................................................................................7
Connecting ..........................................................................................................................7
Automating ..........................................................................................................................9
Version ................................................................................................................................9
Units ....................................................................................................................................9
Modifying.............................................................................................................................9
PDM.......................................................................................................... 11
Introduction .......................................................................................................................12
Identifiers...........................................................................................................................12
Revisions...........................................................................................................................12
Search by Identifiers .........................................................................................................13
Search by Universal Identifiers .........................................................................................14
Documents .............................................................................................. 17
Introduction .......................................................................................................................18
Identifiers...........................................................................................................................18
PDM ..................................................................................................................................18
Modifying...........................................................................................................................18
Elements.................................................................................................. 21
Introduction .......................................................................................................................22
Identifiers...........................................................................................................................22
Names...............................................................................................................................22
Items .................................................................................................................................22
Parameters .............................................................................................. 25
Introduction .......................................................................................................................26
Types ................................................................................................................................26
Reals .................................................................................................................................26
Smart Objects ...................................................................................................................26
User Properties .................................................................................................................27
Geometries .............................................................................................. 29
Introduction .......................................................................................................................30
Types ................................................................................................................................30
Sketches .................................................................................................. 33
Introduction .......................................................................................................................34
Frames ..............................................................................................................................34
Topologies.........................................................................................................................34
Exploring ...........................................................................................................................35
Creating.............................................................................................................................36
Modifying...........................................................................................................................37
Shapes ..................................................................................................... 39
Introduction .......................................................................................................................40
Topologies.........................................................................................................................40
Events ...................................................................................................... 41
Introduction .......................................................................................................................42
Architecture .......................................................................................................................42
Contract Implementation ...................................................................................................42
Client Name ......................................................................................................................43
Events Handling ................................................................................................................43
Multiple Access....................................................................................... 49
Introduction .......................................................................................................................50
Architecture .......................................................................................................................50
Processes .........................................................................................................................50
Connecting ........................................................................................................................51
Glossary .................................................................................................. 53
Index ........................................................................................................ 55
iv Missler Software
Introduction TopSolid’Design Automation Guide
Introduction
Missler Software 1
Introduction TopSolid’Design Automation Guide
Contents
This document explains how to drive TopSolid’Design (or TopSolid, for short) from another
application, to automate some frequent tasks.
Automation can often significantly increase productivity, and reduce risk of making errors, so
the investment needed to implement it is very quickly paid off by the benefits.
For instance, if your industrial process commonly requires to set the part number of all the
parts of a project according to the values found in an Excel sheet, it will be worthwhile
automating it instead of spending valuable time every time it needs doing.
Skills
This documentation makes the assumption that you are a fully trained TopSolid user, all the
usual TopSolid terminology (project, part, assembly, entity, operation, parameter...) will be
used without any explanation (you will find some in the TopSolid user documentation).
Automation is performed by writing a program, so some minimum programming skills are
required.
It is possible to use several programming languages, as far as they are compatible with
Microsoft .NET Framework, the most common being C# and Visual Basic.
This documentation makes the assumption that you are using C#, so you will need to translate
some provided code sample into your own development language if you are not using C#.
Tools
To develop and test your program, you will need some tools that are usually part of an
integrated development environment (IDE).
Several IDEs are commercially available, but this documentation makes the assumption that
you are using Microsoft Visual Studio, so again if you are using another IDE, you will need to
perform some translation when some descriptions are related to the IDE.
Architecture
Your application may be a standalone application, or an add-in to another application (like for
instance an Excel add-in), it will run in its own process, and it will drive TopSolid which is
running in its own process by an inter-process protocol called WCF (Windows Communication
Foundation).
Process 1
Process 2
2 Missler Software
TopSolid’Design Automation Guide Introduction
Your application will in fact take the place of a "physical" user, and perform by program some
of the actions that can be manually performed using TopSolid menu commands.
The detailed reference of each method or property of TopSolid Automation API is available in
a companion document "TopSolid’Design Automation.chm" that will be called afterwards
"TopSolid Automation Help".
Commands
Users will be able to start your application directly from TopSolid by associating it to a menu
command.
This can be done in TopSolid by executing the command "Tools > Customize...", and using the
"Add a File to Execute" section.
Missler Software 3
Introduction TopSolid’Design Automation Guide
4 Missler Software
Getting Started TopSolid’Design Automation Guide
Getting Started
Missler Software 5
Getting Started TopSolid’Design Automation Guide
To be able to use TopSolid automation, you will need to reference TopSolid "Automating" DLLs
that are located in TopSolid install folder:
6 Missler Software
TopSolid’Design Automation Guide Getting Started
Once this is done, you will be able to use TopSolid namespaces in your application, and
usually insert the following lines at the top of your C# files:
using TopSolid.Kernel.Automating;
using TopSolid.Cad.Design.Automating;
using TopSolid.Cad.Drafting.Automating;
Deployment
TopSolid Automating DLLs are freely redistributable, you are allowed to (and in fact obliged
to!) deliver them with your application.
Usually, it is best to install them in the same folder than your ".EXE" file in your application
Setup.
Connecting
Your application must first connect to TopSolid, which is simply done by the following lines of
code:
TopSolidHost.Connect();
TopSolidDesignHost.Connect();
TopSolidDraftingHost.Connect();
Missler Software 7
Getting Started TopSolid’Design Automation Guide
using System;
using System.Windows.Forms;
using TopSolid.Cad.Design.Automating;
using TopSolid.Cad.Drafting.Automating;
using TopSolid.Kernel.Automating;
namespace MyApplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
TopSolidHost.Connect();
TopSolidDesignHost.Connect();
TopSolidDraftingHost.Connect();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
TopSolidDraftingHost.Disconnect();
TopSolidDesignHost.Disconnect();
TopSolidHost.Disconnect();
}
8 Missler Software
TopSolid’Design Automation Guide Getting Started
Automating
Once successfully connected to TopSolid, your application will be able to perform some
automation by calling methods and properties exposed in interfaces accessible as properties
of TopSolidHost, TopSolidDesignHost and TopSolidDraftingHost.
These interfaces are described in TopSolid Automation Help.
For instance, to access TopSolid documents it will be possible to use the methods and
properties of the interface IDocuments returned by the property TopSolidHost.Documents.
Getting the document currently edited will therefore be coded as follows:
Version
Once connected to TopSolid, you will be able to know its version, which is available as a
property of TopSolidHost (TopSolidHost.Version).
If the version of the connected TopSolid is anterior to the version of the automation API used
for generating your application, some methods or properties may not be used as they are not
yet available.
You will find the availability of each method or property in TopSolid Automation Help, and need
to check if they are available before using then, otherwise an exception will be thrown.
Units
Values are sent to, and received from TopSolid using the International System of Units (also
called SI units), even if they are exposed to the user using other units.
Therefore angles are in radians, lengths in meters, volumes in cubic meters, masses in
kilograms...
Coordinates of points are, like lengths, in meters.
Modifying
Your application may access TopSolid to extract some information, but it may also perform
some modification of TopSolid data.
Getting information may be done at any time, but modifying cannot.
To modify the contents of TopSolid documents, your application will have to inform TopSolid
that some modification is going to be performed before doing so by calling
TopSolidHost.Application.StartModification, and once the modification has been completed,
it will have to signal that it is finished by calling TopSolidHost.Application.EndModification.
StartModification may fail if TopSolid is not currently available (for instance if the user is
running a menu command), so your application must manage that fact.
If StartModification succeeds, TopSolid will be unavailable to the user until EndModification is
called, so your application must always call it as soon as the current modification is over.
If you forget to call EndModification, TopSolid will stay locked forever and the user will have to
kill the process and loose its modifications, therefore great care is needed!
Most of the time, the appropriate code will look like this:
Missler Software 9
Getting Started TopSolid’Design Automation Guide
try
{
// Perform modification.
...
TopSolidHost.Application.EndModification(true, true);
}
catch
{
// End modification (failure).
TopSolidHost.Application.EndModification(false, false);
}
When possible, the documents modifications performed will be undoable by the user like for
TopSolid commands.
Other types of modifications (like for instance Checking-in a document) are not undoable and
must not be performed within a StartModification / EndModification sequence.
When a method cannot be called at any time but only within or outside a StartModification /
EndModification sequence, it is usually mentioned in the "Remarks" section of its specification.
10 Missler Software
PDM TopSolid’Design Automation Guide
PDM
Missler Software 11
PDM TopSolid’Design Automation Guide
Introduction
Access to TopSolid’Pdm will be possiblle using the methods of IPdm interface returned by the
property TopSolidHost.Pdm.
Identifiers
The objects managed by TopSolid’Pdm are identified by "PDM object identifiers", represented
by the type PdmObjectId.
When you ask TopSolid for a project, or one of its folders or documents, the API will return the
information using such an identifier.
The identifier may be empty (when its property "IsEmpty" is true), in which case it does not
represent any object. This is useful as it allows to mean "no object".
For instance, when searching for a project of a specified name, if the identifier returned is
empty, it means that there is no project with that name.
Revisions
A PDM object may have several major revisions, and each major revision may have several
minor revisions, the last one being the final state.
Major Rev. B
Minor Rev. 2
Minor Rev. 1
Minor Rev. 0
Major Rev. A
Minor Rev. 0
12 Missler Software
TopSolid’Design Automation Guide PDM
Major revisions are identified by a PdmMajorRevisionId, and minor revisions are identified by
a PdmMinorRevisionId.
It is possible to obtain the major revisions of a PDM object using the method
TopSolidHost.Pdm.GetMajorRevisions(PdmObjectId).
It is possible to obtain the minor revisions of a major revision using the method
TopSolidHost.Pdm.GetMinorRevisions(PdmMajorRevisionId).
Search by Identifiers
There are several ways of finding a specific PDM object, but the most common one is by its
identifier.
Typically, if you want to set the material of a part equal to the "Steel" standard material, your
application must first find the document defining the steel material in the "TopSolid
Mechanical" library.
To do so, you must start TopSolid in advanced mode (using the "-a" option), select the
document in the library tree, and use the "Tools > Identifiers" context command.
Missler Software 13
PDM TopSolid’Design Automation Guide
The PDM object identifier of the document is available as a text, that must be copied, and
used directly in the PdmObjectId constructor in your application.
For instance, here is a code sample to get the name of the steel standard material document.
To be sure the document exists in the PDM of the user running your application, it is advised to
check it by using the TopSolidHost.Pdm.Exists(PdmObjectId) method, as shown in the
sample. Otherwise an exception will be thrown when attempting to use it in other methods
(typically, if there is no document corresponding to the identifier provided, the
TopSolidHost.Pdm.GetName(PdmObjectId) method would throw an exception).
14 Missler Software
TopSolid’Design Automation Guide PDM
Missler Software 15
PDM TopSolid’Design Automation Guide
16 Missler Software
Documents TopSolid’Design Automation Guide
Documents
Missler Software 17
Documents TopSolid’Design Automation Guide
Introduction
Access to TopSolid documents will be possiblle using the methods of IDocuments interface
returned by the property TopSolidHost.Documents.
Identifiers
TopSolid documents are identified by "document identifiers", represented by the type
DocumentId.
When you ask TopSolid for a specified document the API will return the information using such
an identifier, and when you want to perform some action on a document you will need to give
its identifier to the API.
The identifier may be empty (when its property "IsEmpty" is true), in which case it does not
represent any document. This is useful as it allows the meaning "no document".
For instance, when getting the document being edited using the "EditedDocument" property, if
the identifier returned is empty, it means that there is no document being edited at the
moment.
You may give an empty document identifier to the API by passing DocumentId.Empty as
argument.
PDM
More precisely, the document identifier corresponds to a specific minor revision of a PDM
object of type TopSolid document, when a new revision is produced, it will have a new
identifier.
It is possible to obtain the document corresponding to the last minor revision of a PDM
TopSolid document using the method TopSolidHost.Documents.GetDocument(PdmObjectId).
Reciprocally, it is possible to obtain the PDM object corresponding to a specific document
using the method TopSolidHost.Documents.GetPdmObject(DocumentId).
It is possible to obtain the document corresponding to a specific minor revision of a PDM
TopSolid document using the method
TopSolidHost.Documents.GetMinorRevisionDocument(PdmMinorRevisiontId).
Reciprocally, it is possible to obtain the PDM minor revision corresponding to a specific
document using the method TopSolidHost.Documents.GetPdmMinorRevision(DocumentId).
Modifying
Every time your application needs to modify a document, it will have to ensure that the
document is in a modifiable state by calling TopSolidHost.Documents.EnsureIsDirty, bearing
in mind that this could fail when for instance it is checked-out by another user in a client-server
PDM situation.
Typically, every time you want to modify the document being edited, you will have to code
something like this:
if (!TopSolidHost.IsConnected) return;
DocumentId docId = TopSolidHost.Documents.EditedDocument;
18 Missler Software
TopSolid’Design Automation Guide Documents
if (docId.IsEmpty) return;
// Start modification.
// Modify document.
try
{
// Make document modifiable.
TopSolidHost.Documents.EnsureIsDirty(ref docId);
...
TopSolidHost.Application.EndModification(true, true);
}
catch
{
// End modification (failure).
TopSolidHost.Application.EndModification(false, false);
}
Care must be taken when using document identifiers, and in particular attention paid to the
fact that when a document that has just been saved is modified, a new revision is created,
which will have a new document identifier.
This is why the method "EnsureIsDirty" that makes sure that a document is in a modifiable
state before performing modifications uses the "ref" keyword for the argument.
TopSolidHost.Documents.EnsureIsDirty(ref docId);
If the document identifier was also stored in another variable than "docId", using that out-of-
date value to modify the document after calling this method would lead to a bug, as it would
correspond to the read-only previous revision of the document.
Missler Software 19
Documents TopSolid’Design Automation Guide
20 Missler Software
Elements TopSolid’Design Automation Guide
Elements
Missler Software 21
Elements TopSolid’Design Automation Guide
Introduction
Basically, a TopSolid document contains elements, that may be of different kinds: entities,
operations...
Access to TopSolid elements will be possiblle using the methods of IElements interface
returned by the property TopSolidHost.Elements.
Identifiers
Elements are identified by "element identifiers", represented by the type ElementId.
When you ask TopSolid for a specified element the API will return the information using such
an identifier, and when you want to perform some action on an element you will need to give
its identifier to the API.
The identifier may be empty (when its property "IsEmpty" is true), in which case it does not
represent any element. This is useful as it allows to mean "no element".
You may give an empty element identifier to the API by passing ElementId.Empty as
argument.
An element always belongs to a specific document, which identifier may be obtained by the
property "DocumentId" of the element identifier.
Names
In TopSolid, some elements have got a name which is unique in the document, this in
particular is the case for parameters, or other simple entities created using the "Construction"
menu (points, axes, planes, ...).
It is often needed to retrieve such elements by program, this can be done using the method
SearchByName().
The name of system elements is translated into the user’s local language in the user interface,
so to find them using the SearchByName() method you need to know their "real" name before
translation.
This can be done by launching TopSolid in advanced mode (with the "-a" command line
option), and using the advanced contextual command "System Name..." available in the
"Others" sub-menu when selecting a system element.
For instance, thanks to this command you will find out that the real name of the absolue frame
of a part document is "$TopSolid.Kernel.DB.D3.Documents.ElementName.AbsoluteFrame"!
Items
It is sometimes needed to identify a subpart of an element, for instance an edge or a face of a
shape entity.
These element subparts are called "element items", they will be identified by "item labels",
represented by the type ItemLabel.
The item label identifies the item within the element, which is supposed to be already known,
therefore an element item is in fact completely identified by specifying the pair (ElementId,
ItemLabel), "ElemenId" specifying the element, and "ItemLabel" specifying the item within the
element.
The pair (ElementId, ItemLabel) is encapsulated into the dedicated type ElementItemId called
element item identifier.
When you ask TopSolid for a specified element item the API will return the information using
an element item identifier, and when you want to perform some action on an element item you
will need to give its element item identifier to the API.
Here is a code sample that gets the edges connected to a specified shape face:
22 Missler Software
TopSolid’Design Automation Guide Elements
ElementItemId faceId;
...
Missler Software 23
Elements TopSolid’Design Automation Guide
24 Missler Software
Parameters TopSolid’Design Automation Guide
Parameters
Missler Software 25
Parameters TopSolid’Design Automation Guide
Introduction
Some of the most frequent tasks to automate involve getting or setting the value of document
parameters.
This will be possiblle using the methods of IParameters interface returned by the property
TopSolidHost.Parameters.
Parameters are entities, and therefore elements, they are identified using element identifiers.
It is possible to get all the parameters of the parameters folder of a document using the
method "GetParameters".
When looking for a parameter knowing its name, it is faster to get it directly using the method
IElements.SearchByName().
Some frequently used system parameters may be obtained by a dedicated method, like
GetAuthorParameter() which gets the parameter "Author" of a document.
Types
TopSolid manages many types of parameters, most of them being accessible through
Automation.
The supported types are listed in the enumeration ParameterType.
It is possible to know the type of a parameter using the method GetParameterType().
It is possible to get or set the value of a parameter of type "Xyz" by the methods
GetXyzValue() and SetXyzValue().
Reals
One of the most used type is the real parameter, which is used to represent a real value with a
unit, like "8.5mm".
The type of unit (Length, Mass, ...) of the parameter and the specific unit used to expose it to
the user defined by its symbol ("mm", "kg", ...) may be obtained using the GetRealUnit()
method.
The value of the parameter given by the GetRealValue() method is in SI units.
It is possible to access the available units using the IUnits interface returned by the property
TopSolidHost.Units.
Smart Objects
In TopSolid, when for instance creating an offset point at a specified distance from a specified
origin point in a specified direction, it is possible to enter different types of values for the
distance.
One can:
• enter a basic real value like "10mm",
• give the name of a length parameter, like "d",
• enter a formula mixing basic values and parameters like "2 * d + 5mm",
• select a circular edge, meaning the diameter of the circle,
• ...
Therefore it must be possible to do the same by program when automating this task.
To do so, instead of using simple objects like "double" or "int" as arguments, new types of
objects will be available, called smart objects.
For instance, to specify the offset distance, a SmartReal will be used.
A SmartReal may be of different types, as defined by the enumeration SmartRealType.
Here is a code sample showing the construction of several types of SmartReal:
26 Missler Software
TopSolid’Design Automation Guide Parameters
SmartReal real;
Like for reals, there will be smart "versions" of other types of values like SmartIntegers,
SmartBooleans...
User Properties
Some parameters may correspond to user properties, that are defined in a dedicated type of
document (see User’s Guide).
Here is a code sample showing how to create, if needed, and set the value of a user property
text parameter in a document:
PdmObjectId userPropertyObjectId =
TopSolidHost.Pdm.SearchDocumentByUniversalId(
PdmObjectId.Empty, "Domain", "Name");
if (userPropertyObjectId.IsEmpty) return;
DocumentId userPropertyDocId = TopSolidHost.Documents.GetDocument(
userPropertyObjectId);
if (param.IsEmpty)
{
param = TopSolidHost.Parameters.CreateUserPropertyParameter(
docId, userPropertyDocId);
}
Missler Software 27
Parameters TopSolid’Design Automation Guide
28 Missler Software
Geometries TopSolid’Design Automation Guide
Geometries
Missler Software 29
Geometries TopSolid’Design Automation Guide
Introduction
Access to TopSolid simple 2-dimensional (2D) and 3-dimensional (3D) geometric entities will
be possiblle using the methods of IGeometries2D and IGeometries3D interfaces returned by
the properties TopSolidHost.Geometries2D and TopSolidHost.Geometries3D.
2D geometry will be found in 2D documents like "Draft" or "2D Model".
3D geometry will be found in 3D documents like "Part", "Assembly" or "3D Model".
Types
To receive from and send to TopSolid geometric information, several useful structures are
provided, they are divided into 2D and 3D types.
2D geometry
• Vector2D: 2D vector.
• Direction2D: 2D direction, defined by a 2D unit vector.
• Point2D: 2D point.
• Axis2D: 2D axis.
• Frame2D: 2D frame.
• Transform2D: 2D transform.
3D geometry
• Vector3D: 3D vector.
• Direction3D: 3D direction, defined by a 3D unit vector.
• Point3D: 3D point.
• Axis3D: 3D axis.
• Plane3D: 3D plane.
• Frame3D: 3D frame.
• Transform3D: 3D transform.
Operators
Useful operators are provided for these geometric types, they allow to write clearer and more
compact code.
For instance, the middle point between two existing points may be computed like this:
Also, finding a point at a specific local coordinate on an axis, may be coded as folow:
Axis3D ax;
double x;
...
30 Missler Software
TopSolid’Design Automation Guide Geometries
Sample
Here is a code sample that gets the geometry of a linear edge of a shape:
ElementItemId edgeId;
...
if (TopSolidHost.Shapes.GetEdgeCurveType(edgeId) !=
CurveType.Line) return;
Axis3D axis;
TopSolidHost.Shapes.GetEdgeLineCurve(edgeId, out axis);
Smart Objects
We have already seen that it was possible to provide associative real values using SmartReal
objects, but smart objects also exist for the geometry.
So there will be a smart version of the "Point3D" type called "SmartPoint3D", a smart version
of the "Axis3D" type called "SmartAxis3D",...
Therefore, it will be possible for instance to create by program an offset point at a distance "d
+ 10mm" from the point "Point 1" in the direction of the absolute X axis as follows:
TopSolidHost.Geometries3D.CreateOffsetPoint(docId, smartOrigin,
smartDirection, smartDistance);
Missler Software 31
Geometries TopSolid’Design Automation Guide
32 Missler Software
Sketches TopSolid’Design Automation Guide
Sketches
Missler Software 33
Sketches TopSolid’Design Automation Guide
Introduction
Access to TopSolid 2D and 3D sketch entities will be possible using the methods of
ISketches2D and ISketches3D interfaces returned by the properties
TopSolidHost.Sketches2D and TopSolidHost.Sketches3D.
The 2D sketches embedded into 3D documents are considered as being 2D, so they will be
accessed using the ISketches2D interface.
Therefore, in a 3D document, the 3D sketches are obtained using
TopSolidHost.Sketches3D.GetSketches(), and the 2D sketches are obtained using
TopSolidHost.Sketches2D.GetSketches().
Frames
A sketch has got a definition frame that may be obtained by the method GetFrame(), all the
geometry contained in the sketch is defined in that frame (i.e. when you get the coordinates of
a point in the sketch, they are relative to that frame).
In the case of a 2D sketch embedded into a 3D document, its 2D frame will be replaced by a
3D plane obtained by the method GetPlane().
Therefore, here is how to get the absolute 2D coordinates of the point (X=0, Y=100mm) of 2D
sketch in a 2D document:
And, here is how to get the absolute 3D coordinates of the point (X=0, Y=100mm) of 2D
sketch in a 3D document:
Topologies
The sketch structure is described using topological items, or "topologies" for short, some of
them having an attached geometry:
34 Missler Software
TopSolid’Design Automation Guide Sketches
Segments Vertices
Profiles Section
Exploring
Here is a sample that scans the profiles of a 2D sketch in a 3D document, and creates points
at each segment of type line or circular arc midpoint.
Missler Software 35
Sketches TopSolid’Design Automation Guide
switch (curveType)
{
case CurveType.Line:
Axis2D axis;
TopSolidHost.Sketches2D.GetSegmentLineCurve(
segment, out axis);
midpoints.Add(axis.Origin + tm * axis.Direction);
break;
case CurveType.Circle:
Frame2D frame;
double r;
TopSolidHost.Sketches2D.GetSegmentCircleCurve(
segment, out frame, out r);
midpoints.Add(frame.Origin + r * (
Math.Cos(tm) * frame.XDirection
+ Math.Sin(tm) * frame.YDirection));
break;
}
}
// Create midpoints.
Creating
It is possible to create a sketch by program, several methods are available depending on the
situation:
TopSolidHost.Sketches2D.CreateSketchIn2D
36 Missler Software
TopSolid’Design Automation Guide Sketches
TopSolidHost.Sketches2D.CreateSketchIn3D
TopSolidHost.Sketches3D.CreateSketch
Modifying
It is also possible to modify a sketch by program using several available methods, but before
calling them it is necessary to call the following one (in the case of a 2D sketch, otherwise
replace "2D" by "3D"):
TopSolidHost.Sketches2D.StartModification(inSketchId);
Once the modification is complete, it is necessary to say so by calling the following method:
TopSolidHost.Sketches2D.EndModification();
Here is for instance a sample showing how to make a rectangular profile in an existing 2D
sketch.
TopSolidHost.Sketches2D.StartModification(inSketchId);
// Create vertices.
// Create segments.
Missler Software 37
Sketches TopSolid’Design Automation Guide
// Create profile.
TopSolidHost.Sketches2D.EndModification();
38 Missler Software
Shapes TopSolid’Design Automation Guide
Shapes
Missler Software 39
Shapes TopSolid’Design Automation Guide
Introduction
Access to TopSolid shapes entities will be possible using the methods of IShapes interface
returned by the property TopSolidHost.Shapes.
Topologies
The shape structure is described using topological items, or "topologies" for short, some of
them having an attached geometry:
Edges Vertices
Faces
40 Missler Software
Events TopSolid’Design Automation Guide
Events
Missler Software 41
Events TopSolid’Design Automation Guide
Introduction
Most automating applications will "tell" TopSolid what to do, but sometimes it could be useful
to "listen" to TopSolid and react to some actions performed by the user.
This is possible using events, as described in this chapter.
Architecture
Basically, it is the same principle than for automating TopSolid, but reversed: when an event
occurs, TopSolid will use WCF to call your application, which is required to provide a specified
WCF service.
WCF
Your Application TopSolid
Process 2
TopSolid is just letting you know that something happened, it will not wait for any answer from
your application, as all event methods are "one-way" (see WCF definition for one-way calls if
needed):
Contract Implementation
TopSolid events are defined as WCF service contract interfaces that need to be implemented
in your application.
For instance, to manage documents events, you need to implement IDocumentsEvents in a
class:
42 Missler Software
TopSolid’Design Automation Guide Events
Client Name
To manage events, your application must provide a name when connecting to TopSolid:
So, instead of just typing:
TopSolidHost.Connect();
TopSolidHost.Connect("MyApplication");
Your application will then not be an anonymous client, but a named client connected to
TopSolid.
This client name cannot change during the connection, and may later be obtained using the
following property:
TopSolidHost.ClientName
While an application is connected to TopSolid with a specified name, it will not be possible for
other applications to connect to TopSolid using the same name, therefore this name should be
as unique as possible...
Events Handling
Once connected with a name, it is possible to start handling some events by simply calling the
TopSolidHost method dedicated to that type of events.
For instance for documents events:
TopSolidHost.HandleDocumentsEvents(typeof(DocumentsEventsHost));
This methods makes a new instance of your DocumentsEventsHost class that will receive the
events.
Once this method is called, and until disconnect from TopSolid, when an event occurs in
TopSolid, the corresponding method will be called in the DocumentsEventsHost object that
has been created by this method.
Missler Software 43
Events TopSolid’Design Automation Guide
44 Missler Software
Remote Access TopSolid’Design Automation Guide
Remote Access
Missler Software 45
Remote Access TopSolid’Design Automation Guide
Introduction
Since TopSolid v7.9, it is possible to drive TopSolid from another application running on a
different machine, this is called "remote automation".
This chapter explains how to proceed to perform such operation.
Architecture
Basically, it is the same principle than for normal TopSolid automation, but it uses TCP
protocol that allows communication between two separate machines connected to the same
network.
WCF (TCP)
Your Application TopSolid
Machine 1
Machine 2
Settings
TopSolid options must be set to allow remote access, as this is not the default setting.
In the "General" section of "Tools > Options", in the "Automation" group, the "Manage remote
access" mode must be checked.
Also, if the default communication port number is not convenient, it may be changed.
TopSolid must then be restarted.
Sometimes a firewall may be blocking the specified port communication, it is then required to
adjust its configuration.
Connecting
When connecting to a remote TopSolid, it is required to call TopSolidHost.DefineConnection
method first, to provide the IP address of the machine on the network running TopSolid, and
the port number used in TopSolid settings (for instance 192.168.7.145 and 8090).
46 Missler Software
TopSolid’Design Automation Guide Remote Access
Events
It is also possible to manage events using remote access.
In that case a port must be chosen (and unblocked in the firewall) on the machine running your
application.
When defining the connection, it is then required to provide the IP address of your machine as
well as the port number to use (for instance 192.168.7.153 and 8091).
Sometimes a computer may have several network cards (for instance Ethernet + WiFi), so
care must be taken to provide the right IP address as seen from the machine running TopSolid
on the network.
Missler Software 47
Remote Access TopSolid’Design Automation Guide
48 Missler Software
Multiple Access TopSolid’Design Automation Guide
Multiple Access
Missler Software 49
Multiple Access TopSolid’Design Automation Guide
Introduction
Since TopSolid v7.10, it is possible for an automating application to drive several TopSolid
processes running at the same time on the same machine, or on another machine (remote
access).
This chapter explains how to proceed to perform such operation.
Architecture
Basically, it is the same principle than for single access TopSolid automation, but instead of
using the static class TopSolidHost to connect to a unique TopSolid, one must have one
TopSolidHostInstance object per TopSolid process to connect to.
Instance 1
TopSolid
Process 2
Your Application
Process 1
Instance 2
TopSolid
Process 3
Processes
When running several TopSolid processes on the same machine than the automating
application, they must be started with the command-line argument "-pipeName <name>",
where <name> must be different on each process as it is used to make a specific Windows
named pipe.
For instance: "TopSolid -pipeName TS1".
To connect to one of these processes, the PipeName property of the TopSolidHostInstance
object must be set to the same value before calling a "Connect" method.
When running several TopSolid processes on a different machine than the automating
application (remote access), they must be started with the command-line argument "-tcpPort
<port number>", where <port number> is the TCP port number to use and must be different on
each process.
For instance: "TopSolid -tcpPort 8095".
To connect to one of these processes, the DefineConnection method of the
TopSolidHostInstance object must be called with the same host port value before calling a
"Connect" method.
50 Missler Software
TopSolid’Design Automation Guide Multiple Access
Usually, it will also be required to have different PDM connections on each TopSolid, and
therefore use the "-pdm" command-line argument, as described in the User’s Guide.
Connecting
Here is some example showing how to connect to two TopSolid processes on the local
machine.
tsHost1.PipeName = "TS1";
tsHost1.Connect();
tsDesignHost1.Connect();
tsHost2.PipeName = "TS2";
tsHost2.Connect();
tsDesignHost2.Connect();
...
Missler Software 51
Multiple Access TopSolid’Design Automation Guide
52 Missler Software
Glossary TopSolid’Design Automation Guide
Glossary
Missler Software 53
Glossary TopSolid’Design Automation Guide
The definitions of key terms used in this document are listed below.
API: Acronym of "Application Programming Interface", set of specified rules and conventions
that allow a software to communicate with another software.
54 Missler Software
TopSolid’Design Automation Guide Index
Index
A
API 3
Automation 2
C
C# 2
D
DocumentId 18
E
Edge 40
ElementId 22
ElementItemId 22
Events 42
F
Face 40
I
IDE 2
ItemLabel 22
M
Microsoft .NET Framework 2
Microsoft Visual Studio 2
P
PdmMajorRevisionId 13
PdmMinorRevisionId 13
PdmObjectId 12
Profile 34
S
Section 34
Segment 34
Smart object 26
T
Topology 34, 40
TopSolid 2
TopSolid Automation Help 3
TopSolid’Design 2
TopSolid’Design Automation.chm 3
U
Universal Identifier 14
V
Vertex 34, 40
Visual Basic 2
Missler Software 55
Index TopSolid’Design Automation Guide
W
WCF 2
56 Missler Software