Jump to content

Recommended Posts

Posted (edited)
Nice code too.. Thanks pBe.

 

Its not that all great really, i just tested the theory based on the pseudo code i posted earlier

 

This one for straight segments only [first pseudo code]

 

(defun c:KP1 ( / _testwhere  _insert pline  inspts anglesP i v att d)
(vl-load-com)
(defun _testwhere (pt lst e /  ang)
   (setq ang (vl-some '(lambda (r)
                   (if (< (vlax-curve-getDistAtPoint  e pt) (car r))
                       (cadr r)))
           lst))
   ang
   )
(defun _insert (pt bn ro)
(vlax-invoke (vlax-get (vla-get-ActiveLayout
(vla-get-activedocument (vlax-get-acad-object)))
          'Block) 'InsertBlock  pt bn 1 1 1 ro))
(if (and (setq pline (car (entsel)))
        (setq b (cond ((getdist
         (strcat "Specify KP interval in metres or [Pick two points] <" (rtos (setq b
               (cond ( b ) ( 100 ))
             ) 2 2) ">: " ))) ( b ))
  ))
(progn
     (setq points (mapcar 'cdr (vl-remove-if-not '(lambda (j)
                              ( = (car j) 10)) (setq ent (entget pline)))))
     (setq anglesP (mapcar '(lambda (k l )
                                  (list (setq d (if (null d) (distance k l)
                                                    ( + (distance k l) d)))

                                        (angle k l))) points (cdr points)))
     (setq i b)
     (while
     (setq v (vlax-curve-getPointAtDist pline i))
 (setq inspts (append  inspts (list v))
                          i (+ i b))
     )
     (mapcar
           (function
                 (lambda (m / att)
                       (setq att (_insert
                                       m
                                       "KP"
                                       (_testwhere
                                             m
                                             anglesP
                                             pline)))
                       (mapcar
                             '(lambda (h)
                                    (if   (eq   (vla-get-tagstring
                                                      h)
                                                "KP")
                                               (vla-put-textstring
                                                     h
                                                     (rtos (/ (vlax-curve-getDistAtPoint pline m)
                                                              1000)
                                                           2
                                                           1))))
                             (vlax-invoke att 'GetAttributes))))
           (cons (vlax-curve-getStartPoint pline) inspts)
           )
     )
     ) (princ)
     )

 

 

 

Hey pBe, your rouine is very nice,

Regards,

 

Oleg

 

Thank you Oleg, it means a lot coming from you :)

Edited by pBe
  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • aaryan

    11

  • pBe

    8

  • fixo

    4

  • Tharwat

    1

Top Posters In This Topic

Posted

Thanks pBe and Oleg. both of your code working fine and very much suits my requirement.

Is it possible.

Suppose if i want to give Kp interval as 250m, then the attribute inserted should be "0.25" Kp and if i give 25m it should be "0.025" Kp. Or simply ask the user for decimal place.

1, When i use Oleg's code the rotation of the KP block differs (when the polyline picked is zig zag from north to south or curvy) from the measure command. Can this be fixed Oleg Please...

2, When i use pBe's code and gives the interval as 250m, sometimes the KP starts from other end even after picking the nearest point from the desired direction and sometimes not. Am i doing something wrong.

 

 

Reference drawing is inserted. Comparison.dwg

 

Regards

Aaryan

Posted
Thanks pBe and Oleg. both of your code working fine and very much suits my requirement.

When i use pBe's code and gives the interval as 250m, sometimes the KP starts from other end even after picking the nearest point from the desired direction and sometimes not. Am i doing something wrong.

 

Reference drawing is inserted. [ATTACH]35237[/ATTACH]

 

Regards

Aaryan

 

You are not doing anything wrong, its the code thats causing the all the chaos , I knew i should've test it more thoroughly :lol:

I will look into it later.

If i were you, i'll stick with Olegs code, mine is somewhat on experimental stage.

Posted

Thanks pBe I will do the same as you suggests.

 

Regards.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...