Customizing azimuth/distance display for automated survey plats

Customizing azimuth/distance display for automated survey plats

buchistyle
Participant Participant
585 Views
8 Replies
Message 1 of 9

Customizing azimuth/distance display for automated survey plats

buchistyle
Participant
Participant

Hello, 

Please I have the code below which I have been using for several years. I got the code from this forum and after some modifications it has served me just fine. The code is:

(vl-load-com)
(defun c:brg69 ( / l_var js htx AcDoc Space ss nw_style n obj ename pr dist_start dist_end pt_start pt_end seg_len alpha val_txt dim_txt nw_obj)
(setq l_var (mapcar 'getvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS")))
(mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") '(1 2 2 2))
(princ "\nSelect polylines or lines.")
(while (null (setq js (ssget '((0 . "LWPOLYLINE,LINE")))))
(princ "\nSelection is empty or not are LWPOLYLINE,LINE!")
)
(initget 6)
(setq htx (getdist (getvar "VIEWCTR") (strcat "\nSpecify text height <" (rtos (getvar "TEXTSIZE")) ">: ")))
(if htx (setvar "TEXTSIZE" htx))
(setq
AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
Space
(if (= 1 (getvar "CVPORT"))
(vla-get-PaperSpace AcDoc)
(vla-get-ModelSpace AcDoc)
)
ss (ssadd)
)
(vla-startundomark AcDoc)
(cond
((null (tblsearch "LAYER" "DIMENSIONS"))
(vlax-put (vla-add (vla-get-layers AcDoc) "DIMENSIONS") 'color 7)
)
)
(cond
((null (tblsearch "STYLE" "LABEL_ARIAL"))
(setq nw_style (vla-add (vla-get-textstyles AcDoc) "LABEL_ARIAL"))
(mapcar
'(lambda (pr val)
(vlax-put nw_style pr val)
)
(list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
(list (strcat (getenv "windir") "\\fonts\\arial.ttf") 0.0 0.0 1.0 0.0)
)
)
)
(repeat (setq n (sslength js))
(setq
obj (ssname js (setq n (1- n)))
ename (vlax-ename->vla-object obj)
pr -1
)
(cond
((eq (cdr (assoc 0 (entget obj))) "LWPOLYLINE")
(repeat (fix (vlax-curve-getEndParam ename))
(setq
dist_start (vlax-curve-GetDistAtParam ename (setq pr (1+ pr)))
dist_end (vlax-curve-GetDistAtParam ename (1+ pr))
pt_start (vlax-curve-GetPointAtParam ename pr)
pt_end (vlax-curve-GetPointAtParam ename (1+ pr))
seg_len (- dist_end dist_start)
alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
val_txt (vl-string-subst "%%d" "d"(strcat (angtos alpha) "\\P " (rtos seg_len)))
dim_txt (textbox (list (cons 1 val_txt)))
)
(if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
(if (> (distance (car dim_txt) (cadr dim_txt)) seg_len)
(setq val_txt (vl-string-subst "E \\P" "E " val_txt))
)
(setq nw_obj
(vla-addMtext Space
(vlax-3d-point (setq pt (vlax-curve-GetPointAtParam ename (+ 0.5 pr))))
0.0
val_txt
)
)
(mapcar
'(lambda (pr val)
(vlax-put nw_obj pr val)
)
(list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
(list 5 (getvar "TEXTSIZE") 5 pt "LABEL_ARIAL" "DIMENSIONS" alpha)
)
(setq ss (ssadd (entlast) ss))
)
)
(T
(setq
pt_start (vlax-curve-GetStartPoint ename)
pt_end (vlax-curve-GetEndPoint ename)
seg_len (distance pt_start pt_end)
alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
val_txt (vl-string-subst "%%d" "d"(strcat (angtos alpha) "\\P " (rtos seg_len)))
dim_txt (textbox (list (cons 1 val_txt)))
)
(if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
(if (> (distance (car dim_txt) (cadr dim_txt)) seg_len)
(setq val_txt (vl-string-subst "E \\P" "E " val_txt))
)
(setq nw_obj
(vla-addMtext Space
(vlax-3d-point (setq pt (mapcar '* (mapcar '+ (vlax-curve-GetStartPoint ename) (vlax-curve-GetEndPoint ename)) '(0.5 0.5 0.5))))
0.0
val_txt
)
)
(mapcar
'(lambda (pr val)
(vlax-put nw_obj pr val)
)
(list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
(list 5 (getvar "TEXTSIZE") 5 pt "LABEL_ARIAL" "DIMENSIONS" alpha)
)
(setq ss (ssadd (entlast) ss))
)
)
)
(vla-endundomark AcDoc)
(mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") l_var)
(sssetfirst nil ss)
(prin1)
)

 

I need the azimuths to come above the distances if the line direction points from 0 degrees (North) to 180 degrees (South) and I need the distances to come above the azimuths if the given line points anywhere from 180d 01' to just below 0 degrees (or 359d 59').

 

So far the current result is as shown:

buchistyle_1-1722960034540.png

 

I would like to automate the process to produce this:

buchistyle_2-1722960160417.png

Please I would very much appreciate any help given. Thanks.

 

0 Likes
586 Views
8 Replies
Replies (8)
Message 2 of 9

Moshe-A
Mentor
Mentor

@buchistyle  hi,

 

check this, the correction is on lines: 61 & 88

 

enjoy

Moshe

 

 

(vl-load-com)

(defun c:brg69 ( / l_var js htx AcDoc Space ss nw_style n obj ename pr dist_start dist_end pt_start pt_end seg_len alpha val_txt dim_txt nw_obj)
 (setq l_var (mapcar 'getvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS")))
 (mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") '(1 2 2 2))
  
 (princ "\nSelect polylines or lines.")
 (while (null (setq js (ssget '((0 . "LWPOLYLINE,LINE")))))
  (princ "\nSelection is empty or not are LWPOLYLINE,LINE!")
 )
  
 (initget 6)
 (setq htx (getdist (getvar "VIEWCTR") (strcat "\nSpecify text height <" (rtos (getvar "TEXTSIZE")) ">: ")))
 (if htx (setvar "TEXTSIZE" htx))
  
 (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
      Space
        (if (= 1 (getvar "CVPORT"))
         (vla-get-PaperSpace AcDoc)
         (vla-get-ModelSpace AcDoc)
        )
     ss (ssadd)
 )
  
 (vla-startundomark AcDoc)
  
 (cond
  ((null (tblsearch "LAYER" "DIMENSIONS"))
   (vlax-put (vla-add (vla-get-layers AcDoc) "DIMENSIONS") 'color 7)
  )
 )
  
 (cond
  ((null (tblsearch "STYLE" "LABEL_ARIAL"))
   (setq nw_style (vla-add (vla-get-textstyles AcDoc) "LABEL_ARIAL"))
   (mapcar
    '(lambda (pr val)
      (vlax-put nw_style pr val)
     )
    (list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
    (list (strcat (getenv "windir") "\\fonts\\arial.ttf") 0.0 0.0 1.0 0.0)
   )
  )
 )
  
 (repeat (setq n (sslength js))
  (setq obj (ssname js (setq n (1- n)))
        ename (vlax-ename->vla-object obj)
        pr -1
  )
  (cond
   ((eq (cdr (assoc 0 (entget obj))) "LWPOLYLINE")
    (repeat (fix (vlax-curve-getEndParam ename))
     (setq dist_start (vlax-curve-GetDistAtParam ename (setq pr (1+ pr)))
           dist_end (vlax-curve-GetDistAtParam ename (1+ pr))
           pt_start (vlax-curve-GetPointAtParam ename pr)
           pt_end (vlax-curve-GetPointAtParam ename (1+ pr))
           seg_len (- dist_end dist_start)
           alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
           ; val_txt (vl-string-subst "%%d" "d"(strcat (angtos alpha) "\\P " (rtos seg_len)))
           val_txt (vl-string-subst "%%d" "d" (strcat (rtos seg_len) "\\P " (angtos alpha)))
           dim_txt (textbox (list (cons 1 val_txt)))
     )
      
     (if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
     (if (> (distance (car dim_txt) (cadr dim_txt)) seg_len)
      (setq val_txt (vl-string-subst "E \\P" "E " val_txt))
     )
      
     (setq nw_obj (vla-addMtext Space (vlax-3d-point (setq pt (vlax-curve-GetPointAtParam ename (+ 0.5 pr)))) 0.0 val_txt))
      
     (mapcar
      '(lambda (pr val)
        (vlax-put nw_obj pr val)
       )
      (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
      (list 5 (getvar "TEXTSIZE") 5 pt "LABEL_ARIAL" "DIMENSIONS" alpha)
     )
     (setq ss (ssadd (entlast) ss))
    ); repeat
   ); case
   (T
    (setq pt_start (vlax-curve-GetStartPoint ename)
          pt_end (vlax-curve-GetEndPoint ename)
          seg_len (distance pt_start pt_end)
          alpha (angle (trans pt_start 0 1) (trans pt_end 0 1))
          ; val_txt (vl-string-subst "%%d" "d"(strcat (angtos alpha) "\\P " (rtos seg_len)))
          val_txt (vl-string-subst "%%d" "d" (strcat (rtos seg_len) "\\P " (angtos alpha)))
          dim_txt (textbox (list (cons 1 val_txt)))
    )
    
    (if (and (> alpha (* pi 0.5)) (< alpha (* pi 1.5))) (setq alpha (+ alpha pi)))
    (if (> (distance (car dim_txt) (cadr dim_txt)) seg_len)
     (setq val_txt (vl-string-subst "E \\P" "E " val_txt))
    )
    (setq nw_obj (vla-addMtext Space (vlax-3d-point (setq pt (mapcar '* (mapcar '+ (vlax-curve-GetStartPoint ename) (vlax-curve-GetEndPoint ename)) '(0.5 0.5 0.5)))) 0.0 val_txt))
    
    (mapcar
     '(lambda (pr val)
       (vlax-put nw_obj pr val)
      )
     (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
     (list 5 (getvar "TEXTSIZE") 5 pt "LABEL_ARIAL" "DIMENSIONS" alpha)
    )
    (setq ss (ssadd (entlast) ss))
   ); case
  ); cond
 ); repeat
  
 (vla-endundomark AcDoc)
 (mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") l_var)
 (sssetfirst nil ss)
 (prin1)
); c:brg69

 

0 Likes
Message 3 of 9

buchistyle
Participant
Participant

Thanks @Moshe-A. But I actually am looking for distances to come over azimuth if and only if the line points anywhere in the direction of 180d 01' all the way to 359d 59'. And vice versa if and only if the line points anywhere in the direction of 0d all the way to 180d. The final product will have the distances inside the space enclosed by the red lines and the azimuths outside. I don't know lisp but I know it's a conditional/logic problem in other programming languages. Can you help with that please?

0 Likes
Message 4 of 9

buchistyle
Participant
Participant

@Moshe-A Something like:

if line_azimuth >= 0 <=180 then distance should come over azimuth

else azimuth should come over distance

🙂You know, something like that?

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

It sounds to me like the which-is-over-the-other issue is going to depend on your always drawing your outlines in the same direction [clockwise vs. counter-clockwise].  Are you completely and unfailingly consistent about that in your drawing procedure?  Do you ever Mirror one and spoil that?

 

If the outline is a Polyline, rather than separate Lines, it can have one of those pieces of information always placed inside and the other outside, whether its drawn direction is CW or CCW.  Would that serve your purpose?  For example, you could use the DPI command defined in DimPoly.lsp, >here<, with a Dimension Style that has both extension lines and both dimension lines suppressed, to get the lengths on the inside.  It might not be too hard to modify that to add the directions on the outside, but it does depend on the boundary being one Polyline, not Lines.

Kent Cooper, AIA
0 Likes
Message 6 of 9

buchistyle
Participant
Participant

Hello @Kent1Cooper,

Yes I am consistent in drawing lines in the clockwise direction as the correct (or intended) azimuth readings depends on that. The distance over azimuth or azimuth over distance actually doesn't depend on which (clockwise or anticlockwise) I do. One is always over the other. It only results in a forward azimuth or backward azimuth is all.

I will try out your provided lisp and see how it works then I will reach out. All I can say for now is making my outlines with a polyline as opposed to lines isn't a hard sacrifice to make; actually it's no sacrifice at all. I do that sometimes with the posted lisp code and it produces the same results, lines or polylines.

 

I appreciate. I will get back soon

0 Likes
Message 7 of 9

buchistyle
Participant
Participant

I don't have access to my laptop currently so I can't apply the latest suggestions but I have been engrossed by the challenge since yesterday. At a point I copied the code to an AI chatbot from You.com and did a little prompting, expecting a quick resolution to the problem as I usually get when stuck in python and can you believe it? The AI actually asked me for sometime to review the code and get back to me with modifications. I gave up waiting. So to all y'all who speak the lisp lingo I honestly and in deep humility doff my hat in respect.

 

I have gone through the code to see if something will speak to me and I have noticed that a section of the code is repeated and I wonder why. I suspect these sections handle the logic but why the exact same syntax is what I don't understand. In @Moshe-A 's code they are lines 65 through 67 and lines 92 through 94.

 

How does the logic here work? Is it like

 

if condition A:

then y 

else:

 

Or is it more like: 

if condition A:

then y 

If condition B:

then x

 

If the latter is the case, how does the code deal with identifying when a given line or polyline segment points in the direction of 0d to 180d.

 

Lines 65 and 92 of the current code seem to deal with situations where the line direction is 180d 01' to 359d 59' am I right? Is there an else or otherwise in the code to handle the other condition. Could this be the solution to the challenge? 

 

 

 

0 Likes
Message 8 of 9

buchistyle
Participant
Participant

@Kent1Cooper I just tried the DimPoly.lsp and it's okay but requires some more formatting. Like the text needs to be aligned with the lines. The decimal places need to be reduced to just 2. The font size increased. And then there is the azimuth readings. Some work is needed to make it just right for doing land survey plats. Thanks Kent. And in case you don't remember you were very instrumental in getting the lisp I currently use (the one I need a slight modification on now:-) to work as required. I am grateful. 

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

@buchistyle wrote:

... I just tried the DimPoly.lsp and it's okay but requires some more formatting. Like the text needs to be aligned with the lines. The decimal places need to be reduced to just 2. The font size increased. .... 


[All of those aspects are simply part of the Dimension Style definition, and also the DIMZIN System Variable setting, if you want your 2 decimal places to include trailing zeroes.]

Kent Cooper, AIA
0 Likes