Jump to content

copy elevation of the nearest polyline


ktbjx

Recommended Posts

is there a lisp routine to make it easier? because i am doing it by hand and its too time consuming..

 

is there a way to copy the elevation of the nearest polyline and make it the elevation of the other objects without its elevation or Z???

Drawing2.dwg

Edited by ktbjx
added DWG sample
Link to comment
Share on other sites

i made one! well atleast i can work faster... :)

if someone can do it better, im really very OPEN to suggestion :D

 

(vl-load-com)
(defun c:qq    (/ elevations sss)
 (if (ssget '((0 . "*POLYLINE")))

   (progn
     (vlax-for    x (vla-get-activeselectionset
           (vla-get-activedocument (vlax-get-acad-object))
         )

   (setq elevations (cons (vla-get-elevation x) elevations))
     )

(prompt "\n2nd Selection")
(setq sss (ssget "_:L"))

(command"_.CHANGE" sss "" "_P" "_E" (rtos (last elevations))
       
   
     )
    )
 )
 (princ)
)

Link to comment
Share on other sites

Consider the following:

(defun c:fixelevation ( / dis dst elv ent enx idx lst src tmp vts )
   (if (and (setq src (LM:ssget "\nSelect polylines with elevation: " '(((0 . "LWPOLYLINE")))))
            (setq dst (LM:ssget "\nSelect polylines to modify: "      '("_:L" ((0 . "LWPOLYLINE")))))
       )
       (progn
           (repeat (setq idx (sslength src))
               (setq ent (ssname src (setq idx (1- idx)))
                     lst (cons (cons ent (assoc 38 (entget ent))) lst)
               )
           )
           (repeat (setq idx (sslength dst))
               (setq enx (entget (ssname dst (setq idx (1- idx))))
                     vts (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
                     dis (getmindistance (caar lst) vts)
                     elv (cdar lst)
               )
               (foreach itm (cdr lst)
                   (if (< (setq tmp (getmindistance (car itm) vts)) dis)
                       (setq elv (cdr itm)
                             dis tmp
                       )
                   )
               )
               (entmod (subst elv (assoc 38 enx) enx))
           )
       )
   )
   (princ)
)
(defun getmindistance ( ent lst / dis tmp )
   (setq dis 1e308)
   (foreach vtx lst
       (if (< (setq tmp (distance vtx (vlax-curve-getclosestpointto ent vtx))) dis)
           (setq dis tmp)
       )
   )
   dis
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
   (princ msg)
   (setvar 'nomutt 1)
   (setq sel (vl-catch-all-apply 'ssget arg))
   (setvar 'nomutt 0)
   (if (not (vl-catch-all-error-p sel)) sel)
)

(vl-load-com) (princ)

Edited by Lee Mac
Added (vl-load-com)
Link to comment
Share on other sites

Consider the following:
(defun c:fixelevation ( / dis dst elv ent enx idx lst src tmp vts )
   (if (and (setq src (LM:ssget "\nSelect polylines with elevation: " '(((0 . "LWPOLYLINE")))))
            (setq dst (LM:ssget "\nSelect polylines to modify: "      '("_:L" ((0 . "LWPOLYLINE")))))
       )
       (progn
           (repeat (setq idx (sslength src))
               (setq ent (ssname src (setq idx (1- idx)))
                     lst (cons (cons ent (assoc 38 (entget ent))) lst)
               )
           )
           (repeat (setq idx (sslength dst))
               (setq enx (entget (ssname dst (setq idx (1- idx))))
                     vts (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
                     dis (getmindistance (caar lst) vts)
                     elv (cdar lst)
               )
               (foreach itm (cdr lst)
                   (if (< (setq tmp (getmindistance (car itm) vts)) dis)
                       (setq elv (cdr itm)
                             dis tmp
                       )
                   )
               )
               (entmod (subst elv (assoc 38 enx) enx))
           )
       )
   )
   (princ)
)
(defun getmindistance ( ent lst / dis tmp )
   (setq dis 1e308)
   (foreach vtx lst
       (if (< (setq tmp (distance vtx (vlax-curve-getclosestpointto ent vtx))) dis)
           (setq dis tmp)
       )
   )
   dis
)

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
   (princ msg)
   (setvar 'nomutt 1)
   (setq sel (vl-catch-all-apply 'ssget arg))
   (setvar 'nomutt 0)
   (if (not (vl-catch-all-error-p sel)) sel)
)

(princ)

 

 

 

Command: fixelevation

 

Select polylines with elevation:

Select polylines to modify: ; error: no function definition:

VLAX-CURVE-GETCLOSESTPOINTTO

 

 

there is an error sir, and also its not jut polyline i wanted to change but also text(Position Z), leader(Vertex Z), line (Star/End Z)...

Link to comment
Share on other sites

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...