counting all assemblies in tekla multidrawings
Here's a C# script using the Tekla Open API to count the number of assemblies in a multi-drawing. This script will
1. Open the currently active multi-drawing in Tekla Structures.
2. Iterate through all drawing objects and count the assemblies.
3. Print the total number of assemblies found in the multi-drawing.
C# Code: Count Assemblies in a Multi-Drawing
using System;
using Tekla.Structures.Drawing;
using Tekla.Structures.Model;
using Tekla.Structures.Model.Drawing;
class Program
{
static void Main()
{
// Open the currently active drawing
DrawingHandler drawingHandler = new DrawingHandler();
if (!drawingHandler.GetConnectionStatus())
{
Console.WriteLine("Tekla Structures is not running or not connected.");
return;
}
Drawing currentDrawing = drawingHandler.GetActiveDrawing();
if (currentDrawing == null)
{
Console.WriteLine("No active drawing found.");
return;
}
Console.WriteLine("Active Drawing: " + currentDrawing.Name);
// Initialize counter
int assemblyCount = 0;
// Iterate through all drawing objects
DrawingObjectEnumerator drawingObjects = currentDrawing.GetSheet().GetAllObjects();
while (drawingObjects.MoveNext())
{
if (drawingObjects.Current is AssemblyDrawing assemblyDrawing)
{
assemblyCount++;
}
}
Console.WriteLine($"Total Assemblies in Multi-Drawing: {assemblyCount}");
}
}
How It Works
1. Connects to Tekla Structures using DrawingHandler.
2. Retrieves the active drawing using drawingHandler.GetActiveDrawing().
3. Iterates through all objects in the drawing to find AssemblyDrawing objects.
4. Counts the assemblies and displays the result.
How to Use
1. Open Tekla Structures and load a multi-drawing.
2. Run the C# script inside a Tekla API environment (e.g., a Tekla plugin or standalone application).
3. It will display the total number of assemblies in the multi-drawing.
Additional Enhancements
If you need to filter by specific assembly types, modify the if condition.
If you want to list each assembly’s mark or ID, use:
Console.WriteLine($"Assembly: {assemblyDrawing.AssemblyNumber}");
If you want to count only visible assemblies, apply additional filtering based on Visibility properties.
Here's a C# script using the Tekla Open API to count the number of assemblies in a multi-drawing. This script will
1. Open the currently active multi-drawing in Tekla Structures.
2. Iterate through all drawing objects and count the assemblies.
3. Print the total number of assemblies found in the multi-drawing.
C# Code: Count Assemblies in a Multi-Drawing
using System;
using Tekla.Structures.Drawing;
using Tekla.Structures.Model;
using Tekla.Structures.Model.Drawing;
class Program
{
static void Main()
{
// Open the currently active drawing
DrawingHandler drawingHandler = new DrawingHandler();
if (!drawingHandler.GetConnectionStatus())
{
Console.WriteLine("Tekla Structures is not running or not connected.");
return;
}
Drawing currentDrawing = drawingHandler.GetActiveDrawing();
if (currentDrawing == null)
{
Console.WriteLine("No active drawing found.");
return;
}
Console.WriteLine("Active Drawing: " + currentDrawing.Name);
// Initialize counter
int assemblyCount = 0;
// Iterate through all drawing objects
DrawingObjectEnumerator drawingObjects = currentDrawing.GetSheet().GetAllObjects();
while (drawingObjects.MoveNext())
{
if (drawingObjects.Current is AssemblyDrawing assemblyDrawing)
{
assemblyCount++;
}
}
Console.WriteLine($"Total Assemblies in Multi-Drawing: {assemblyCount}");
}
}
How It Works
1. Connects to Tekla Structures using DrawingHandler.
2. Retrieves the active drawing using drawingHandler.GetActiveDrawing().
3. Iterates through all objects in the drawing to find AssemblyDrawing objects.
4. Counts the assemblies and displays the result.
How to Use
1. Open Tekla Structures and load a multi-drawing.
2. Run the C# script inside a Tekla API environment (e.g., a Tekla plugin or standalone application).
3. It will display the total number of assemblies in the multi-drawing.
Additional Enhancements
If you need to filter by specific assembly types, modify the if condition.
If you want to list each assembly’s mark or ID, use:
Console.WriteLine($"Assembly: {assemblyDrawing.AssemblyNumber}");
If you want to count only visible assemblies, apply additional filtering based on Visibility properties.
Here's a C# script using the Tekla Open API to count the number of assemblies in a multi-drawing. This script will
1. Open the currently active multi-drawing in Tekla Structures.
2. Iterate through all drawing objects and count the assemblies.
3. Print the total number of assemblies found in the multi-drawing.
C# Code: Count Assemblies in a Multi-Drawing
using System;
using Tekla.Structures.Drawing;
using Tekla.Structures.Model;
using Tekla.Structures.Model.Drawing;
class Program
{
static void Main()
{
// Open the currently active drawing
DrawingHandler drawingHandler = new DrawingHandler();
if (!drawingHandler.GetConnectionStatus())
{
Console.WriteLine("Tekla Structures is not running or not connected.");
return;
}
Drawing currentDrawing = drawingHandler.GetActiveDrawing();
if (currentDrawing == null)
{
Console.WriteLine("No active drawing found.");
return;
}
Console.WriteLine("Active Drawing: " + currentDrawing.Name);
// Initialize counter
int assemblyCount = 0;
// Iterate through all drawing objects
DrawingObjectEnumerator drawingObjects = currentDrawing.GetSheet().GetAllObjects();
while (drawingObjects.MoveNext())
{
if (drawingObjects.Current is AssemblyDrawing assemblyDrawing)
{
assemblyCount++;
}
}
Console.WriteLine($"Total Assemblies in Multi-Drawing: {assemblyCount}");
}
}
How It Works
1. Connects to Tekla Structures using DrawingHandler.
2. Retrieves the active drawing using drawingHandler.GetActiveDrawing().
3. Iterates through all objects in the drawing to find AssemblyDrawing objects.
4. Counts the assemblies and displays the result.
How to Use
1. Open Tekla Structures and load a multi-drawing.
2. Run the C# script inside a Tekla API environment (e.g., a Tekla plugin or standalone application).
3. It will display the total number of assemblies in the multi-drawing.
Additional Enhancements
If you need to filter by specific assembly types, modify the if condition.
If you want to list each assembly’s mark or ID, use:
Console.WriteLine($"Assembly: {assemblyDrawing.AssemblyNumber}");
If you want to count only visible assemblies, apply additional filtering based on Visibility properties.
Comments
Post a Comment