Skip to content

Instantly share code, notes, and snippets.

View beweir's full-sized avatar

Benjamin Weir beweir

  • Canada
View GitHub Profile
@beweir
beweir / ExcelFunction-BLookup.vb
Last active September 27, 2017 05:50
Excel VBA functions
' Find a matching value in a table/range and return the found value else return the default value.
Public Function BLookup(match As String, table As Range, missingValue As Variant) As Variant
Dim result As Variant
Dim r As Range
result = missingValue
For Each r In table.Rows
If match = r.Cells.Value2(1, 1) Then
result = r.Cells.Value2(1, 2)
@beweir
beweir / clsDirectionGrip.vb
Created April 6, 2017 15:55
AutoCAD GripOverrule API sample, demonstrates how to add a direction grip that will change the direction of a polyline when clicked.
Option Explicit On
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.GraphicsInterface
Imports Autodesk.AutoCAD.DatabaseServices
Public Class DirectionGrip
Inherits GripData
@beweir
beweir / clsSampleLabel.vb
Last active April 3, 2017 17:19
Polyline Label Overrule for AutoCAD using .NET APIs; this has been a bit of ad hoc programming to create a tool to use for creating and marking student assignments. The overrule draws labels on each segment of a polyline. Labels include length, bearing, azimuth, deflection and DMS/DD formating features.
Option Explicit On
Imports System.ComponentModel
Imports adb = Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.GraphicsInterface
Imports Autodesk.AutoCAD.Runtime
Public Class SampleLabel
@beweir
beweir / MoveToObjectDataElevation.lsp
Created February 2, 2017 19:00
AutoCAD Lisp routine to move polylines to the elevation specified in an Object Data field.
; Written by: Benjamin Weir
; Description: Defines the MOVETOODELEVATION command which will apply the
; elevation value found in an Object Data field to the elevation of a
; polyline.
;
; The code has minimal error checking and assumes the field value is in
; the Real data type.
(vl-load-com)