Adding error handlers to your code is very import to enable you to fix errors that come up from users. This allows them to easily pass the info on so that the developer can fix. Without error handlers, the code will either skip the errors or just bring up a confusing pop of that the… Continue reading Understanding On Error Resume next
Tag: vba
Move Coordinates of Polyline After It Is Already Drawn
Sub MoveCoordinatesPolylineAfterAlreadyDrawn() Dim VFG(7) As Double Dim retCoord(0 To 1) As Double Set acadApp = GetObject(, "AutoCAD.Application") Set acadDoc = acadApp.ActiveDocument Set objss = acadDoc.SelectionSets.Add("ToErase") objss.Select acSelectionSetAll objss.Erase objss.Delete VFG(0) = 0: VFG(1) = 0 'vertex 1 VFG(2) = 0: VFG(3) = -5 'vertex 2 VFG(4) = 10: VFG(5) = -5 'vertex 3 VFG(6) =… Continue reading Move Coordinates of Polyline After It Is Already Drawn
Draw on UCS Front View
Instead of drawing on the default top view. The code below will show how to draw on the front view Sub test() Dim pointUCS As Variant Dim circleObj As AcadCircle Dim centerPoint(0 To 2) As Double Set acadApp = GetObject(, "AutoCAD.Application") Set acadDoc = acadApp.ActiveDocument ' set the world ucs With acadDoc Set currUCS =… Continue reading Draw on UCS Front View
Add a Viewport and Show Front View
This will create a viewport in paper space and instead of the standard top view, the viewport will show as the front view center(0) = 5.4682: center(1) = 1.4055 dblviewdirection(0) = 0: dblviewdirection(1) = -1: dblviewdirection(0) = 0 Set pviewportObj = acadDoc.PaperSpace.AddPViewport(center, vpwidth, 2.2565) pviewportObj.direction = dblviewdirection pviewportObj.Layer = "viewport" pviewportObj.Display True acadDoc.MSpace = True… Continue reading Add a Viewport and Show Front View
Veiwports with TranslateCoordinates and CHSPACE
The code below will draw a viewport in paper space and zoom to an area in model space. It will then create a circle in model space and then change that circle to to papers pace while still keeping the circle in the same location. Note: for this to work, the MSpace has to be… Continue reading Veiwports with TranslateCoordinates and CHSPACE
ByRef vs ByVal
When passing arguments to a procedure (sub or function) the default will be 'byRef' in Excel VBA, thus you don't have to write 'byRef' before the variable. If you want to pass ByVal you have to explicitly write 'ByVal' before the variable. When using ByVal you are only passing a copy of the argument to… Continue reading ByRef vs ByVal
Check If Each Input Box is filled
Many times you don't want a user to proceed until all input boxes are filled. To solve this you can loop through each control with a For Each statement. For Each will be especially useful when you there are many controls and you don't want to reference each name individually. The examples below show how… Continue reading Check If Each Input Box is filled
Clear All Check Boxes In Excel VBA Userform
This example uses a for each loop so that each check box name does not have to be explicitly written out. This is useful when you are adding more control and limit the amount of code you are writing. Better Method Dim ctrl As Control Sub ClearAllButton_Click() For Each ctrl In exportFilesUF.Controls If TypeName(ctrl) =… Continue reading Clear All Check Boxes In Excel VBA Userform
Find Intersect Between Two Block Objects
This code will create two blocks that have a light weight polyline of a triangle and a trapezoid. We want the two object to have a specific gap between them without intersecting. WE CAN DO THIS! No Calculus required. We do this by exploding the block and then offsetting the polyline a specific distance with… Continue reading Find Intersect Between Two Block Objects
Change Tags of all MultiLeader objects
This example shown is for a custom multileader that has additional attributes; although with slight modification it can also work with standard multileader. This is useful when trying to match the pcmarks with the Bill of Material items in a table. The code can be expanded to loop through a BOM table, for simplicity I… Continue reading Change Tags of all MultiLeader objects