BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.

Creating Dimension Elements for Walls Based on Input File Data(csv)

sercet65
Booster

Hello,

I'm currently working on a project where I need to automatically create dimension elements for walls in ArchiCAD based on data from an input file. I have a CSV file containing information such as the GUID of the walls, their bounding box coordinates, and their lengths.

Here's a brief overview of what I'm trying to achieve:

-Read all data from a CSV file.
-Create dimension lines for each wall based on its length, as provided in the input file.
I've implemented a function to read the wall data from the CSV file, but I'm unsure if my logic for parsing the CSV file is correct. Additionally, I've created a function to create dimension lines for each wall using the ArchiCAD API. However, I'm encountering difficulties in accurately placing the dimension lines next to the corresponding walls based on the length information provided in the input file.

 

 

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "ACAPinc.h" // Ensure you include the correct headers for ArchiCAD API

struct WallData {
    std::string guid;
    double bb_xmin, bb_ymin, bb_xmax, bb_ymax;
    int labelType;
};

std::vector<WallData> ReadWallDataFromCSV(const std::string& filePath) {
    std::vector<WallData> walls;
    std::ifstream file(filePath);
    std::string line;

    // Skipping the header
    std::getline(file, line);

    while (std::getline(file, line)) {
        std::istringstream iss(line);
        std::string token;
        WallData data;

        // Skipping columns to reach the GUID (adjust if GUID is not the first column)
        std::getline(iss, data.guid, ',');

        // Skipping columns to reach bb_xmin, which is the 10th column including guid
        for (int i = 0; i < 8; ++i) std::getline(iss, token, ',');
        data.bb_xmin = std::stod(token);
        std::getline(iss, token, ',');
        data.bb_ymin = std::stod(token);
        std::getline(iss, token, ','); // Skipping zmin
        std::getline(iss, token, ',');
        data.bb_xmax = std::stod(token);
        std::getline(iss, token, ',');
        data.bb_ymax = std::stod(token);

        // Skipping to the label_type, which is the 20th column from the start
        for (int i = 0; i < 9; ++i) std::getline(iss, token, ',');
        if (std::stoi(token) == 1) { // Add wall if label_type == 1
            walls.push_back(data);
        }
    }

    return walls;
}

void CreateDimensionLinesForWalls(const std::vector<WallData>& walls) {
    for (const auto& wall : walls) {
        double length = wall.bb_xmax - wall.bb_xmin; // Calculate wall length
        

        API_Element element;
        BNZeroMemory(&element, sizeof(API_Element));

        API_ElementMemo memo;
        BNZeroMemory(&memo, sizeof(API_ElementMemo));

        // Example setup for dimension line (add details as needed)
        // Important: Ensure to populate the memo with the correct details as per API requirements

        GSErrCode err = ACAPI_Element_Create(&element, &memo);
        if (err != NoError) {
            std::cerr << "Failed to create dimension line for wall GUID: " << wall.guid << " Error: " << err << std::endl;
        }
        else {
            std::cout << "Dimension line created for wall GUID: " << wall.guid << std::endl;
        }

        // Dispose of memo handles if allocated
        ACAPI_DisposeElemMemoHdls(&memo);
    }
}

void AutomaticAnnotation() {
    std::string filePath = "C:\\API Development Kit 27.3001\\Server Add on\\Extraction_V2 c\\Extraction_V2\\build\\Debug\nodes_data_1.csv"; // Adjust the file path as necessary
    auto walls = ReadWallDataFromCSV(filePath);
    CreateDimensionLinesForWalls(walls);

    // You might want to log or indicate completion
    ACAPI_WriteReport(GS::UniString("Automatic Wall Annotation Complete"), true);
}

 

 

Could anyone review my logic for reading the CSV file and provide feedback on its correctness? Furthermore, I would greatly appreciate any guidance on how I can properly position the dimension lines relative to the walls based on the wall length data in my input file.

sercet65_0-1710458992777.png

This how my input file looks like.

 

Thank you for your support!

0 REPLIES 0
Learn and get certified!