godofcad Posted April 6, 2012 Share Posted April 6, 2012 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)) ) Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 6, 2012 Share Posted April 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
pBe Posted April 6, 2012 Share Posted April 6, 2012 Where would "Vertex point of LWpolyline" factor into this godofcad? Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted April 6, 2012 Share Posted April 6, 2012 Here are my useful links for this task : post on theswamp M.R. Quote Link to comment Share on other sites More sharing options...
godofcad Posted April 6, 2012 Author Share Posted April 6, 2012 @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 Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 6, 2012 Share Posted April 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 6, 2012 Share Posted April 6, 2012 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] ) Quote Link to comment Share on other sites More sharing options...
pBe Posted April 6, 2012 Share Posted April 6, 2012 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).... Quote Link to comment Share on other sites More sharing options...
godofcad Posted April 6, 2012 Author Share Posted April 6, 2012 LWPolyline_Distance.dwg I want to do like this please find the attachment Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 6, 2012 Share Posted April 6, 2012 In this case you should try to adjust the examples provided by pBe or me to suit your case. Quote Link to comment Share on other sites More sharing options...
godofcad Posted April 6, 2012 Author Share Posted April 6, 2012 Yes i vl try to do my best Tank u MSasu & pBe Quote Link to comment Share on other sites More sharing options...
pBe Posted April 6, 2012 Share Posted April 6, 2012 Yes i vl try to do my best Tank u MSasu & pBe Thats the spirit godofcad Go fo it. Cheers Quote Link to comment Share on other sites More sharing options...
godofcad Posted April 6, 2012 Author Share Posted April 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
pBe Posted April 6, 2012 Share Posted April 6, 2012 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 ..... Quote Link to comment Share on other sites More sharing options...
godofcad Posted April 6, 2012 Author Share Posted April 6, 2012 Yes this Codes Working perfectly Than a lot buddy Keep in touch :) Quote Link to comment Share on other sites More sharing options...
pBe Posted April 6, 2012 Share Posted April 6, 2012 Yes this Codes Working perfectly Than a lot buddy Keep in touch :) Glad to help, now wrap that code you posted with CODE TAGS Code_Posting_Guidelines Cheers Quote Link to comment Share on other sites More sharing options...
SLW210 Posted April 6, 2012 Share Posted April 6, 2012 Please read the CODE POSTING GUIDELINES and edit your posts! Quote Link to comment Share on other sites More sharing options...
godofcad Posted April 6, 2012 Author Share Posted April 6, 2012 (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) ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.