Store User Selected Inputs in Variables

Store User Selected Inputs in Variables

Anonymous
Not applicable
523 Views
2 Replies
Message 1 of 3

Store User Selected Inputs in Variables

Anonymous
Not applicable

I am new to writing AutoCAD macros in VBA and need some help. I've written a couple of simple macros in SolidWorks starting with the record function and then doing minor edits.

 

I want a macro that generates geometry (a weld pattern in this case) based on user input.

  1. The macro prompts the user to select a polyline and two end points
  2. The selections just made are stored inside variables as a length and two pairs of cartesian coordinates
  3. I use those inputs to calculate the necessary parameters and generate the weld pattern about the selection.

The problem I am having is figuring out how to store the user inputs properly. I was messing around with "GetEntity" and "InitializeUserInput" but all they seemed to accomplish was identify what type of entity the user had selected. I need the dimensions so I can caclulate the necessary geometry to build the weld pattern.

 

Make Believe Example Code:

-Prompt window comes up and user selects Polyline, Start Point and End Point

Length = 45.000 'from polyline selected

Type = AcadLWPolyline 'stores what type of entity it is

Start Point = (20.000, 30.000) 'start point that was selected

End Point = (150.000, 300.000) 'end point that was selected

-The rest of my code doing all the necessary calcs and draw functions

 

I want all those variables to be driven by the user input. Is there anyway to do this?

0 Likes
524 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Been messing around with the GetEntity and GetPoint functions and it seems they have the functionality I need. I think I figured it out, no need to respond to this post unless someone has useful tips on how to use these functions.

0 Likes
Message 3 of 3

truss_85
Advocate
Advocate

I change a little bit I hope it is helpful

no need to select end points only polyline needed

coord is a matrix 0 to what else

odd index gives y coordinates of a vertex,

even index gives x coordinates of a vertex,

lgt is the length of the polyline.

take a look help menu of acad will be good for you...

here is the code 

 

Public Sub example()
Dim oEnt As AcadEntity
Dim Pt As Variant
Dim oLWP As AcadLWPolyline
ThisDrawing.Utility.GetEntity oEnt, Pt, "select a pline"
If TypeOf oEnt Is AcadLWPolyline Then
Set oLWP = oEnt
Else
MsgBox "entity must be polyline", vbCritical
End If
coord = oLWP.Coordinates
lgt = oLWP.Length
End Sub

Public Sub example()
Dim oEnt As AcadEntityDim Pt As VariantDim oLWP As AcadLWPolyline
End Sub

 

0 Likes