Author Topic: Numbering vertex polyline  (Read 3009 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Numbering vertex polyline
« on: July 11, 2007, 03:45:55 AM »
Hi Alls,
I got problem, and my brain got locked to solve this problem, how to add list funtion or quote at a variable.
(xxx yyy) to '(xxx yyy)
This code is function to put number every vertex of polyline
Code: [Select]
; nvop is stand for Numbering Vertex Object Polyline
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 11 July 2007
;        Program no.: 0615/07/2007
;        Edit by    :
;        ***********UNDER CONSTRUCTION*************

(defun massoc (key alist / x nlist)          ; Jaysen Long
  (foreach x alist
    (if
      (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
      )
    )
  (reverse nlist)
  )

(defun c:nvop (/ cnt etyp len loc lst pre ss sse str th ts)
  (if
    (setq ss (car (entsel "\nPick an object polyline")))
    (progn
      (setq sse (entget ss))
      (setq etyp (cdr (assoc 0 sse)))
      (if
(= etyp "LWPOLYLINE")
(progn
  (setq lst (massoc 10 sse))
  (setq len (length lst))
  (setq pre (getint "\nEnter number as prefix<0>: "))
  (if (= pre nil)(setq pre 0))
  (setq cnt 0)
  (setq ts (getvar "textsize"))
  (if
    (or (> ts 1)(< ts 1))
    (setq th 1)
    )  ; if
  (repeat
    len
    (setq loc (nth cnt lst))
    (setq str (strcat (itoa pre)(itoa (1+ cnt))))
    (command "_text" loc th "" str)
    ; still get trouble in loc variable, from (xx yyy) it shouls '(xx yy)
    )  ; repeat
  )    ; progn
(alert "\nInvalid object line, it's not LWPOLYLINE")
)      ; if
      )        ; progn
    (alert "\nInvalid selected object, please try again")
    )          ; if
  (princ)
  )            ; defun

VVA

  • Newt
  • Posts: 166
Re: Numbering vertex polyline
« Reply #1 on: July 11, 2007, 04:26:11 AM »
try it
Code: [Select]
; nvop is stand for Numbering Vertex Object Polyline
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 11 July 2007
;        Program no.: 0615/07/2007
;        Edit by    : 11.07.07 by VVA
;        ***********UNDER CONSTRUCTION*************

(defun massoc (key alist / x nlist)          ; Jaysen Long
  (foreach x alist
    (if
      (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
      )
    )
  (reverse nlist)
  )

(defun c:nvop (/ ss pre cnt str txt)
  (if (and
        (setq ss (car (entsel "\nPick an object polyline")))
        (= (cdr(assoc 0 (entget ss))) "LWPOLYLINE")
        )
    (progn
     (if (null (setq pre (getint "\nEnter number as prefix<0>: ")))
       (setq pre 0)
       )
     (setq cnt 0)
     (mapcar '(lambda(pt)
                (setq pt (mapcar '+ pt '(1 1 0))) ;_ 1 unit left and upper vertex
                (setq str (strcat (itoa pre)(itoa (setq cnt (1+ cnt)))))
                (setq txt
                       (entmake(list  '(0 . "TEXT")
                                      '(100 . "AcDbEntity")
                                      '(100 . "AcDbText")
                                      (cons 10 pt)
                                      (cons 1 str) ;_Number
                                      (cons 40 3)       ;_Text height = 3
                                      (cons 8 "TextLayer") ;_TextLayer
                                      '(72 . 0)             ;_Left
                                      (cons 50 0)           ;_Angle in radians
                                      (cons 11 pt)
                                      )
                               )
                      )
                )
             (massoc 10 (entget ss))
             )
     )
    )
  (princ)
  )
« Last Edit: July 11, 2007, 04:29:30 AM by VVA »

Adesu

  • Guest
Re: Numbering vertex polyline
« Reply #2 on: July 11, 2007, 04:39:45 AM »
Hi VVA,
yes with entmake function it get solve the problem, but I hope any one help to create with use command function, I want solve that problem without entmake.
thanks VVA for your help, I appreaciated it.

VVA

  • Newt
  • Posts: 166
Re: Numbering vertex polyline
« Reply #3 on: July 11, 2007, 07:39:08 AM »
With command
Code: [Select]
; nvop is stand for Numbering Vertex Object Polyline
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 11 July 2007
;        Program no.: 0615/07/2007
;        Edit by    : 11.07.07 by VVA
;        ***********UNDER CONSTRUCTION*************

(defun massoc (key alist / x nlist)          ; Jaysen Long
  (foreach x alist
    (if
      (eq key (car x))
      (setq nlist (cons (cdr x) nlist))
      )
    )
  (reverse nlist)
  )
(defun mip-text-draw (txt pnt height rotation justification)
   (if (null pnt)(vl-cmdf "_.-TEXT" "" txt)
   (if (= (cdr (assoc 40 (tblsearch "STYLE" (getvar "TEXTSTYLE"))))
    0.0
       ) ;_ end of =
     (progn
     ;; нулевая высота текста
     ;; height = 0
       (if justification
   (vl-cmdf "_.-TEXT" "_J" justification "_none" pnt height rotation txt)
   (vl-cmdf "_.-TEXT" "_none" pnt height rotation txt)
       ) ;_ end of if
     ) ;_ end of progn
     (progn
       ;; фиксированнная высота
       ;; fixed height
       (if justification
   (vl-cmdf "_.-TEXT" "_J" justification "_none" pnt rotation txt)
   (vl-cmdf "_.-TEXT" "_none" pnt rotation txt)
       ) ;_ end of if
     ) ;_ end of progn
   ) ;_ end of if
     )
  (entlast)
)

(defun c:nvop (/ ss pre cnt str txt)
  (if (and
        (setq ss (car (entsel "\nPick an object polyline")))
        (= (cdr(assoc 0 (entget ss))) "LWPOLYLINE")
        )
    (progn
     (if (null (setq pre (getint "\nEnter number as prefix<0>: ")))
       (setq pre 0)
       )
     (setq cnt 0)
     (mapcar '(lambda(pt)
                (setq pt (mapcar '+ pt '(1 1 0))) ;_ 1 unit left and upper vertex
                (setq str (strcat (itoa pre)(itoa (setq cnt (1+ cnt)))))
                (setq pt (trans pt 0 1))
                (mip-text-draw
                  str ;_String
                  pt  ;_Point in UCS
                  3   ;_Height
                  0   ;_Angle in degree
                  nil ;_justification nil-left or "_R" "_TL" and ect
                  )
                )
             (massoc 10 (entget ss))
             )
     )
    )
  (princ)
  )

SomeCallMeDave

  • Guest
Re: Numbering vertex polyline
« Reply #4 on: July 11, 2007, 07:58:57 AM »
Adesu,

I did some quick testing and I'm not sure that the value of LOC is causing the problem.

You might want to check what happens if the sysvar "TEXTSIZE" is 1.    Also, you may need to look at your repeat loop.  I think something may be missing there.

Hope this help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Numbering vertex polyline
« Reply #5 on: July 11, 2007, 09:50:06 AM »
Adesu
You do not increment the cnt variable within the repeat loop and a problem when there is a text height.
Code: [Select]
; nvop is stand for Numbering Vertex Object Polyline
;        Design by  : Adesu <Ade Suharna>
;        Email      : mteybid@yuasabattery.co.id
;        Homepage   : http://www.yuasa-battery.co.id
;        Create     : 11 July 2007
;        Program no.: 0615/07/2007
;        Edit by    :
;        ***********UNDER CONSTRUCTION*************

(defun massoc (key alist / x nlist) ; Jaysen Long
  (foreach x alist
    (if
      (eq key (car x))
       (setq nlist (cons (cdr x) nlist))
    )
  )
  (reverse nlist)
)

(defun c:nvop (/ cnt etyp len loc lst pre ss sse str th ts)
  (if
    (setq ss (car (entsel "\nPick an object polyline")))
     (progn
       (setq sse (entget ss))
       (setq etyp (cdr (assoc 0 sse)))
       (if
         (= etyp "LWPOLYLINE")
          (progn
            (setq lst (massoc 10 sse))
            (setq len (length lst))
            (setq pre (getint "\nEnter number as prefix<0>: "))
            (if (= pre nil)
              (setq pre 0)
            )
            (setq cnt 0)
            (setq ts (getvar "textsize"))
            (setq th 1)
            (setvar "textsize" th)
            (repeat
              len
               (setq loc (nth cnt lst))
               (setq str (strcat (itoa pre) (itoa (1+ cnt))))
               ;; If text height is undefined (signified by 0 in the table)
               (if (zerop (cdr(assoc 40(tblsearch "style" (getvar "textstyle")))))
                 ;; Draw the text using the current text height (textsize)
                 (command ".text" loc th 0 str)
                 ;; Otherwise use the defined text height
                 (command ".text" "_non" loc 0 str)
               ) ; endif
               ;(command "_text" "_non" loc th "" str)
               (setq cnt (1+ cnt))
            )       ; repeat
            (setvar "textsize" ts) ; restore
          )         ; progn
          (alert "\nInvalid object line, it's not LWPOLYLINE")
       )            ; if
     )              ; progn
     (alert "\nInvalid selected object, please try again")
  )                 ; if
  (princ)
)                   ; defun
« Last Edit: July 11, 2007, 09:51:15 AM by CAB »
I've reached the age where the happy hour is a nap. (°ї°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Numbering vertex polyline
« Reply #6 on: July 11, 2007, 03:21:42 PM »
Another approach:

Code: [Select]
;;  Number pline vertex
;;  CAB 07.11.07
;;  User start number & prefix
;;  Uses current text style & layer "Text_Layer"
(defun c:pvnumber (/ ACTDOC ACTSP CCURVE CURANG CURDER ENDPARAM ENT NEXTPT OFFPT PARAM
                   PREFIX SPFLAG TMP TXTLAY TXTOBJ VERTEX# txtSize layer_name)

  (vl-load-com)
 
  (setq layer_name "Text_Layer") ; layer name for text
  (setq txtSize (getvar "TEXTSIZE"))
  ;; (setq txtSize 5.0) ; default size


  (defun _Addlayer (layName acDoc / layObj layCol)
    (setq layCol (vla-get-layers acDoc))
    (if (vl-catch-all-error-p
          (setq layObj (vl-catch-all-apply 'vla-item (list layCol layName))))
      (setq layObj (vla-add layCol layName))
    )
    layObj
  )

  (setq actDoc (vla-get-activedocument (vlax-get-acad-object))
        spFlag (vla-get-activespace actDoc)
  )
  (if (= 0 spFlag)
    (setq actSp (vla-get-paperspace actDoc))
    (setq actSp (vla-get-modelspace actDoc))
  )

  (or Start# (setq Start# 1))
  (initget (+ 2 4))
  (setq tmp (getint (strcat "\nSpecify starting number <" (itoa Start#) ">: ")))
  (if tmp (setq Vertex# tmp)(setq Vertex# Start#))
 
  (setq Prefix "0")
  (setq tmp (getstring t (strcat "\nSpecify number prefix <" prefix "> / for none: ")))
  (if (/= tmp "") (setq prefix tmp))
  (if (eq prefix "/")
    (setq prefix "")
  )
  (if
    (and
      (princ "\n*** Select pline to number *** ")
      (setq ent (ssget "_+.:E:S" '((0 . "LWPOLYLINE,POLYLINE"))))
      (setq ent (ssname ent 0))
      (not (vl-catch-all-error-p
                  (setq tmp (vl-catch-all-apply
                                'vlax-curve-getpointatparam
                                (list ent 0.0))))
      )
      (setq cCurve (vlax-ename->vla-object ent))

      (setq endparam (vlax-curve-getendparam cCurve))
      (setq txtLay (_Addlayer layer_name actDoc))

    ) ; end and
     (progn
       (vla-startundomark actDoc)
       (setq param 0)
       (repeat (1+ (fix endparam))
         (setq nextPt (vlax-curve-getpointatparam cCurve param))
         (setq curDer (vlax-curve-getfirstderiv cCurve
                        (vlax-curve-getparamatpoint cCurve nextPt)))
         ;; Get angle 90 deg to curve
         (if (= (cadr curDer) 0.0)
           (setq curAng (/ pi 2))
           (setq curAng (- pi (atan (/ (car curDer) (cadr curDer)))))
         )
         (setq OffPt  (polar nextPt curAng (* 1.5 txtSize))
               txtObj (vla-addtext
                        actSp
                        (strcat prefix (itoa Vertex#))
                        (vlax-3d-point OffPt)
                        txtSize
                      )
         )
         (vla-put-alignment txtObj acalignmentmiddlecenter)
         (vla-put-textalignmentpoint txtobj (vlax-3d-point OffPt))
         (vla-put-layer txtObj (vla-get-name txtLay))

         (setq Param (1+ param)
               Vertex# (1+ Vertex#))
         (if (> param endparam)
           (setq Param endparam)
         )
       ) ; end while
       (vla-endundomark actDoc)
     ) ; end progn
     (princ
       "\nERROR. Empty selection, invalid object type. "
     )
  )  ; end if
  (princ)
)
(prompt "\Vertex Number Loaded, Enter pvnumber to run.")
(princ)
I've reached the age where the happy hour is a nap. (°ї°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Numbering vertex polyline
« Reply #7 on: July 11, 2007, 03:44:48 PM »
Here's my contribution:
Code: [Select]
(defun c:test (/ doc num)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))
num (getint "\n Enter Start Number: ")
  )
  (mapcar '(lambda (x)
     (if (member (car x) '(10))
       (progn
(vla-addText
   (vla-get-modelspace doc)
   (itoa num)
   (vlax-3d-point (list (cadr x) (caddr x)))
   (if (= (getvar 'cvport) 1)
     0.125
     (* (getvar 'dimscale) 0.125)
   )
)
(setq num (1+ num))
       )
     )
   )
  (entget (car (entsel "\n Select polyline: ")))
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Adesu

  • Guest
Re: Numbering vertex polyline
« Reply #8 on: July 11, 2007, 07:34:06 PM »
Hi VVA,
Wow.....it's great, thanks you very much.

Adesu

  • Guest
Re: Numbering vertex polyline
« Reply #9 on: July 11, 2007, 07:37:53 PM »
Hi CAB,
it's great too, I glad with your help become open my brain, thanks a lot.

Adesu

  • Guest
Re: Numbering vertex polyline
« Reply #10 on: July 11, 2007, 07:41:25 PM »
Hi ronjonp,
Your code very simple and fantastic, I like that and thanks you very much for your help, I appreaciated to you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Numbering vertex polyline
« Reply #11 on: July 12, 2007, 12:00:56 AM »
Glad you got what you needed. :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC