Class GraphicComponent
The base class of all objects in the station that represent physical objects or entities.
Inheritance
Inherited Members
Namespace: ABB.Robotics.RobotStudio.Stations
Assembly: ABB.Robotics.RobotStudio.Stations.dll
Syntax
public abstract class GraphicComponent : ProjectObject, IHasTransform, IHasFrames, IAttachableChild, ISupportCopy
Examples
GraphicComponent Example.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
Constructors
View SourceGraphicComponent()
Declaration
protected GraphicComponent()
GraphicComponent(GraphicComponent)
Declaration
protected GraphicComponent(GraphicComponent parent)
Parameters
| Type | Name | Description |
|---|---|---|
| GraphicComponent | parent |
GraphicComponent(PimDocument)
Declaration
protected GraphicComponent(PimDocument doc)
Parameters
| Type | Name | Description |
|---|---|---|
| PimDocument | doc |
Fields
View Source_childInstances
Declaration
[Persistent("ChildInstances")]
[CLSCompliant(false)]
protected CmList<GraphicComponent> _childInstances
Field Value
| Type | Description |
|---|---|
| CmList<GraphicComponent> |
_clipPlane
Declaration
[Undoable]
[Persistent("ClipPlane")]
[CLSCompliant(false)]
protected ClipPlane _clipPlane
Field Value
| Type | Description |
|---|---|
| ClipPlane |
_definition
Declaration
[Undoable]
[Persistent("Definition")]
[CLSCompliant(false)]
protected ComponentDef _definition
Field Value
| Type | Description |
|---|---|
| ComponentDef |
_detectable
Declaration
[Persistent("Detectable")]
[CLSCompliant(false)]
protected bool _detectable
Field Value
| Type | Description |
|---|---|
| bool |
_frames
Declaration
[Persistent("AttachmentPoints")]
[CLSCompliant(false)]
protected CmList<Frame> _frames
Field Value
| Type | Description |
|---|---|
| CmList<Frame> |
_pickingEnabled
Declaration
[Undoable]
[Persistent("PickingEnabled")]
[CLSCompliant(false)]
protected bool _pickingEnabled
Field Value
| Type | Description |
|---|---|
| bool |
_source
Declaration
[Undoable]
[Persistent("Source")]
[CLSCompliant(false)]
protected string _source
Field Value
| Type | Description |
|---|---|
| string |
_sourceFileTime
Declaration
[Undoable]
[Persistent("SourceFileTime")]
[CLSCompliant(false)]
protected DateTime _sourceFileTime
Field Value
| Type | Description |
|---|---|
| DateTime |
_transformMat
Declaration
[Undoable]
[Persistent("Transform")]
[CLSCompliant(false)]
protected Matrix4 _transformMat
Field Value
| Type | Description |
|---|---|
| Matrix4 |
Properties
View SourceAnnotations
Gets an AnnotationCollection object that contains the Annotations on this object.
Declaration
public AnnotationCollection Annotations { get; }
Property Value
| Type | Description |
|---|---|
| AnnotationCollection |
ClipPlane
Gets or sets a ClipPlane that will hide all geometry in the negative z space of its transform.
Declaration
public ClipPlane ClipPlane { get; set; }
Property Value
| Type | Description |
|---|---|
| ClipPlane |
Remarks
Setting a clip plane on a GraphicComponent will override the global clip plane defined on a GraphicControl.
Color
Gets or sets the color of the object in the graphics.
Declaration
public Color Color { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
Remarks
Returns Color.Empty if color is ambiguous.
Examples
Get/Set Color.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
Detectable
Gets or sets a value indicating the the component can be detected by sensors.
Declaration
public bool Detectable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Frames
Gets a FrameCollection object that represents all the Frames on this object.
Declaration
public FrameCollection Frames { get; }
Property Value
| Type | Description |
|---|---|
| FrameCollection |
GfxData
Declaration
protected GfxData GfxData { get; }
Property Value
| Type | Description |
|---|---|
| GfxData |
IsTransient
Gets a value indicating whether the object is transient.
Declaration
public bool IsTransient { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Transient components are temporary used during the simulation. They are deleted after the simulation stops.
Library
Returns the GraphicComponentLibrary that contains the definition of this component, or null.
Declaration
public GraphicComponentLibrary Library { get; }
Property Value
| Type | Description |
|---|---|
| GraphicComponentLibrary |
Opacity
Gets or sets the opacity of the object.
Declaration
public double Opacity { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Remarks
Valid values are 0.0 (fully transparent) through 1.0 (fully opaque). Returns 1.0 if opacity is ambiguous.
Parent
The Parent property returns a reference to the parent GraphicComponent object.
Declaration
public override ProjectObject Parent { get; }
Property Value
| Type | Description |
|---|---|
| ProjectObject | Returns a ProjectObject object. |
Overrides
Remarks
You can use the Parent property to navigate up from the current object to the object one level higher.
Examples
Get Parent.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
PhysicsMotionControl
Gets or sets the physical behavior of this GraphicComponent.
Declaration
public PhysicsMotionControl PhysicsMotionControl { get; set; }
Property Value
| Type | Description |
|---|---|
| PhysicsMotionControl |
PickingEnabled
Gets or sets if the component can be picked and selected in 3D graphic windows.
Declaration
public bool PickingEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Examples
Get/Set PickingEnabled.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
Transform
Gets the Transform of the object.
Declaration
public virtual Transform Transform { get; }
Property Value
| Type | Description |
|---|---|
| Transform |
Remarks
The Transform is read-only on mechanism links.
Examples
Get Transform.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
Visible
Gets or sets whether the object should be displayed in the graphics or not.
Declaration
public virtual bool Visible { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Examples
Get/Set Visible.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
Methods
View SourceAfterLoad(PimDocument)
Declaration
protected override void AfterLoad(PimDocument doc)
Parameters
| Type | Name | Description |
|---|---|---|
| PimDocument | doc |
Overrides
View SourceCanImport(string)
Returns true if the fileName refers to a file type that is possible to import using ImportAsync().
Declaration
public static bool CanImport(string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileName |
Returns
| Type | Description |
|---|---|
| bool |
Copy()
Creates a deep copy of the object.
Declaration
public virtual ProjectObject Copy()
Returns
| Type | Description |
|---|---|
| ProjectObject | The copy of the object. |
Examples
Copy.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
CopyInstance()
Creates a copy but keeps a connection to the definition of the GraphicComponent, typically in a Library definition.
Declaration
public GraphicComponent CopyInstance()
Returns
| Type | Description |
|---|---|
| GraphicComponent | The instance copy of the object. |
Examples
CopyInstance.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
Delete()
Deletes this object permanently.
Declaration
public virtual void Delete()
Remarks
The object must first be removed from its parent. Any subsequent attempts to access the object or its children will fail. Use with caution. The operation is not undoable.
DeleteGeometry()
Recursively deletes all CAD geometry.
Declaration
public void DeleteGeometry()
Examples
DeleteGeometry.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
DeleteGeometry(bool)
Declaration
[Obsolete("Use DeleteGeometry() instead")]
public void DeleteGeometry(bool preserveSnapPoints)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | preserveSnapPoints |
DisconnectFromLibrary()
Moves the definition to the Station or Project. This causes the Library property to return Null.
Declaration
public void DisconnectFromLibrary()
Remarks
The GraphicComponentLibrary will be closed if this is the only instance connected to it. This will cause any subsequent operations on the GraphicComponentLibrary to fail.
Examples
DisconnectFromLibrary.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
ExportXml(string)
Exports this to an XML file
Declaration
public void ExportXml(string xmlFile)
Parameters
| Type | Name | Description |
|---|---|---|
| string | xmlFile | The path to the XML file to create. |
Remarks
Parts and assets are saved in the same directory as xmlFile.
ExportXml(string, string)
Exports this to an XML file
Declaration
public void ExportXml(string xmlFile, string referenceDirectory)
Parameters
| Type | Name | Description |
|---|---|---|
| string | xmlFile | The path to the XML file to create. |
| string | referenceDirectory | The directory where parts and assets should be saved. |
GetBoundingBox(bool)
Computes the (axis-aligned) bounding box for this object.
Declaration
public BoundingBox GetBoundingBox(bool global)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | global | Specifies that the bounding box should be in the global (world) coordinate system rather than in this object's local coordinate system. |
Returns
| Type | Description |
|---|---|
| BoundingBox |
GetBoundingBox(bool, out Vector3, out Vector3)
Computes the (axis-aligned) bounding box for this object.
Declaration
[Obsolete("Use GetBoundingBox(bool global) instead", true)]
public void GetBoundingBox(bool global, out Vector3 min, out Vector3 max)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | global | Specifies that the bounding box should be in the global (world) coordinate system rather than in this object's local coordinate system. |
| Vector3 | min | The first corner of the bounding box. |
| Vector3 | max | The second corner of the bounding box. |
Examples
GetBoundingBox.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
GetBoundingBox(bool, IntPtr, IntPtr)
Declaration
[Obsolete("Don't use", true)]
public void GetBoundingBox(bool global, IntPtr min, IntPtr max)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | global | |
| IntPtr | min | |
| IntPtr | max |
GetGfxChildren()
Declaration
protected virtual IEnumerable<IGfxObject> GetGfxChildren()
Returns
| Type | Description |
|---|---|
| IEnumerable<IGfxObject> |
GetGfxMatrix()
Declaration
protected virtual Matrix4 GetGfxMatrix()
Returns
| Type | Description |
|---|---|
| Matrix4 |
GetMatrix()
Declaration
protected virtual Matrix4 GetMatrix()
Returns
| Type | Description |
|---|---|
| Matrix4 |
GetNormalToSurface(Vector3, out Vector3, out Vector3, out Face)
Calculates the closest point and the corresponding normal.
Declaration
[Obsolete("Use TryGetNormalToSurface instead.")]
public void GetNormalToSurface(Vector3 testPoint, out Vector3 hitPoint, out Vector3 hitPointNormal, out Face hitFace)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | testPoint | The test point, in world coordinates. |
| Vector3 | hitPoint | The closest point, in world coordinates. |
| Vector3 | hitPointNormal | Normal to the closest point, in world coordinates. May contain NaN values on failure. |
| Face | hitFace | The face of the closest point. If the closest point is on an edge or vertex, hitFace will be null. |
Remarks
If this GraphicComponent does not contain geometric information the result will be an approximation, and hitFace will be null.
Examples
GetNormalToSurface.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
Highlight(bool)
Highlights the object using the default highlight style and color.
Declaration
public void Highlight(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | True if the object should be highlighted, False to turn the highlighting off. |
Examples
Highlight.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
Highlight(bool, Color)
Highlights the object using a specified color.
Declaration
public void Highlight(bool value, Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | True if the object should be highlighted, False to turn the highlighting off. |
| Color | color | Highlight color. |
ImportAsync(string)
Creates a GraphicComponent from the given CAD or graphics file.
Declaration
public static Task<GraphicComponent> ImportAsync(string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileName |
Returns
| Type | Description |
|---|---|
| Task<GraphicComponent> |
Remarks
Supports all formats available in the Import Geometry user interface of RobotStudio. When importing a CAD file, avoid all modeling operations until the returned Task is completed.
ImportAsync(string, GraphicImportSettings, IProgressCallback)
Creates a GraphicComponent from the given CAD or graphics file.
Declaration
public static Task<GraphicComponent> ImportAsync(string fileName, GraphicImportSettings settings, IProgressCallback progress)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileName | |
| GraphicImportSettings | settings | |
| IProgressCallback | progress |
Returns
| Type | Description |
|---|---|
| Task<GraphicComponent> |
Remarks
Supports all formats available in the Import Geometry user interface of RobotStudio. When importing a CAD file, avoid all modeling operations until the returned Task is completed.
ImportXml(string)
Declaration
[Obsolete("Use ImportXmlAsync instead")]
public static GraphicComponent ImportXml(string xmlFile)
Parameters
| Type | Name | Description |
|---|---|---|
| string | xmlFile |
Returns
| Type | Description |
|---|---|
| GraphicComponent |
ImportXml(string, string)
Declaration
[Obsolete("Use ImportXmlAsync instead")]
public static GraphicComponent ImportXml(string libraryXmlFile, string libraryFileName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | libraryXmlFile | |
| string | libraryFileName |
Returns
| Type | Description |
|---|---|
| GraphicComponent |
ImportXml(string, string, Dictionary<string, string>)
Declaration
[Obsolete("Use ImportXmlAsync instead")]
public static GraphicComponent ImportXml(string libraryXmlFile, string libraryFileName, Dictionary<string, string> replacements)
Parameters
| Type | Name | Description |
|---|---|---|
| string | libraryXmlFile | |
| string | libraryFileName | |
| Dictionary<string, string> | replacements |
Returns
| Type | Description |
|---|---|
| GraphicComponent |
ImportXml(string, string, string, string)
Declaration
[Obsolete("Use ImportXmlAsync instead")]
public static GraphicComponent ImportXml(string xmlData, string referenceDirectory, string defaultName, string defaultResource)
Parameters
| Type | Name | Description |
|---|---|---|
| string | xmlData | |
| string | referenceDirectory | |
| string | defaultName | |
| string | defaultResource |
Returns
| Type | Description |
|---|---|
| GraphicComponent |
ImportXmlAsync(string)
Creates a GraphicComponent from an RSXML file.
Declaration
public static Task<GraphicComponent> ImportXmlAsync(string xmlFile)
Parameters
| Type | Name | Description |
|---|---|---|
| string | xmlFile | The filename of the RSXML file to compile. |
Returns
| Type | Description |
|---|---|
| Task<GraphicComponent> | The compiled GraphicComponent. |
Remarks
The XML is validated against GraphicComponentSchema.xsd.
ImportXmlAsync(string, string)
Creates a GraphicComponent specified in a Library XML file.
Declaration
public static Task<GraphicComponent> ImportXmlAsync(string libraryXmlFile, string libraryFileName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | libraryXmlFile | XML file that adheres to LibraryCompilerSchema.xsd. |
| string | libraryFileName | The 'fileName' attribute of the Library or Variant node that specifies the component. |
Returns
| Type | Description |
|---|---|
| Task<GraphicComponent> | The compiled GraphicComponent. |
ImportXmlAsync(string, string, Dictionary<string, string>)
Creates a GraphicComponent specified in a Library XML file.
Declaration
public static Task<GraphicComponent> ImportXmlAsync(string libraryXmlFile, string libraryFileName, Dictionary<string, string> replacements)
Parameters
| Type | Name | Description |
|---|---|---|
| string | libraryXmlFile | XML file that adheres to LibraryCompilerSchema.xsd. |
| string | libraryFileName | The 'fileName' attribute of the Library or Variant node that specifies the component. |
| Dictionary<string, string> | replacements | Key-value pairs where {key} in the XML is replaced by the corresponding value. |
Returns
| Type | Description |
|---|---|
| Task<GraphicComponent> | The compiled GraphicComponent. |
ImportXmlAsync(string, string, string, string)
Creates a GraphicComponent from in-memory XML.
Declaration
public static Task<GraphicComponent> ImportXmlAsync(string xmlData, string referenceDirectory, string defaultName, string defaultResource)
Parameters
| Type | Name | Description |
|---|---|---|
| string | xmlData | The XML to compile. |
| string | referenceDirectory | The directory to search for files referenced by the XML data. |
| string | defaultName | The default name of the GraphicComponent. |
| string | defaultResource | The defalt name of the file containing SmartComponent resources. |
Returns
| Type | Description |
|---|---|
| Task<GraphicComponent> | The compiled GraphicComponent. |
Remarks
The XML is validated against GraphicComponentSchema.xsd.
MoveDefinitionToLibrary()
Moves the definition to a new Library.
Declaration
public GraphicComponentLibrary MoveDefinitionToLibrary()
Returns
| Type | Description |
|---|---|
| GraphicComponentLibrary | The new Library containing the GraphicComponent as RootComponent. |
Examples
MoveDefinitionToLibrary.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>
View Source
OnCreatingObject()
Declaration
protected override void OnCreatingObject()
Overrides
View SourceOnDefinitionChanged()
Declaration
protected virtual void OnDefinitionChanged()
OnDelete()
Declaration
protected override void OnDelete()
Overrides
View SourceOnUndoRedo()
Declaration
protected override void OnUndoRedo()
Overrides
View SourceSetMaterial(Material, bool)
Sets the material of the object.
Declaration
public void SetMaterial(Material material, bool preserveOpacity)
Parameters
| Type | Name | Description |
|---|---|---|
| Material | material | |
| bool | preserveOpacity |
SetMatrix(Matrix4)
Declaration
protected virtual void SetMatrix(Matrix4 m)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4 | m |
TryGetNormalToSurface(Vector3, out Vector3, out Vector3, out Face)
Calculates the closest point and the corresponding normal.
Declaration
public bool TryGetNormalToSurface(Vector3 testPoint, out Vector3 hitPoint, out Vector3 hitPointNormal, out Face hitFace)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | testPoint | The test point, in world coordinates. |
| Vector3 | hitPoint | The closest point, in world coordinates. |
| Vector3 | hitPointNormal | Normal to the closest point, in world coordinates. |
| Face | hitFace | The face of the closest point. If the closest point is on an edge or vertex, hitFace will be null. |
Returns
| Type | Description |
|---|---|
| bool | True on success |
Remarks
If this GraphicComponent does not contain geometric information the result will be an approximation, and hitFace will be null.
Examples
GetNormalToSurface.
Project.UndoContext.BeginUndoStep("PartProperties");
try
{
Station station = Station.ActiveStation;
// Create a part.
#region PartPropertiesStep1
Part myPart1 = new Part();
myPart1.Name = "MyPart_1";
#endregion
// Add the part to the graphics componenets collection of the station.
#region PartPropertiesStep2
station.GraphicComponents.Add(myPart1);
#endregion
// Create a box and add it to myPart.
#region PartPropertiesStep3
Matrix4 box_origin = new Matrix4(Vector3.XVector, 0.0);
Vector3 box_size = new Vector3(0.1, 0.1, 0.1);
Body box = Body.CreateSolidBox(box_origin, box_size);
box.Name = "MyBox";
myPart1.Bodies.Add(box);
#endregion
// Create a cylinder and add it to myPart.
#region PartPropertiesStep4
Matrix4 origin = new Matrix4(new Vector3(Axis.X), 0.0);
double radius = 0.2;
double height = 1.0;
Body myCylinder = Body.CreateSolidCylinder(origin, radius, height);
myCylinder.Name = "MyCylinder";
myPart1.Bodies.Add(myCylinder);
#endregion
// Make all the geometries in myPart orange.
// When using VSTA, change to these lines instead:
// Byte R1 = 255; Byte G1 = 165; Byte B1 = 0;
// VSTABridge.SetColor(myPart, R1, G1, B1);
#region PartPropertiesStep5
myPart1.Color = Color.Orange;
#endregion
#region PartPropertiesStep6
myPart1.Visible = true;
#endregion
myPart1.PickingEnabled = true;
// Move myPart and all the bodies in it 100 mm along the
// X-axis and 100 mm along the Y-axis.
#region PartPropertiesStep7
myPart1.Transform.X = myPart1.Transform.X + 0.1;
myPart1.Transform.Y = myPart1.Transform.Y + 0.1;
#endregion
// Create a copy of myPart.
#region PartPropertiesStep8
Part myPart2 = (Part)myPart1.Copy();
myPart2.Name = "MyPart_2";
#endregion
// Add myPart2 to the station.
#region PartPropertiesStep9
station.GraphicComponents.Add(myPart2);
#endregion
#region PartPropertiesStep10
GraphicComponentLibrary myLib = myPart2.MoveDefinitionToLibrary();
Logger.AddMessage(new LogMessage(
$"The RootComponent of the Lib is: {myLib.RootComponent.Name}"));
// Save a copy of the lib.
// Get the path to the user project folder.
string userProjPath =
(string)Options.GetValue("RobotStudio", "Directories.UserDocuments");
if (userProjPath != null)
{
myLib.SaveAs(userProjPath + "\\Libraries\\myLib.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
myLib.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myLib.rslib"));
}
#endregion
// Create a new instance of myPart.
#region PartPropertiesStep11
Part myPart3 = (Part)myPart1.CopyInstance();
#endregion
// Add myPart3 to the station.
station.GraphicComponents.Add(myPart3);
// Delete the geometry of myPart3.
// This causes the geometry of myPart1 to be deleted to,
// since they use the same definition.
#region PartPropertiesStep12
myPart3.DeleteGeometry();
#endregion
// Disconnect myPart2 from its library.
#region PartPropertiesStep13
myPart2.DisconnectFromLibrary();
#endregion
// Close the library
myLib.Close();
// Get the normal of myPart2
#region PartPropertiesStep14
BoundingBox bbox = myPart2.GetBoundingBox(true);
Vector3 firstCorner = bbox.min;
Vector3 secondCorner = bbox.max;
Logger.AddMessage(new LogMessage(
$"The first corner of the bounding box is ( {firstCorner.x}; {firstCorner.y}; {firstCorner.z} )"));
Logger.AddMessage(new LogMessage(
$"The second corner of the bounding box is ( {secondCorner.x}; {secondCorner.y}; {secondCorner.z} )"));
Vector3 testPoint = new Vector3(0.0, 0.0, 0.0);
Vector3 hitPoint;
Vector3 hitPointNormal;
Face hitFace;
myPart2.TryGetNormalToSurface(testPoint, out hitPoint, out hitPointNormal, out hitFace);
#endregion
// Make the hitFace green.
// When using VSTA, change to these lines instead:
// Byte R = 0; Byte G = 255; Byte B = 0;
// VSTABridge.SetColor(hitFace, R, G, B);
hitFace.Color = Color.Green;
Logger.AddMessage(new LogMessage(
$"The hit point from GetNormalToSurface at test point (0,0,0) is: ( {hitPoint.x}; {hitPoint.y}; {hitPoint.z} )"));
Logger.AddMessage(new LogMessage(
$"The hit point normal from GetNormalToSurface at test point (0,0,0) is: ( {hitPointNormal.x}; {hitPointNormal.y}; {hitPointNormal.z} )"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}</code></pre>