prodromosm 发表于 2022-7-6 02:33:52

Nice try but i think that the calculation is wrong. Can you do something for the second part.

pBe 发表于 2022-7-6 02:37:20

 
I see, show me the correct value if i select the middle of the line? 150.20?
 
I see why.i'm guessing ts aTEXT alignment point/Insertion point issue. changing 10 to 11 is the quick fix.
 
Code at post #10 updated

prodromosm 发表于 2022-7-6 02:39:56

With the yellow collor is your results. Some calculations are the same with mine but same other are difference.I add some red points to speak about specific position
contous2.dwg

pBe 发表于 2022-7-6 02:44:38

 
Update code at post # 10

prodromosm 发表于 2022-7-6 02:45:20

nice job pBe thanx.The first part of my question is complete.....
Can you do something for the second part.
- select level lines (polilynes with angle of inclination) and calculate the beween elevetions

pBe 发表于 2022-7-6 02:49:15

 
Glad it works for you.
Wanted to get the feedback on item number 1 first, I'll post a code for number 2 later.

Least 发表于 2022-7-6 02:52:55

that's really good, but can it be made for block attributes 'instead of / as well as' text?
 
thanks
 

pBe 发表于 2022-7-6 02:54:18

 
Yes it can be done, but what will be the reference for the distance? is it the block insertion point?
 
@prodromosm
 
Item number 2: based on your example. "elevation" between contor 1and contour 2you have 110.8, automating the process can be quite tricky . if i to write a code i will determine half the distance between contour lines which makes a dead even 110.00. and so on. Now if you add an option to indicate a "distance from" or divide the space by # then we can proceed to do that. IF you are wanting to pick a point between each contour at every interval, that will give the distance per level, is that how you wanted it to work for you?

Least 发表于 2022-7-6 03:00:19

yes block insertion point
 
P

GP_ 发表于 2022-7-6 03:00:53

Good code, pBe.
 
 
This is my attempt for item number 2.
Does not always work.
 
Here it works.
 

 
 
Here it does not work.
 

 
 

(defun c:test ( / p1 p2 d sel LEV LEV_F LEV_L TT)   (if       (and         (setq p1 (getpoint "\nSelect Level Lines, first fence point:"))         (setq p2 (getpoint p1 "\nSpecify endpoint of line:"))                (setq d (distance p1 p2))         (if (setq sel (ssget "_F" (list p1 p2) '((0 . "LWPOLYLINE"))))               (progn                   (repeat (setq n (sslength sel))                     (setq LEV (cons (ssname sel (setq n (1- n))) LEV))                   )                   (setq LEV (reverse LEV))               )         )         (setq LEV_F (car LEV))         (setq LEV_L (last LEV))         (if               (>                   (cdr (assoc 38 (entget LEV_L)))                   (cdr (assoc 38 (entget LEV_F)))               )               (setq segno -)               (setq segno +)                           )       )       (progn         (setq TT               (vlax-ename->vla-object                   (entmakex                     (list                           (cons 0 "TEXT")                           (cons 7 (getvar "textstyle"))                           (cons 10 p2)                           (cons 11 p2)                                                            (cons 40 2.5)                           (cons 1 "")                           (cons 73 2)                           (cons 72 1)                           (cons 50 0)                     )                   )               )         )         (princ "\nText position: ")         (while (= (car (setq pt (grread T 12 0))) 5)               (vla-put-TextAlignmentPoint TT (vlax-3d-point (cadr pt)))               (vla-put-TextString TT (location))         )         (if (= (vla-get-TextString TT) "OUT") (vla-delete TT))       )   )   (prompt "\n ")(prompt "\n ")   (princ));***************************************************************************(defun location ( / pa ang pb pc e1 e2 elev_a elev_b diff p_1 p_2 elev+ elev)   (setq pa (cadr pt))   (setq ang            (angle                (vlax-curve-getClosestPointTo LEV_F pa)                (vlax-curve-getClosestPointTo LEV_L pa)            )   )   (setq pb (polar pa ang d))   (setq pc (polar pa (- ang pi) d))   (if       (and         (setq e1 (ssget "_F" (list pa pb) '((0 . "LWPOLYLINE"))))         (setq e1 (ssname e1 0))         (setq e2 (ssget "_F" (list pa pc) '((0 . "LWPOLYLINE"))))         (setq e2 (ssname e20))       )       (progn         (setq elev_a (cdr (assoc 38 (entget e1))))         (setq elev_b (cdr (assoc 38 (entget e2))))         (setq diff (abs (- elev_a elev_b)))            (setq p_1 (LEV_inters pa pb (pl_coord e1)))         (setq p_2 (LEV_inters pa pc (pl_coord e2)))                     (if (and p_1 p_2)               (setq elev+ (/ (* (distance p_1 pa) diff) (distance p_1 p_2))                     elev (rtos (segno elev_a elev+))               )         )       )       "OUT"   ));***************************************************************************(defun LEV_inters (:p1 :p2 vPL / p_int *p*)   (mapcar       '(lambda (a b)            (setq *p*                     (inters                         (list (car a) (cadr a))                         (list (car b) (cadr b))                         :p1                         :p2                     )            )            (if *p* (setq p_int *p*))      )       vPL(cdr vPL)   )   p_int);***************************************************************************(defun pl_coord (# / p m)   (setq p (if (vlax-curve-IsClosed #)               (fix (vlax-curve-getEndParam #))               (1+ (fix (vlax-curve-getEndParam #)))         )   )   (while (/= 0 p)       (setq m (cons (vlax-curve-getPointAtParam # (setq p (1- p))) m))   ))
页: 1 [2]
查看完整版本: Level lines -calculate height