Get distances between selected polylines

Get distances between selected polylines

DC-MWA
Collaborator Collaborator
3,059 Views
35 Replies
Message 1 of 36

Get distances between selected polylines

DC-MWA
Collaborator
Collaborator

Hello all,

I'm working on a routine to assist in calculating frontage increase for building area.

At this point there is a lot of clicking/picking involved with getting the input data from the user

;;pick wall face points
(setq P1 (getpoint "\nPick 1st end of wall: "))
(setq P2 (getpoint "\nPick 2nd end of wall: "))
(setq F (distance P1 P2))

;;pick yard points
(setq Y1 (getpoint "\nPick building corner: "))
(setvar "osmode" 640)
(setq Y2 (getpoint Y1 "\nPick perpendicular property line or center of public way: "))
(setvar "osmode" 1)
(setq Y3 (getpoint "\nPick building corner: "))
(setvar "osmode" 640)
(setq Y4 (getpoint Y3 "\nPick perpendicular property line or center of public way: "))

(setq DIST1 (distance Y1 Y2))
(setq DIST2 (distance Y3 Y4))

 

I'm looking to simplify the selection process. I'm hoping somebody has already done something similar.

I have provided an image of what I'm hoping to achieve

Frontage1.JPG

0 Likes
Accepted solutions (1)
3,060 Views
35 Replies
Replies (35)
Message 21 of 36

DC-MWA
Collaborator
Collaborator

Thank you very much.

 

First:

(setq P get total perimeter of the building polyline (once)

 

In the loop:

(setq W ....    add left dist and right dist then divide the sum by 2;  to get the "weighted average"

if W is greater than 20 add to running total

if W is greater than 30, set W as 30.

(setq F...    get length of the building  polyline segment

 

After loop:

Show W total

Show F total

 

goal is to process this equation:

If = [F/P - 0.25]w/30

 

0 Likes
Message 22 of 36

DC-MWA
Collaborator
Collaborator

Disregard previous post.

I will clarify when i get back to my desk.

0 Likes
Message 23 of 36

DC-MWA
Collaborator
Collaborator

Hello Mr Cooper,

Sorry for delay in reply, The perpendicular and 640 (perp + near) were my weak attempt at getting points either perpendicular or nearest if sloped pl. Only worked on simple square or rectangle buildings. And yes, this is very complicated. I have been testing with dlanorh's program and if I had vertices to the polyline boundary where projections intersect other buildings or property lines change direction it works well.

-dc

0 Likes
Message 24 of 36

DC-MWA
Collaborator
Collaborator

Hello,

I apologize for delay, had DSA submittal to finish yesterday.

Thank you so much for assistance with this.

 

First let me say that I have tested the functionality of this program on dozens of real project drawings with varying shaped property lines and building outlines. It seems to be pretty much bullet proof.

 

To clarify how I need information returned/displayed:

For each building boundary segment:

P = get perimeter of building (total length of all polyline segments) <1 time only>

F = get segment length of building boundary polyline selected <add to Ftotal>

D1 = get left distance

D2 = get right distance

WAV = (D1 + D2)/2 (Note: if WAV <20  WAV = 0,  if WAV >30  WAV=30)

YARD = (WAV * F) <add to YARDtotal>

Display to user (princ...)

F

D1

D2

WAV

 

After all building boundary segments are selected:

Display to user (alert...)

P

Ftotal

YARDtotal

 

At this point I can take the information gathered and use for Frontage coefficient.

 

I hope this helps to clarify things.

Again, thank you very much for your time.

-dc

 

 

 

0 Likes
Message 25 of 36

dlanorh
Advisor
Advisor

Seems simple enough, but one question, if wav < 20 then wav = 0 thus yard = 0 but you still want f added to ftotal; is this correct?

I am not one of the robots you're looking for

0 Likes
Message 26 of 36

dlanorh
Advisor
Advisor

Mk2. Test if this produces what you want and there are no glaring errors. I've briefly tested to ensure Left and Right are correct (as viewed from the building), and if all segments are selected the total agrees with the perimeter. I've tried to keep variable names in line with your outline, although some differ.

 

(defun rh:cwpl ( obj / o_obj)
  (setq o_obj (car (vlax-invoke obj 'Offset -0.01)) cw (if (> (vlax-get-property o_obj 'area) (vlax-get-property obj 'area)) T nil))
  (vla-delete o_obj)
  cw
);end_defun

(defun c:test ( / *error* c_doc c_spc sv_lst sv_vals lu lp tyard tslen d_ent sel elen v_lst vlen p_pt v_p pt1 pt2 ang chk slen b_obj x_obj pt3 pt4 d1 d2 wav yard)

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        sv_lst (list 'cmdecho 'osmode)
        sv_vals (mapcar 'getvar sv_lst)
        lu (getvar 'lunits)
        lp (getvar 'luprec)
        tyard 0
        tslen 0
  );end_setq

  (mapcar 'setvar sv_lst (list 0 0))

  (setq b_obj (vlax-ename->vla-object (car (entsel "\nSelect Boundary Polyline : "))))

  (while (setq sel (entsel "\nSelect Building Polyline on Frontage : "))
    (setq d_ent (car sel)
          elen (vlax-curve-getdistatparam d_ent (vlax-curve-getendparam d_ent))
          v_lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget d_ent)))
          vlen (length v_lst)
          p_pt (cadr sel)
          v_p (fix (vlax-curve-getparamatpoint d_ent (vlax-curve-getclosestpointto d_ent p_pt)))
          pt1 (reverse (cons 0.0 (reverse (nth v_p v_lst))))
          pt2 (if (= v_p (1- vlen)) (reverse (cons 0.0 (reverse (nth 0 v_lst)))) (reverse (cons 0.0 (reverse (nth (1+ v_p) v_lst)))))
    );end_setq

    (if (rh:cwpl (vlax-ename->vla-object d_ent))
      (setq ang (+ (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv d_ent v_p)) (* pi 0.5)) chk T)
      (setq ang (- (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv d_ent v_p)) (* pi 0.5)) chk nil)
    );end_if

    (setq slen (distance pt1 pt2) tslen (+ tslen slen)
          x_obj (vlax-invoke c_spc 'addray pt1 (polar pt1 ang 10.0))
          pt3 (vlax-invoke x_obj 'intersectwith b_obj acextendnone)
    );end_setq

    (vlax-invoke x_obj 'move pt1 pt2)
    (setq pt4 (vlax-invoke x_obj 'intersectwith b_obj acextendnone))
    (vla-delete x_obj)

    (if chk (setq d1 (distance pt1 pt3) d2 (distance pt2 pt4)) (setq d1 (distance pt2 pt4) d2 (distance pt1 pt3)))

    (setq wav (/ (+ d1 d2) 2.0))

    (cond ( (< wav 20.0) (setq wav 0 yard 0.0))
          ( (> wav 30.0) (setq wav 30 yard (* wav slen)) tyard (+ tyard yard))
          (t (setq yard (* wav slen) tyard (+ yard tyard)))
    );end_cond

    (alert (strcat "Length of Segment (F) : " (rtos slen lu lp)
                   "\n\nDistance to Boundary (L) : " (rtos d1 lu lp)
                   "\n\nDistance to Boundary (R) : " (rtos d2 lu lp)
                   "\n\nAverage Distance to Boundary : " (rtos wav lu lp)
           );end_strcat
    );end_alert

  );end_while

  (alert (strcat "Building Perimeter Length : " (rtos elen lu lp)
                 "\n\nTotal Segment Length : " (rtos tslen lu lp)
                 "\n\nTotal Yard : " (rtos tyard lu lp)
         );end_strcat
  );end_alert

  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

I am not one of the robots you're looking for

0 Likes
Message 27 of 36

DC-MWA
Collaborator
Collaborator

Good catch.

If WAV=0 do not add F to Ftotal.

0 Likes
Message 28 of 36

dlanorh
Advisor
Advisor

@DC-MWA wrote:

Good catch.

If WAV=0 do not add F to Ftotal.



OK, amended lisp attached to cover the above

I am not one of the robots you're looking for

0 Likes
Message 29 of 36

DC-MWA
Collaborator
Collaborator

Tested:  See image for results...

 

Capture.JPG

Message 30 of 36

dlanorh
Advisor
Advisor

Can you attach the test drawing as dxf or saved as Autocad 2010 or earlier. My initial though is that this is a units problem.

I am not one of the robots you're looking for

0 Likes
Message 31 of 36

DC-MWA
Collaborator
Collaborator

here you go...

0 Likes
Message 32 of 36

dlanorh
Advisor
Advisor
Accepted solution

Many thanks, that helped no end. It was 95% a units problem, and a misplaced closing brace on one of the conditions. The average distance at 2' 6" (30") when it should have been 30' was the biggest hint. The routine now works for architectural units and decimal units and hopefully decimal feet.

 

I have made one small change that you should be aware of. I change the DIMZIN value to 1 from 3. A setting of 3 was suppressing 0' when wav was less than 20' (I'm picky).  This should reset to the entry state when exiting properly or through the error routine. I have left a comment over the main routine that should it exit disgracefully that the three changed sysvars will need to be manually reset.

 

Updated attached. If you get any problem let me know.

 

 

 

I am not one of the robots you're looking for

Message 33 of 36

DC-MWA
Collaborator
Collaborator

Thank you very much!

I have been testing vigorously, works great.

I am able to utilize the variables and complete formulas needed for calculations.

A truly appreciate your time and effort on this.

-dc

0 Likes
Message 34 of 36

Sea-Haven
Mentor
Mentor

Just read this post, the ability to move a building with regard to constraints was solved over 30 years ago in a 3rd party Civil product Civilcad here in Aus, it had various options like slide on a line maintaining a distance and used a increment function to move the building so you could get a better compromise without trying to fix values. It dynamically displayed the offsets as you moved. So a rectang lot, ortho building was a simple 2 side enter increment and done.

0 Likes
Message 35 of 36

DC-MWA
Collaborator
Collaborator

This program is ultimately used to calculate the frontage increase calculations for the california building code.

I have added formulas using the variables it produces to do the increase calculations.

 

0 Likes
Message 36 of 36

Sea-Haven
Mentor
Mentor

Understand, but you still have the side offsets that must meet code at the same time, so a building envelope may not meet the requirements.

0 Likes