DS-precast Posted October 10, 2012 Share Posted October 10, 2012 Hello All I'm trying to write a vba routine which allows me to get the starting width and length of a polyline shape by specifying three points. The polyline will usually be made up of orthographic straight lines (but not always) Points 1 and 2 are the start and end points of the first side, from which I get the starting width and angle of the first side. Point 3 is a point anywhere on the opposite side. The length of the bay is the perpendicular distance between Point 3 and the first side (a line joining Points 1 & 2). I have written a (crude) LISP routine using vlax-curve-getClosestPointTo, but I now would like to write a vba routine to achieve the same thing. The purpose of the routine is to assist in the production of pre-cast floor layout drawings. The polyline shape would be a bay in a building drawing; the width would provide the pre-cast beam length; the length would provide the length of flooring to fill. Can anybody please help or point me in the right direction? Many thanks ;; dtr - degrees to radians ;; rtd - radians to degrees (defun dtr (a) (* pi (/ a 180.0)) ) (defun rtd (a) (/ (* a 180.0 pi)) ) (defun C:bay (/ pt1 pt2 pt3 pt4) (setq OrigCmdEcho (getvar "CMDECHO")); gets CMDECHO value (setvar "CMDECHO" 0); sets to 0 - wont echo on command line (vl-load-com) (setq pt1 (getpoint "\Enter Point 1 : ")) (setq pt2 (getpoint pt1 "\nEnter point 2 : ")) (setq myline (command "_line" pt1 pt2 ""));draws 1st line (setq mylinename (entlast));obtain entity name of myline (setq pt3 (getpoint pt2 "\nEnter Point 3 : ")); get point on opposite side of rectangle (setq Span (distance pt1 pt2)); sets Span = length of myline (setq ang1 (angle pt1 pt2)); sets ang1 equal to line angle (setq mylinenamevla (vlax-ename->vla-object mylinename)); converts to vla object (setq pt4 (vlax-curve-getClosestPointTo mylinenamevla pt3 T)); gets perpendicular point (setq perpline (command "_line" pt3 pt4 "")); draws perpendicular line (setq perplinename (entlast));obtain entity name of perpline (setq bayl (distance pt3 pt4)); sets bay length to length of perpline (princ "\nSpan is : ")(princ Span) (princ "\nBay length is : ")(princ bayl) (command "_erase" mylinename "") (command "_erase" perplinename "") (setvar "CMDECHO" OrigCmdEcho); puts back to original value (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 11, 2012 Share Posted October 11, 2012 I ran the code and not sure where your headed me for precast stuff I would just make a lisp for each basic shape ask L X W etc point to put it at, then you get stuff like its properties using Region & Massprop this gives stuff you need like centroid and area. The codes a bit long winded for a plain rectang. Even drawn on an angle. Pretty sure theirs some tilt panel stuff here on Cadtutor search for it. ---------------- REGIONS ---------------- Area: 11871.234 Perimeter: 549.003 Bounding box: X: 291.749 -- 467.573 Y: 191.899 -- 340.565 Centroid: X: 383.674 Y: 257.132 Moments of inertia: X: 794650878.004 Y: 1770166566.666 Product of inertia: XY: 1174021820.406 Radii of gyration: X: 258.726 Y: 386.153 Principal moments and X-Y directions about centroid: I: 9154728.825 along [0.978 0.208] J: 23258071.958 along [-0.208 0.978] Quote Link to comment Share on other sites More sharing options...
DS-precast Posted October 11, 2012 Author Share Posted October 11, 2012 Hi BIGAL, many thanks for your response. Region & Massprop isn't really what I'm looking for. Maybe I can re-define my problem a bit. This is intended to be a small part of a larger project written in VBA. What I want to do is to click three points on the screen. These points form a triangle (if they're not in a straight line). A line between points 1 & 2 forms the 'base' of the triangle. I can extract the length and angle of the 'base' line of the triangle. I then want to find the perpendicular distance from point 3, to the 'base' of the triangle (the altitude of the triangle). I have achieved this in LISP using vlax-curve-GetClosestPointTo, but I am wondering if there is a similar or equivalent command in VBA. In other words, how can I achieve the same result as my LISP routine, but using VBA. Hope this clarifies. Quote Link to comment Share on other sites More sharing options...
fixo Posted October 11, 2012 Share Posted October 11, 2012 Search on forums for Curve.cls and Vlax.cls to use vlax functions for VBA Quote Link to comment Share on other sites More sharing options...
DS-precast Posted October 11, 2012 Author Share Posted October 11, 2012 Many thanks fixo. I downloaded your file UsingVlax.dvb from another thread, and I'm sure it gives me all I need to crack this nut. I have not yet encountered Class Modules in my VBA programming , so I hope it will also provide an opportunity to increase my programming abilities. In the meantime, and for the benefit of other users, I managed to write some lines of code based on triangular geometry (Heron's Formula - from Wikipedia) to obtain the altitude of the triangle. It's a solution, but maybe not as elegant as it could be. Thanks again. Quote Link to comment Share on other sites More sharing options...
SEANT Posted October 11, 2012 Share Posted October 11, 2012 Unfortunately, I don’t have access to a system with VBA. Are we talking 2D only; this Excel spreadsheet demos a fairly modest computational method. 3D compatibility would be a little more complex but still not too bad. Bay Lenght.zip Quote Link to comment Share on other sites More sharing options...
DS-precast Posted October 12, 2012 Author Share Posted October 12, 2012 Thanks for the reply SEANT. It is for 2d points, not 3D. Your formula provides another interesting alternative. Many thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.