Skip to content

Instantly share code, notes, and snippets.

View benkoshy's full-sized avatar

Ben Koshy benkoshy

View GitHub Profile
@benkoshy
benkoshy / autocad_dot_net_API_projections.md
Created January 8, 2026 02:12
autocad .net - matrix projection
// insert the usual references


Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
@benkoshy
benkoshy / autocad_dot_net_API_create_rotated_dimension.md
Last active November 18, 2025 07:06
A method to create a rotated dimension using the AutoCAD .net API

A method to create a rotated dimension using the AutoCAD .net API

protected void drawDimensions(Point3d dimensionPoint, Point3d point1, Point3d point2, double rotation)
{
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
        BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
@benkoshy
benkoshy / tekla-api-dimension-bolts-2-selectGridLine.md
Last active October 24, 2025 00:06
Tekla Open API - Dimensioning Groups of Bolts - How to select a grid line - Part 2
// WARNING - it is REALLY REALLY hard to select a grid using this code.
// I no longer recommend this approach.

public PickGridLine(DrawingHandler drawingHandler, Model model)
{
    if (drawingHandler.GetConnectionStatus())
    {
        this._picker = drawingHandler.GetPicker();
@benkoshy
benkoshy / tekla-api-drawing-revision-no.md
Last active October 15, 2025 23:30
Get Revision Number of Drawings - Tekla Open API

The Tekla API is not very open - one of my peeves is that you cannot access a drawing's revision number, because it is not exposed. Not to worry, you can access it with a hack:

using System;
using System.Collections.Generic;
@benkoshy
benkoshy / tekla-api-access-model-object-from-drawing.md
Last active October 15, 2025 23:19
Tekla API - How to access a drawing's model object?

Sometimes you will want to query an object's properties - that you found in a drawing. How do you do that?

Let us suppose we have a single part. Then we need to:

  • Get the Drawing
  • Get the part identifier
  • Select it in the model
SinglePartDrawing singlePartDrawing = (SinglePartDrawing)drawing;
@benkoshy
benkoshy / then_example.rb
Created July 1, 2025 09:16
An example of then
# https://benkoshy.github.io/2024/12/09/then-ruby-keyword.html
# this is a contrived example
# experiment with it in an IRB console.
# we want to:
# take a string
# add convert it to an int
# add 1 to that
# and then cube it
@benkoshy
benkoshy / google_form_submission_notification.js
Last active July 4, 2025 03:33
Google Scripts API - OnSubmit
function onSubmit(e) {
// some work is done here:
// var form = FormApp.getActiveForm();
// var allResponses = form.getResponses();
// var latestResponse = allResponses[allResponses.length - 1];
// var response = latestResponse.getItemResponses();
// var payload = {};
// for (var i = 0; i < response.length; i++) {
// var question = response[i].getItem().getTitle();
@benkoshy
benkoshy / GetDocumentFromDatabase.md
Last active June 23, 2025 11:20
AutoCAD .net - Accessing the Document from the database
  // We've all seen this line a thousand times before:
  
    Document doc = Application.DocumentManager.CurrentDocument;
    Database db = doc.Database; 
            
  // But what if we already have the database and we want to get the document?
  // Then you could simply do this: 
  
 Document doc = Application.DocumentManager.GetDocument(db);
@benkoshy
benkoshy / outline_ideas.md
Last active January 23, 2025 22:18
Pagy - Ideas on Outline of the Docs

Things which could be improved:

  • Move away from API docs and Extras "docs" as separate pages ----> makes things harder to find and needlessly complicated.
  • Improve "discoverability" problem. i.e. for example - to help readers answer the question: "which extras do I need, and why?" I feel I can improve upon this currently.

The rest:

  • The rest of the docs seem pretty good. We have config options for advanced use cases.

Questions:

@benkoshy
benkoshy / go-fibonacci.md
Created December 31, 2024 00:05
Go - Tour exercise - Fibonacci