vector Posted April 5, 2009 Posted April 5, 2009 Hi everyone !!!I would like to know if there is such a command in AutoCAD (2007)?A command that creates inclining numbering with every click on an object it adds new number , the next new number is higher with 1 (+1) than the current , and it supposed to prompt the user to give a value to the first number in a series . Thanke a lot in advance GM Quote
Lee Mac Posted April 5, 2009 Posted April 5, 2009 Was bored, so made ya this one ;; ============ Num.lsp =============== ;; ;; FUNCTION: ;; Will sequentially place numerical ;; text upon mouse click, with optional ;; prefix and suffix. ;; ;; SYNTAX: num ;; ;; AUTHOR: ;; Copyright (c) 2009, Lee McDonnell ;; (Contact Lee Mac, CADTutor.net) ;; ;; PLATFORMS: ;; No Restrictions, ;; only tested in ACAD 2004. ;; ;; VERSION: ;; 1.0 ~ 05.04.2009 ;; ;; ==================================== (defun c:num (/ vlst ovar stmp intmp ptmp sutmp vars pt) (setq vlst '("OSMODE" "CLAYER") ovar (mapcar 'getvar vlst)) (setvar "OSMODE" 0) (or (tblsearch "LAYER" "NumText") (vla-add (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) "NumText")) (or sNum (setq sNum 1)) (or inNum (setq inNum 1)) (or Pref (setq Pref "")) (or Suff (setq Suff "")) (setq stmp (getreal (strcat "\nSpecify Starting Number <" (rtos sNum) ">: ")) intmp(getreal (strcat "\nSpecify Increment <" (rtos inNum) ">: ")) ptmp (getstring (strcat "\nSpecify Prefix <" (if (eq "" Pref) "-None-" Pref) ">: ")) sutmp(getstring (strcat "\nSpecify Suffix <" (if (eq "" Suff) "-None-" Suff) ">: "))) (or (not stmp) (setq sNum stmp)) (or (not intmp) (setq inNum intmp)) (or (eq "" ptmp) (setq Pref ptmp)) (or (eq "" sutmp) (setq Suff sutmp)) (while (setq pt (getpoint "\nClick for Text... ")) (Make_Text pt (strcat Pref (rtos sNum) Suff)) (setq sNum (+ sNum inNum))) (mapcar 'setvar vlst ovar) (princ)) (defun Make_Text (txt_pt txt_val) (entmake (list '(0 . "TEXT") '(8 . "NumText") (cons 10 txt_pt) (cons 40 (max 2.5 (getvar "TEXTSIZE"))) (cons 1 txt_val) '(50 . 0.0) (cons 7 (getvar "TEXTSTYLE")) '(71 . 0) '(72 . 1) '(73 . 2) (cons 11 txt_pt)))) Quote
mdbdesign Posted April 5, 2009 Posted April 5, 2009 Text looks like: pref 1" suffix. " mark is what you plan to achieve? Quote
Lee Mac Posted April 5, 2009 Posted April 5, 2009 Text looks like: pref 1" suffix. " mark is what you plan to achieve? Are you querying my code Mdb? - if so, yes, I thought the user may want a prefix and/or suffix, eg A10CB A11CB etc etc I only wrote it quickly - can easily be modified Quote
mdbdesign Posted April 5, 2009 Posted April 5, 2009 Prefix and suffix is OK. Just " mark looks like: 1 inch, 2 inches.(A10"CB;A11"CB) Quote
Lee Mac Posted April 5, 2009 Posted April 5, 2009 Prefix and suffix is OK. Just " mark looks like: 1 inch, 2 inches.(A10"CB;A11"CB) Hmmm... there shouldn't be any quotation marks - will investigate this one.. :P Quote
Tankman Posted April 5, 2009 Posted April 5, 2009 You might like callout.lsp. A simple program, has been changed numerous times to suit the end-users requirements (needs). Callout.lsp Quote
Lee Mac Posted April 5, 2009 Posted April 5, 2009 I think the quotation marks were due to your units setting being in imperial and not metric, but this should work for you ;; ============ Num.lsp =============== ;; ;; FUNCTION: ;; Will sequentially place numerical ;; text upon mouse click, with optional ;; prefix and suffix. ;; ;; SYNTAX: num ;; ;; AUTHOR: ;; Copyright (c) 2009, Lee McDonnell ;; (Contact Lee Mac, CADTutor.net) ;; ;; PLATFORMS: ;; No Restrictions, ;; only tested in ACAD 2004. ;; ;; VERSION: ;; 1.0 ~ 05.04.2009 ;; ;; ==================================== (defun c:num (/ vlst ovar dVars tmpVars pt) (setq vlst '("OSMODE" "CLAYER") ovar (mapcar 'getvar vlst)) (setvar "OSMODE" 0) (or (tblsearch "LAYER" "NumText") (vla-put-color (vla-add (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object))) "NumText") acYellow)) (setq dVars '(sNum inNum Pref Suff)) (mapcar '(lambda (x y) (or (boundp x) (set x y))) dVars '(1 1 "" "")) (setq tmpVars (list (getreal (strcat "\nSpecify Starting Number <" (rtos sNum 2 2) ">: ")) (getreal (strcat "\nSpecify Increment <" (rtos inNum 2 2) ">: ")) (getstring (strcat "\nSpecify Prefix <" (if (eq "" Pref) "-None-" Pref) ">: ")) (getstring (strcat "\nSpecify Suffix <" (if (eq "" Suff) "-None-" Suff) ">: ")))) (mapcar '(lambda (x y) (or (or (not x) (eq "" x)) (set y x))) tmpVars dVars) (while (setq pt (getpoint "\nClick for Text... ")) (Make_Text pt (strcat Pref (rtos sNum 2 2) Suff)) (setq sNum (+ sNum inNum))) (mapcar 'setvar vlst ovar) (princ)) (defun Make_Text (txt_pt txt_val) (entmake (list '(0 . "TEXT") '(8 . "NumText") (cons 10 txt_pt) (cons 40 (max 2.5 (getvar "TEXTSIZE"))) (cons 1 txt_val) '(50 . 0.0) (cons 7 (getvar "TEXTSTYLE")) '(71 . 0) '(72 . 1) '(73 . 2) (cons 11 txt_pt)))) Quote
Cad64 Posted April 5, 2009 Posted April 5, 2009 I think it's time to move this thread to the lisp section. :wink: Quote
Lee Mac Posted April 5, 2009 Posted April 5, 2009 Ok, hows this :P ;; ============ NumCur.lsp =============== ;; ;; FUNCTION: ;; Will sequentially place numerical ;; text at the end of a leader, upon ;; mouse click. ;; ;; SYNTAX: numCur ;; ;; AUTHOR: ;; Copyright (c) 2009, Lee McDonnell ;; (Contact Lee Mac, CADTutor.net) ;; ;; PLATFORMS: ;; No Restrictions, ;; only tested in ACAD 2004. ;; ;; VERSION: ;; 1.0 ~ 05.04.2009 ;; ;; ======================================= (defun c:numCur (/ *error* vlst ovar doc spc dVars tmpVars cObj tBox GLst mPos cPt cDis EnPt ArPt1 ArPt2 AngCor vCol Verts VertVar ) (vl-load-com) (defun *error* (msg) (redraw) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\nError: " (strcase msg))) (princ "\n<<-- cancelled -->>")) (princ)) (setq vlst '("OSMODE" "CLAYER") ovar (mapcar 'getvar vlst)) (setvar "OSMODE" 0) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (or (tblsearch "LAYER" "Num-Text") (vla-put-color (vla-add (vla-get-layers doc) "NumText") acYellow)) (setq dVars '(sNum inNum Pref Suff)) (mapcar '(lambda (x y) (or (boundp x) (set x y))) dVars '(1 1 "" "")) (setq tmpVars (list (getreal (strcat "\nSpecify Starting Number <" (rtos sNum 2 2) ">: ")) (getreal (strcat "\nSpecify Increment <" (rtos inNum 2 2) ">: ")) (getstring t (strcat "\nSpecify Prefix <" (if (eq "" Pref) "-None-" Pref) ">: ")) (getstring t (strcat "\nSpecify Suffix <" (if (eq "" Suff) "-None-" Suff) ">: ")))) (mapcar '(lambda (x y) (or (or (not x) (eq "" x)) (set y x))) tmpVars dVars) (while (and (setq cEnt (car (entsel "\nSelect Curve to Label: "))) (member (cdr (assoc 0 (entget cEnt))) '("LINE" "POLYLINE" "LWPOLYLINE" "SPLINE" "ARC" "ELLIPSE" "CIRCLE"))) (vla-EndUndoMark doc) (vla-StartUndomark doc) (setq cObj (vlax-ename->vla-object cEnt) tBox (textbox (list (cons 1 (setq tStr (strcat Pref (rtos sNum 2 0) Suff)))))) (princ "\nSelect Location for Leader... ") (while (= (car (setq GLst (grread T 1))) 5) (redraw) (if (= (type (setq mPos (cadr GLst))) 'list) (progn (setq cPt (vlax-curve-getClosestPointto cObj mPos) cAng (angle cPt mPos) cDis (distance cPt mPos) EnPt (polar cPt cAng (/ cDis 1.5)) ArPt1 (polar cPt (+ cAng (/ pi 12)) (/ cDis 8.0)) ArPt2 (polar cPt (- cAng (/ pi 12)) (/ cDis 8.0)) AngCor (fix (abs (* 10.0 (fix (* 18.0 (/ cAng pi))))))) (or (and (< AngCor 1.0) (setq vCol 1)) (setq vCol AngCor)) (grvecs (list vCol cPt EnPt vCol cPt ArPt1 vCol cPt ArPt2))))) (princ "\nSelect Leader Size & Angle...") (while (= (car (setq GLst (grread T 1))) 5) (redraw) (if (= (type (setq mPos (cadr GLst))) 'list) (progn (setq cAng (angle cPt mPos) cDis (distance cPt mPos) ArPt1 (polar cPt (+ cAng (/ pi 12)) (/ cDis 8.0)) ArPt2 (polar cPt (- cAng (/ pi 12)) (/ cDis 8.0))) (grvecs (list vCol cPt mPos vCol cPt ArPt1 vCol cPt ArPt2))))) (setq Verts (apply 'append (list cPt mPos)) VertVar (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length Verts)))) Verts))) (vla-addleader spc VertVar (vla-addMText spc (vlax-3d-Point (polar mPos 0 (/ (getvar "TEXTSIZE") 2.0))) (- (caadr tBox) (caar tBox)) tStr) acLineWithArrow) (redraw) (setq sNum (+ sNum inNum))) (mapcar 'setvar vlst ovar) (redraw) (princ)) Quote
Lee Mac Posted April 6, 2009 Posted April 6, 2009 Don't forget TCOUNT in ExpressTools Never knew that was there - fantastic command as well! Quote
Lee Mac Posted April 6, 2009 Posted April 6, 2009 Actually this is better (colourwise): ;; ============ NumCur.lsp =============== ;; ;; FUNCTION: ;; Will sequentially place numerical ;; text at the end of a leader, upon ;; mouse click. ;; ;; SYNTAX: numCur ;; ;; AUTHOR: ;; Copyright (c) 2009, Lee McDonnell ;; (Contact Lee Mac, CADTutor.net) ;; ;; PLATFORMS: ;; No Restrictions, ;; only tested in ACAD 2004. ;; ;; VERSION: ;; 1.0 ~ 05.04.2009 ;; ;; ======================================= (defun c:numCur (/ *error* vlst ovar doc spc dVars tmpVars cObj tBox GLst mPos cPt cDis EnPt ArPt1 ArPt2 AngCor vCol Verts VertVar ) (vl-load-com) (defun *error* (msg) (redraw) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\nError: " (strcase msg))) (princ "\n<<-- cancelled -->>")) (princ)) (setq vlst '("OSMODE" "CLAYER") ovar (mapcar 'getvar vlst)) (setvar "OSMODE" 0) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (or (tblsearch "LAYER" "Num-Text") (vla-put-color (vla-add (vla-get-layers doc) "NumText") acYellow)) (setq dVars '(sNum inNum Pref Suff)) (mapcar '(lambda (x y) (or (boundp x) (set x y))) dVars '(1 1 "" "")) (setq tmpVars (list (getreal (strcat "\nSpecify Starting Number <" (rtos sNum 2 2) ">: ")) (getreal (strcat "\nSpecify Increment <" (rtos inNum 2 2) ">: ")) (getstring t (strcat "\nSpecify Prefix <" (if (eq "" Pref) "-None-" Pref) ">: ")) (getstring t (strcat "\nSpecify Suffix <" (if (eq "" Suff) "-None-" Suff) ">: ")))) (mapcar '(lambda (x y) (or (or (not x) (eq "" x)) (set y x))) tmpVars dVars) (while (and (setq cEnt (car (entsel "\nSelect Curve to Label: "))) (member (cdr (assoc 0 (entget cEnt))) '("LINE" "POLYLINE" "LWPOLYLINE" "SPLINE" "ARC" "ELLIPSE" "CIRCLE"))) (vla-EndUndoMark doc) (vla-StartUndomark doc) (setq cObj (vlax-ename->vla-object cEnt) tBox (textbox (list (cons 1 (setq tStr (strcat Pref (rtos sNum 2 0) Suff)))))) (princ "\nSelect Location for Leader... ") (while (= (car (setq GLst (grread T 1))) 5) (redraw) (if (= (type (setq mPos (cadr GLst))) 'list) (progn (setq cPt (vlax-curve-getClosestPointto cObj mPos) cAng (angle cPt mPos) cDis (distance cPt mPos) EnPt (polar cPt cAng (/ cDis 1.5)) ArPt1 (polar cPt (+ cAng (/ pi 12)) (/ cDis 8.0)) ArPt2 (polar cPt (- cAng (/ pi 12)) (/ cDis 8.0)) AngCor (fix (rem (abs (* 10.0 (fix (* 18.0 (/ cAng pi))))) 255.0))) (or (and (< AngCor 1.0) (setq vCol 1)) (setq vCol AngCor)) (grvecs (list vCol cPt EnPt vCol cPt ArPt1 vCol cPt ArPt2))))) (princ "\nSelect Leader Size & Angle...") (while (= (car (setq GLst (grread T 1))) 5) (redraw) (if (= (type (setq mPos (cadr GLst))) 'list) (progn (setq cAng (angle cPt mPos) cDis (distance cPt mPos) ArPt1 (polar cPt (+ cAng (/ pi 12)) (/ cDis 8.0)) ArPt2 (polar cPt (- cAng (/ pi 12)) (/ cDis 8.0))) (grvecs (list vCol cPt mPos vCol cPt ArPt1 vCol cPt ArPt2))))) (setq Verts (apply 'append (list cPt mPos)) VertVar (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length Verts)))) Verts))) (vla-addleader spc VertVar (vla-addMText spc (vlax-3d-Point (polar mPos 0 (/ (getvar "TEXTSIZE") 2.0))) (- (caadr tBox) (caar tBox)) tStr) acLineWithArrow) (redraw) (setq sNum (+ sNum inNum))) (mapcar 'setvar vlst ovar) (redraw) (princ)) Quote
tzframpton Posted April 6, 2009 Posted April 6, 2009 CAB has an excellent one over at theswamp.org that my office uses on a daily basis. Quote
Lee Mac Posted April 6, 2009 Posted April 6, 2009 I just like messing around with the GRREAD, GRVECS etc commands Quote
tzframpton Posted April 6, 2009 Posted April 6, 2009 http://www.theswamp.org/index.php?topic=518.0 Quote
CAB Posted April 6, 2009 Posted April 6, 2009 Thanks, Make sure you try version 26 here http://www.theswamp.org/index.php?topic=518.msg295901#msg295901 Also testing version 29, see last post by me. 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.