Jump to content

How to put Distance Text To Each Vertex to another Vertex point of LWpolyline


godofcad

Recommended Posts

How to put Distance Text To Each Vertex to another Vertex point of LWpolyline

 

Here i m posting codes ..but its not working properly ....

 

Please help me to fix this guys

 

 

(defun c:lwdst()

(setq ssnme(CAR(ENTSEL)))

(setq ent(entget ssnme))

(foreach VERT Ent

(if(= (car VERT) 10)

(progn

(SETQ POS(CDR VERT))

(setq PNT 0)

(SETQ FPOINT(NTH PNT POS))

(SETQ EPOINT(NTH (1+ PNT) POS))

(setq PNT (1+ PNT))

 

)

)

)

 

(SETQ DIS1(DISTANCE FPOINT EPOINT))

(SETQ DIS2(/ DIS1 2))

(SETQ ANG(ANGLE FPOINT EPOINT))

(SETQ MIDPTS(POLAR FPOINT ANG DIS2))

(COMMAND "TEXT" "J" "MC" MIDPTS "2" ANG (RTOS DIS1))

 

)

Link to comment
Share on other sites

Please take care that the variables FPOINT and EPOINT are X, respectively Y coordinates, not points so cannot be used as arguments for DISTANCE, ANGLE or POLAR functions. The DXF code 10 is storing the coordinates of the vertex.

(SETQ POS(CDR VERT))              [color=blue];'(1.1 2.2)
[/color](setq PNT 0)
(SETQ FPOINT(NTH PNT POS))        [color=blue];1.1
[/color](SETQ EPOINT(NTH (1+ PNT) POS))   [color=blue];2.2[/color]

Also, please edit you posts to add code brackets.

Link to comment
Share on other sites

@MSasu I have modified it but also not working

 

 

Code::

(defun c:lwdst ()

(setq ssnme (car (entsel)))

;;LWpOLYLINE

(setq ent (entget ssnme))

(setq pos '())

(foreach VERT Ent

(if (= (car VERT) 10)

(progn

(setq pos (append pos (list (cdr VERT))))

(setq pntcntr 0)

(setq strt (NTH pntcntr pos))

(setq End (NTH (1+ Pntcntr) pos))

(setq pntcntr (1+ pntcntr))

(SETQ DIS1 (DISTANCE FPOINT EPOINT))

(SETQ DIS2 (/ DIS1 2))

(SETQ ANG (ANGLE FPOINT EPOINT))

(SETQ MIDPTS (POLAR FPOINT ANG DIS2))

(COMMAND "TEXT" "J" "MC" MIDPTS "2" ANG (RTOS DIS1))

)

)

)

)

 

 

;;;result:Error: bad argument type: 2D/3D point: nil

Link to comment
Share on other sites

What do you want to achive? Calculate the length of each segment of the polyline as distance between current vertex and next one and print it on segment?

I suggest you to load the code above (again, please add those code brackets) in VisualLISP editor and run it - after use the "Inspect" button to check the content of the variables to be able to debug it.

Link to comment
Share on other sites

Please check if this is what you are looking for:

(defun c:lwdst  ()
(setq ssnme (car (entsel)))
;;LWpOLYLINE 
(setq ent (entget ssnme))
(if (equal (cdr (assoc 0 ent))
           "LWPOLYLINE")
 (progn
  (setq listVertexes '())
  ;build a list of vertexes
  (foreach entry Ent
   (if (= (car entry) 10)
    (setq listVertexes
          (cons (cdr entry)
                listVertexes))
   )
  )
  ;parse vertexes and calculate partial distances
  (setq index 0)
  (repeat (1- (length listVertexes))
   (setq pointCurrent (nth index listVertexes)
         pointNext    (nth (1+ index) listVertexes))
   (print (setq distVtoV  (distance pointCurrent pointNext)))
   (print (setq angleVtoV (angle pointCurrent pointNext)))

   (setq index (1+ index))   ;go to next point
  )
 )
)
[color=magenta] ;...[/color]
)

Link to comment
Share on other sites

Are you trying to put a text between two vertices?

 

(defun c:lwdst  (/ ssnme ent)
     (if (and (setq ssnme (car (entsel)))
              (eq (cdr (assoc 0 (setq ent (entget ssnme))))
                  "LWPOLYLINE"))
           (mapcar '(lambda (j k)
                          (COMMAND "TEXT" "J" "BC"
                                "_non"  (polar j
                                       (angle j k)
                                       (/ (distance j k) 2))
                                (/ (* (angle j k) 180.0) pi)
                                (rtos (distance j k))))
                   (setq pos  (mapcar 'cdr
                                      (vl-remove-if-not
                                            '(lambda (k)
                                                   (= (car k) 10))
                                            ent)))
                   (cdr pos))
           )
     (princ)
     )

 

You may need to add Text height here if you're not using annotative

.....
(/ (distance j k) 2)) [color=blue][b]"2.0"[/b]
[/color](/ (* (angle j k) 180.0) pi).... 

Link to comment
Share on other sites

And Finally i have done to create codes:;

 

 

(defun c:mvd();;;Measure Vertex Distance

(setq osm(getvar "OSMODE"))

(setq clay(getvar "CLAYER"))

(setvar "OSMODE" 0)

(setvar "CMDECHO" 0)

(command "UNDO" "G")

(If (Setq Ss (Ssget '(( 0 . "LWPOLYLINE"))))

(Progn

(command "LAYER" "M" "Distance_Text" "C" "117" "" "")

(setq PLCNTR 0)

(repeat (Setq ln(sslength ss))

(setq ssnme(ssname ss PLCNTR))

(setq Ent (entget ssnme))

(setq Vertlist '())

(Foreach VERT Ent

(if(= (car VERT) 10)

(setq Vertlist (Cons (Cdr VERT) vertlist))

);if

);foreach

(setq PNTCNTR 0)

(Repeat (1- (length Vertlist))

(setq PT1(NTH PNTCNTR Vertlist))

(setq PT2(NTH (1+ PNTCNTR) Vertlist))

(setq MID_PT(POLAR PT1 (ANGLE PT1 Pt2)(/ (DISTANCE Pt1 Pt2) 2)))

(command "TEXT" "J" "BC" MID_PT (/ (getvar "DIMSCALE") 2) (ANGTOS (ANGLE PT1 PT2)) (RTOS (DISTANCE PT1 PT2)))

(Setq PNTCNTR(1+ PNTCNTR))

)

(setq plcntr(1+ plcntr))

)

)

(Princ "\nError-Nothing Selected")

)

(setvar "OSMODE" osm)

(setvar "CLAYER" clay)

(command "UNDO" "E")

(princ)

)

 

 

 

Thank u Guys ...Thanx a lot

Link to comment
Share on other sites

Good for you dude, good job, though the resulting text string doesnt jibe with sample you posted

 

A little mod from the previous code to account for circles and running length like in the sample drawing file:

(defun c:lwdst  (/ ssnme ent [color=blue]d [/color]pos)
     (if (and (setq[color=blue] d     0[/color]
                    ssnme (car (entsel)))
              (eq (cdr (assoc 0 (setq ent (entget ssnme))))
                  "LWPOLYLINE"))
           (progn
                 (mapcar
                       '(lambda (j k)
                              [color=blue](setq d (+ (distance j k) d))[/color]
                              (COMMAND "TEXT"  "J"  "BC"
                                    "_non" (polar j
                                           (angle j k)
                                           (* (distance j k) 0.5))
                                    [color=blue](/ (getvar "DIMSCALE") 2)[/color]
                                    (/ (* (angle j k) 180.0) pi)
                                    (rtos [color=blue]d[/color])))
                       (setq pos  (mapcar 'cdr
                                          (vl-remove-if-not
                                                '(lambda (k)
                                                       (= (car k)
                                                          10))
                                                ent)))
                       (cdr pos))
                 [color=blue](foreach pt pos (command "_circle" "_non" pt "2"))[/color]
                 )
           )
     (princ)
     )

 

Cheers.

 

BTW: use code tags

.....

Link to comment
Share on other sites

(defun c:mvd();;;Measure Vertex Distance
(setq osm(getvar "OSMODE"))
(setq clay(getvar "CLAYER"))
(setvar "OSMODE" 0)
(setvar "CMDECHO" 0)
(command "UNDO" "G")
(If (Setq Ss (Ssget '(( 0 . "LWPOLYLINE"))))
(Progn
(command "LAYER" "M" "Distance_Text" "C" "117" "" "")
(setq PLCNTR 0)
(repeat (Setq ln(sslength ss))
(setq ssnme(ssname ss PLCNTR))
(setq Ent (entget ssnme))
(setq Vertlist '())
(Foreach VERT Ent
(if(= (car VERT) 10)
(setq Vertlist (Cons (Cdr VERT) vertlist))
);if
);foreach
(setq PNTCNTR 0)
(Repeat (1- (length Vertlist))
(setq PT1(NTH PNTCNTR Vertlist))
(setq PT2(NTH (1+ PNTCNTR) Vertlist))
(setq MID_PT(POLAR PT1 (ANGLE PT1 Pt2)(/ (DISTANCE Pt1 Pt2) 2)))
(command "TEXT" "J" "BC" MID_PT (/ (getvar "DIMSCALE") 2) (ANGTOS (ANGLE PT1 PT2)) (RTOS (DISTANCE PT1 PT2)))
(Setq PNTCNTR(1+ PNTCNTR))
)
(setq plcntr(1+ plcntr))
)
)
(Princ "\nError-Nothing Selected")
)
(setvar "OSMODE" osm)
(setvar "CLAYER" clay)
(command "UNDO" "E")
(princ)
)

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