Jump to content

Recommended Posts

Posted

I like to write a text between first and second vertex of a selected Polyline.

please help me to get first vertex (p1) and second vertex (p2) of a polyline. rest of things i can do myself.

 

Thanks in advance

Posted

Here is another example for the 1st and 2nd just use the (getcoords) and look at the first 4 values.

 

; pline co-ords by BIG AL
(defun plcords (/ ent obj plobs )
(vl-load-com)
(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ( / I)
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth (+ I 1) co-ords)(nth I co-ords) ))
(setq coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
)

(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)

(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
)
(co-ords2xy)

(setq inc (length coordsxy))
(repeat (/ inc  2) 
(setq x (rtos (nth (setq inc (- inc 1)) co-ords) 2 3 ))
(setq y (rtos (nth (setq inc (- inc 1)) co-ords) 2 3 ))  
(setq xy (strcat x "," y ))
 (princ xy)
 (princ "\n ")
 )
)
(plcords)

Posted

Try this .

 

(if (and (setq s (car (entsel "\n Select Polyline :")))
        (eq (cdr (assoc 0 (setq e (entget s)))) "LWPOLYLINE")
   )
 (progn
   (setq d (distance (setq 1p (cdr (car (setq l
                                               (vl-remove-if-not '(lambda (u) (eq (car u) 10)) e)
                                        )
                                   )
                              )
                     )
                     (setq 2p (cdr (cadr l)))
           )
         a (angle 1p 2p)
   )
   (command "text"
            "mc"
            (mapcar '(lambda (q p) (* (+ q p) 0.5)) 1p 2p)
            0.2
            (/ (* a 180) pi)
            (strcat (rtos d 2 2) "/BT/RD")
   )
 )
)

Posted

1. do the both side offset of selected pline (centre line) using offset distance

2. double the offset distance to get road width.

 

Does it mean that you want to get two offsets from the Polyline ? Not clear to me , give more info .

Posted
yes. the code i posted above by Lee is doing the same but we need to use its offset distance and place it on selected pline.

 

It is better to give a sample drawing or an image to write the codes in one go .

NOTE: I will not include Lee's routine in routine , just a double offset is enough .

Posted (edited)

Something along this ?

 

(defun c:Test (/ s en e sn l ly o dz d a 1p 2p)
 ;;	Tharwat 08.12.2014	;;
 (princ "\n Select Polyline :")
 (if (and (setq en (entlast)
                s  (ssget "_+.:S:E:L" '((0 . "LWPOLYLINE")))
          )
          (setq dz (getvar 'DIMZIN))
          (setvar 'DIMZIN 0)
          (setq *offDist*
                 (cond ((getdist (strcat "\n Specify offset distance <"
                                         (rtos (if *offDist*
                                                 *offDist*
                                                 (setq *offDist* 1.0)
                                               )
                                               2
                                               2
                                         )
                                         " > :"
                                 )
                        )
                       )
                       (*offDist*)
                 )
          )
          (progn
            (initget 6 "Current Source")
            (setq ly
                   (cond
                     ((getkword
                        "\n Enter layer option for offset objects [Current/Source] <Source>: "
                      )
                     )
                     ("Source")
                   )
            )
          )
     )
   (progn
     (setq d (distance (setq 1p (cdr (car (setq l
                                                 (vl-remove-if-not
                                                   '(lambda (u) (eq (car u) 10))
                                                   (setq e (entget (setq sn (ssname s 0))))
                                                 )
                                          )
                                     )
                                )
                       )
                       (setq 2p (cdr (cadr l)))
             )
           a (angle 1p 2p)
     )
     (foreach x (list *offDist* (- *offDist*))
       (vla-offset (vlax-ename->vla-object sn) x)
       (if (and (eq ly "Current")
                (not (eq en (setq o (entlast))))
           )
         (vla-put-layer (vlax-ename->vla-object o) (getvar 'CLAYER))
       )
     )
     (command "text"
              "mc"
              (mapcar '(lambda (q p) (* (+ q p) 0.5)) 1p 2p)
              0.2
              (/ (* a 180) pi)
              (strcat (rtos d 2 2) "/BT/RD")
     )
   )
 )

 (if dz
   (setvar 'DIMZIN dz)
 )
 (princ)
)(vl-load-com)

Edited by Tharwat
Posted
Thanks Tharwat! yes its working fine. :) . It will be more useful if we can include the Through and current layer option.

 

I modified the program above to include a layer option for the offset process , so try it and let me know .

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