veteranus Posted November 6, 2020 Posted November 6, 2020 (edited) hi, First of all thank you all guys and lee mac for your helps. I'm new to the writing lisp codes. I found a lisp written by lee mac. this lisp can write length and width inside the rectangle. I want to add height in addition to this lisp. but it should ask the user and add the value (number) that the user has written to all selected objects. I'm adding a simple sample code, here's what we want to do but can't do: lenght x width x the value I wrote (setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2) "x" (setq ss (getstring T "\ n Height:"))) the original lisp: (defun c:LR (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpText tmpDist1 tmpDist2) ; Label rectangles with length and width in middle of them. (vl-load-com) (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (if (= (getvar "cvport") 1) (setq CurSpace (vla-get-PaperSpace ActDoc)) (setq CurSpace (vla-get-ModelSpace ActDoc)) ) (if (and (setq Ht (getreal "\n Text Height: ")) (setq ss (ssget '((0 . "*POLYLINE"))))) (progn (setq cnt 0) (while (setq Ent (ssname ss cnt)) (setq EntData (entget Ent)) (if (= (cdr (assoc 0 EntData)) "LWPOLYLINE") (setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates)) (progn (setq VerPoints nil) (setq tmpEnt (entnext Ent)) (while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND")) (setq tmpPt (cdr (assoc 10 (entget tmpEnt)))) (setq VerPoints (append VerPoints (list (car tmpPt)))) (setq VerPoints (append VerPoints (list (cadr tmpPt)))) (setq tmpEnt (entnext tmpEnt)) ) ) ) (if (= (length VerPoints) 8) (progn (setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints)))) (setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints)))) (if (< tmpDist1 tmpDist2) (setq Len tmpDist2 Wid tmpDist1) (setq Len tmpDist1 Wid tmpDist2) ) (setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0)) (setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2))) (setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht)) (vla-put-Alignment tmpText 4) (vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt)) ) ) (setq cnt (1+ cnt)) ) ) ) (princ) ) Edited November 6, 2020 by veteranus Quote
mstb Posted November 6, 2020 Posted November 6, 2020 1 hour ago, veteranus said: hi, First of all thank you all guys and lee mac for your helps. I'm new to the writing lisp codes. I found a lisp written by lee mac. this lisp can write length and width inside the rectangle. I want to add height in addition to this lisp. but it should ask the user and add the value (number) that the user has written to all selected objects. I'm adding a simple sample code, here's what we want to do but can't do: lenght x width x the value I wrote (setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2) "x" (setq ss (getstring T "\ n Height:"))) the original lisp: (defun c:LR (/ ActDoc CurSpace Ht ss cnt Ent EntData VerPoints tmpEnt Wid Len Pt Str tmpText tmpDist1 tmpDist2) ; Label rectangles with length and width in middle of them. (vl-load-com) (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (if (= (getvar "cvport") 1) (setq CurSpace (vla-get-PaperSpace ActDoc)) (setq CurSpace (vla-get-ModelSpace ActDoc)) ) (if (and (setq Ht (getreal "\n Text Height: ")) (setq ss (ssget '((0 . "*POLYLINE"))))) (progn (setq cnt 0) (while (setq Ent (ssname ss cnt)) (setq EntData (entget Ent)) (if (= (cdr (assoc 0 EntData)) "LWPOLYLINE") (setq VerPoints (vlax-get (vlax-ename->vla-object Ent) 'Coordinates)) (progn (setq VerPoints nil) (setq tmpEnt (entnext Ent)) (while (not (equal (cdr (assoc 0 (entget tmpEnt))) "SEQEND")) (setq tmpPt (cdr (assoc 10 (entget tmpEnt)))) (setq VerPoints (append VerPoints (list (car tmpPt)))) (setq VerPoints (append VerPoints (list (cadr tmpPt)))) (setq tmpEnt (entnext tmpEnt)) ) ) ) (if (= (length VerPoints) 8) (progn (setq tmpDist1 (distance (list (nth 0 VerPOints) (nth 1 VerPoints)) (list (nth 2 VerPoints) (nth 3 VerPoints)))) (setq tmpDist2 (distance (list (nth 2 VerPOints) (nth 3 VerPoints)) (list (nth 4 VerPoints) (nth 5 VerPoints)))) (if (< tmpDist1 tmpDist2) (setq Len tmpDist2 Wid tmpDist1) (setq Len tmpDist1 Wid tmpDist2) ) (setq Pt (list (/ (+ (nth 0 VerPoints) (nth 4 VerPoints)) 2.0) (/ (+ (nth 1 VerPoints) (nth 5 VerPoints)) 2.0) 0.0)) (setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2))) (setq tmpText (vla-AddText CurSpace Str (vlax-3d-point Pt) Ht)) (vla-put-Alignment tmpText 4) (vla-put-TextAlignmentPoint tmpText (vlax-3d-point Pt)) ) ) (setq cnt (1+ cnt)) ) ) ) (princ) ) Hello. insert this in line 9th (setq height (getstring "\nHeight of box: ")) replace this in line 37th (setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2) "x" height)) 1 Quote
veteranus Posted November 7, 2020 Author Posted November 7, 2020 16 hours ago, mstb said: Hello. insert this in line 9th (setq height (getstring "\nHeight of box: ")) replace this in line 37th (setq Str (strcat (rtos Len 2 2) "x" (rtos Wid 2 2) "x" height)) Hi, Tx for your help, it working. Quote
veteranus Posted November 7, 2020 Author Posted November 7, 2020 Hi again, Can we change to conversion factor in this lisp? I meant; it gives 2.05 I want 205 Regards. Quote
BIGAL Posted November 7, 2020 Posted November 7, 2020 Why would you not draw the objects true size to start with, I could understand 2.05 and 2050 which would be meters to mm. Any way (* len 100.0) Quote
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.