jake77777 Posted October 1, 2010 Posted October 1, 2010 (edited) I loved this lisp the first time I saw it. It allows you to insert a specified block at all endpoints of selected objects. This would be awesome to use for inserting footings after dimensioning..We found for our us, making lines at the spec'd distance, then quick dimensioning worked well. We would just add this lisp before dimensioning and we'd have our footings drop in automatically! Only problem I can't figure out was how to import the block at 1:1 scale rather than basing it of the dim scale/txt height. Thanks Thomas for letting me post this! ;;; ENDTICK.LSP ;;; ;;; Copyright 2006 Thomas Gail Haws ;;; This program is free software under the terms of the ;;; GNU (GNU--acronym for Gnu's Not Unix--sounds like canoe) ;;; General Public License as published by the Free Software Foundation, ;;; version 2 of the License. ;;; ;;; You can redistribute this software for any fee or no fee and/or ;;; modify it in any way, but it and ANY MODIFICATIONS OR DERIVATIONS ;;; continue to be governed by the license, which protects the perpetual ;;; availability of the software for free distribution and modification. ;;; ;;; You CAN'T put this code into any proprietary package. Read the license. ;;; ;;; If you improve this software, please make a revision submittal to the ;;; copyright owner at [url="http://www.hawsedc.com/"]www.hawsedc.com[/url]. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License on the World Wide Web for more details. ;;; ;;; DESCRIPTION ;;; ;;; ENDTICK inserts and aligns the ENDTICK block at the endpoint of every arc or line ;;; in a selection set. It removes duplicate ticks. ;;; ;;; ENDTICK is useful for surveying and civil engineering plans to demarcate points of ;;; curvature, tangency, et cetera. ;;; ;;; You can make your own ENDTICK block if you prefer some custom shape or size tick. ;;; The default ENDTICK block is a one unit long vertical line with its insertion point ;;; at its midpoint. ENDTICK scales the ticks to the dimension text height ;;; (dimscale * dimtext), so the default ENDTICK block will look as big as the current ;;; dimension text height. ;;; ;;; Revisions ;;; 20060914 TGH Version 1.0PR released. 3 hrs. Works only with world UCS and View (defun c:ENDTICK () (ENDTICK)) (defun ENDTICK ;;No global variables. All the variables should be listed here as local. (/ CENPOINT DS DT ENDANG ENDPOINT ENTLIST ENTNAME ENTTYPE I MINTICKSEPARATION RADIUS SS1 STARTANG STARTPOINT TICKLIST TS ) ;;Set initial variables (setq ds (getvar "dimscale") dt (getvar "dimtxt") ts (* ds dt) ;;If endpoints are closer together than the distance given below ;; and also aligned angularly closer than the angular difference below, ;; ENDTICK only plots the first one of them it finds. mintickseparation (* ts 0.01) ;;In radians. Setting to some big number like 10 (larger than 2 pi) will remove coincident ticks even with different rotations. mintickangulardif 0.01 ) ;;Get selection set from user. Limit to lines and arcs. (setq ss1 (ssget '((0 . "LINE,ARC"))) i -1 ) ;;Get endpoints and orientations from selection set (while (setq entname (ssname ss1 (setq i (1+ i)))) (setq entlist (entget entname) enttype (cdr (assoc 0 entlist)) ) (cond ((= enttype "LINE") (setq startpoint (cdr (assoc 10 entlist)) endpoint (cdr (assoc 11 entlist)) ticklist (ENDTICK-addtolist (list startpoint (angle startpoint endpoint)) ticklist mintickseparation mintickangulardif ) ticklist (ENDTICK-addtolist (list endpoint (angle endpoint startpoint) ) ticklist mintickseparation mintickangulardif ) ) ) ((= enttype "ARC") (setq cenpoint (cdr (assoc 10 entlist)) radius (cdr (assoc 40 entlist)) startang (cdr (assoc 50 entlist)) endang (cdr (assoc 51 entlist)) startpoint (polar cenpoint startang radius) endpoint (polar cenpoint endang radius) ticklist (ENDTICK-addtolist (list startpoint (+ startang (/ pi 2))) ticklist mintickseparation mintickangulardif ) ticklist (ENDTICK-addtolist (list endpoint (+ endang (/ pi 2))) ticklist mintickseparation mintickangulardif ) ) ) ) ) (setq auold (getvar "aunits")) (setvar "aunits" 3) (foreach tick ticklist (command "._insert" "endtick" (car tick) ts "" (cadr tick)) ) (setvar "aunits" auold) ) (defun ENDTICK-addtolist (tick ticklist mintickseparation mintickangulardif / dupfound templist tickcheck ) ;;Look for duplicates in list (setq templist ticklist) (while (setq tickcheck (car templist)) (if (and (< (distance (car tick) (car tickcheck)) mintickseparation) (< (abs (- (cadr tick) (cadr tickcheck))) mintickangulardif) ) (setq dupfound T templist nil ) (setq templist (cdr templist)) ) ) (if (not dupfound) (cons tick ticklist) ticklist ) ) Edited August 22, 2012 by SLW210 Add Code to The Code Tag!!! :{ Quote
jake77777 Posted October 1, 2010 Author Posted October 1, 2010 Block used for import endtick.dwg Quote
Lee Mac Posted October 1, 2010 Posted October 1, 2010 Code formatting: http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines Quote
jake77777 Posted October 1, 2010 Author Posted October 1, 2010 Thanks! Last reminder needed... ;;; ENDTICK.LSP ;;; ;;; Copyright 2006 Thomas Gail Haws ;;; This program is free software under the terms of the ;;; GNU (GNU--acronym for Gnu's Not Unix--sounds like canoe) ;;; General Public License as published by the Free Software Foundation, ;;; version 2 of the License. ;;; ;;; You can redistribute this software for any fee or no fee and/or ;;; modify it in any way, but it and ANY MODIFICATIONS OR DERIVATIONS ;;; continue to be governed by the license, which protects the perpetual ;;; availability of the software for free distribution and modification. ;;; ;;; You CAN'T put this code into any proprietary package. Read the license. ;;; ;;; If you improve this software, please make a revision submittal to the ;;; copyright owner at www.hawsedc.com. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License on the World Wide Web for more details. ;;; ;;; DESCRIPTION ;;; ;;; ENDTICK inserts and aligns the ENDTICK block at the endpoint of every arc or line ;;; in a selection set. It removes duplicate ticks. ;;; ;;; ENDTICK is useful for surveying and civil engineering plans to demarcate points of ;;; curvature, tangency, et cetera. ;;; ;;; You can make your own ENDTICK block if you prefer some custom shape or size tick. ;;; The default ENDTICK block is a one unit long vertical line with its insertion point ;;; at its midpoint. ENDTICK scales the ticks to the dimension text height ;;; (dimscale * dimtext), so the default ENDTICK block will look as big as the current ;;; dimension text height. ;;; ;;; Revisions ;;; 20060914 TGH Version 1.0PR released. 3 hrs. Works only with world UCS and View (defun c:ENDTICK () (ENDTICK)) (defun ENDTICK ;;No global variables. All the variables should be listed here as local. (/ CENPOINT DS DT ENDANG ENDPOINT ENTLIST ENTNAME ENTTYPE I MINTICKSEPARATION RADIUS SS1 STARTANG STARTPOINT TICKLIST TS ) ;;Set initial variables (setq ds (getvar "dimscale") dt (getvar "dimtxt") ts (* ds dt) ;;If endpoints are closer together than the distance given below ;; and also aligned angularly closer than the angular difference below, ;; ENDTICK only plots the first one of them it finds. mintickseparation (* ts 0.01) ;;In radians. Setting to some big number like 10 (larger than 2 pi) will remove coincident ticks even with different rotations. mintickangulardif 0.01 ) ;;Get selection set from user. Limit to lines and arcs. (setq ss1 (ssget '((0 . "LINE,ARC"))) i -1 ) ;;Get endpoints and orientations from selection set (while (setq entname (ssname ss1 (setq i (1+ i)))) (setq entlist (entget entname) enttype (cdr (assoc 0 entlist)) ) (cond ((= enttype "LINE") (setq startpoint (cdr (assoc 10 entlist)) endpoint (cdr (assoc 11 entlist)) ticklist (ENDTICK-addtolist (list startpoint (angle startpoint endpoint)) ticklist mintickseparation mintickangulardif ) ticklist (ENDTICK-addtolist (list endpoint (angle endpoint startpoint) ) ticklist mintickseparation mintickangulardif ) ) ) ((= enttype "ARC") (setq cenpoint (cdr (assoc 10 entlist)) radius (cdr (assoc 40 entlist)) startang (cdr (assoc 50 entlist)) endang (cdr (assoc 51 entlist)) startpoint (polar cenpoint startang radius) endpoint (polar cenpoint endang radius) ticklist (ENDTICK-addtolist (list startpoint (+ startang (/ pi 2))) ticklist mintickseparation mintickangulardif ) ticklist (ENDTICK-addtolist (list endpoint (+ endang (/ pi 2))) ticklist mintickseparation mintickangulardif ) ) ) ) ) (setq auold (getvar "aunits")) (setvar "aunits" 3) (foreach tick ticklist (command "._insert" "endtick" (car tick) ts "" (cadr tick)) ) (setvar "aunits" auold) ) (defun ENDTICK-addtolist (tick ticklist mintickseparation mintickangulardif / dupfound templist tickcheck ) ;;Look for duplicates in list (setq templist ticklist) (while (setq tickcheck (car templist)) (if (and (< (distance (car tick) (car tickcheck)) mintickseparation) (< (abs (- (cadr tick) (cadr tickcheck))) mintickangulardif) ) (setq dupfound T templist nil ) (setq templist (cdr templist)) ) ) (if (not dupfound) (cons tick ticklist) ticklist ) ) Quote
Lee Mac Posted October 1, 2010 Posted October 1, 2010 Quickly hacked together... ;;---------------------=={ EndBlock }==-----------------------;; ;; ;; ;; Inserts a Block at the end points of selected objects ;; ;;------------------------------------------------------------;; ;; Author: Lee McDonnell, 2010 ;; ;; ;; ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;; ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;; ;;------------------------------------------------------------;; (defun c:EndBlock ( / *error* _StartUndo _EndUndo _Insert _AngleAtParam doc spc block ss ) (vl-load-com) ;; © Lee Mac 2010 (setq block "endtick.dwg") ;; << Block Name (defun *error* ( msg ) (and doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) (defun _Insert ( space block point scale rotation ) (if (not (vl-catch-all-error-p (setq result (vl-catch-all-apply 'vla-insertblock (list space (vlax-3D-point point) block scale scale scale rotation) ) ) ) ) result ) ) (defun _AngleatParam ( entity param ) (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv entity param)) ) (LM:ActiveSpace 'doc 'spc) (cond ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER)))))) (princ "\n** Current Layer Locked **") ) ( (not (or (tblsearch "BLOCK" block) (setq block (findfile (strcat block (if (eq "" (vl-filename-extension block)) ".dwg" "") ) ) ) ) ) (princ "\n** Block not Found **") ) ( (not (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,SPLINE,LINE,LWPOLYLINE,"))))) (princ "\n*Cancel*") ) (t (_StartUndo doc) ( (lambda ( i / e ) (while (setq e (ssname ss (setq i (1+ i)))) (mapcar (function (lambda ( point rotation ) (_Insert spc block point 1.0 rotation) ) ) (if (vlax-curve-isClosed e) (list (vlax-curve-getStartPoint e)) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)) ) (mapcar (function (lambda ( param ) (_AngleAtParam e param)) ) (if (vlax-curve-isClosed e) (list (+ (vlax-curve-getStartParam e) 1e-4)) (list (+ (vlax-curve-getStartParam e) 1e-4) (- (vlax-curve-getEndParam e) 1e-4)) ) ) ) ) ) -1 ) (_EndUndo doc) ) ) (princ) ) ;;--------------------=={ ActiveSpace }==---------------------;; ;; ;; ;; Retrieves pointers to the Active Document and Space ;; ;;------------------------------------------------------------;; ;; Author: Lee McDonnell, 2010 ;; ;; ;; ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;; ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; *doc - quoted symbol other than *doc ;; ;; *spc - quoted symbol other than *spc ;; ;;------------------------------------------------------------;; (defun LM:ActiveSpace ( *doc *spc ) ;; © Lee Mac 2010 (set *spc (if (or (eq AcModelSpace (vla-get-ActiveSpace (set *doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ) ) ) (eq :vlax-true (vla-get-MSpace (eval *doc))) ) (vla-get-ModelSpace (eval *doc)) (vla-get-PaperSpace (eval *doc)) ) ) ) Not as many options, but may do the trick Quote
Lee Mac Posted October 1, 2010 Posted October 1, 2010 This is probably quicker actually... ;;---------------------=={ EndBlock }==-----------------------;; ;; ;; ;; Inserts a Block at the end points of selected objects ;; ;;------------------------------------------------------------;; ;; Author: Lee McDonnell, 2010 ;; ;; ;; ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;; ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;; ;;------------------------------------------------------------;; (defun c:EndBlock ( / *error* _StartUndo _EndUndo _Insert _AngleAtParam doc block ss ) (vl-load-com) ;; © Lee Mac 2010 (setq block "endtick.dwg") ;; << Block Name (defun *error* ( msg ) (and doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) (defun _Insert ( block point rotation ) (entmakex (list (cons 0 "INSERT") (cons 2 block) (cons 10 point) (cons 50 rotation) ) ) ) (defun _AngleatParam ( entity param ) (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv entity param)) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (cond ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER)))))) (princ "\n** Current Layer Locked **") ) ( (not (or (and (tblsearch "BLOCK" (vl-filename-base block)) (setq block (vl-filename-base block)) ) (and (setq block (findfile (strcat block (if (eq "" (vl-filename-extension block)) ".dwg" "") ) ) ) ( (lambda ( / ocm ) (setq ocm (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (command "_.-insert" block) (command) (setvar 'CMDECHO ocm) (tblsearch "BLOCK" (setq block (vl-filename-base block))) ) ) ) ) ) (princ "\n** Block not Found **") ) ( (not (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,SPLINE,LINE,LWPOLYLINE,"))))) (princ "\n*Cancel*") ) (t (_StartUndo doc) ( (lambda ( i / e ) (while (setq e (ssname ss (setq i (1+ i)))) (mapcar (function (lambda ( point rotation ) (_Insert block point rotation)) ) (if (vlax-curve-isClosed e) (list (vlax-curve-getStartPoint e)) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)) ) (mapcar (function (lambda ( param ) (_AngleAtParam e param)) ) (if (vlax-curve-isClosed e) (list (+ (vlax-curve-getStartParam e) 1e-4)) (list (+ (vlax-curve-getStartParam e) 1e-4) (- (vlax-curve-getEndParam e) 1e-4)) ) ) ) ) ) -1 ) (_EndUndo doc) ) ) (princ) ) Quote
jake77777 Posted October 2, 2010 Author Posted October 2, 2010 That's just perfect Lee..they even come in at the correct angles:D Thank you! Thank you! Thank you! Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 That's just perfect Lee..they even come in at the correct angles:D Thank you! Thank you! Thank you! You're welcome, I enjoyed writing them Quote
stevesfr Posted October 2, 2010 Posted October 2, 2010 Lee, in your program, what line of code governs the scale of the block being inserted ? thx Steve Quote
Lee Mac Posted October 2, 2010 Posted October 2, 2010 Hi Steve, In the first code: (_Insert spc block point [color=red][b]1.0[/b][/color] rotation) In the second code, add this: (defun _Insert ( block point rotation ) (entmakex (list (cons 0 "INSERT") (cons 2 block) (cons 10 point) (cons 50 rotation) [color=red][b] (cons 41 1.0) ;; X Scale (cons 42 1.0) ;; Y Scale (cons 43 1.0) ;; Z Scale[/b][/color] ) ) ) Quote
jake77777 Posted October 3, 2010 Author Posted October 3, 2010 I cannot get enough of this lisp! Just curious. As the code is..it imports a block to the endpoints only w/o adding the block to the endpoints of the lines within plines..Is it possible to have the block import to the points within a selected group of plines?..or even more, just these points and excluding the endpoints? My first amateur move was to add pline to the snippet ( (not (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,SPLINE,PLINE,LINE,LWPOLYLINE,"))))) That did not do it I had come across a similar code using node insert below, but thinking of all the snap settings don't know how something like that is possible..Any advice? Sorry I couldn't find the author to give credit to on this.. ;;;--- Insert a block on every node found in a drawing (defun C:NODESERT() (setvar "cmdecho" 0) (setq oldSnap(getvar "osmode")) (setvar "osmode" 0) (setq blkName(getstring T "\n Block name: ")) (setq ang(getangle "\n Rotation angle: ")) (setq scalef(getreal "\n Scale factor: ")) (if(setq eset(ssget "X" (list(cons 0 "POINT")))) (progn (setq cntr 0) (while(< cntr (sslength eset)) (setq en(ssname eset cntr)) (setq enlist(entget en)) (setq pt(cdr(assoc 10 enlist))) (command "-insert" blkName pt scalef scalef (angtos ang)) (setq cntr(+ cntr 1)) ) (alert (strcat "\n Inserted " (itoa(- cntr 1)) " blocks!")) ) (alert "No nodes found!") ) (setvar "osmode" oldSnap) (setvar "cmdecho" 1) (princ) This is Lee's fine piece of work I'm using from page 1 of post... ;;---------------------=={ EndBlock }==-----------------------;; ;; ;; ;; Inserts a Block at the end points of selected objects ;; ;;------------------------------------------------------------;; ;; Author: Lee McDonnell, 2010 ;; ;; ;; ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;; ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;; ;;------------------------------------------------------------;; (defun c:EndBlock ( / *error* _StartUndo _EndUndo _Insert _AngleAtParam doc block ss ) (vl-load-com) ;; © Lee Mac 2010 (setq block "endtick.dwg") ;; << Block Name (defun *error* ( msg ) (and doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) (defun _Insert ( block point rotation ) (entmakex (list (cons 0 "INSERT") (cons 2 block) (cons 10 point) (cons 50 rotation) ) ) ) (defun _AngleatParam ( entity param ) (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv entity param)) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (cond ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER)))))) (princ "\n** Current Layer Locked **") ) ( (not (or (and (tblsearch "BLOCK" (vl-filename-base block)) (setq block (vl-filename-base block)) ) (and (setq block (findfile (strcat block (if (eq "" (vl-filename-extension block)) ".dwg" "") ) ) ) ( (lambda ( / ocm ) (setq ocm (getvar 'CMDECHO)) (setvar 'CMDECHO 0) (command "_.-insert" block) (command) (setvar 'CMDECHO ocm) (tblsearch "BLOCK" (setq block (vl-filename-base block))) ) ) ) ) ) (princ "\n** Block not Found **") ) ( (not (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,SPLINE,LINE,LWPOLYLINE,"))))) (princ "\n*Cancel*") ) (t (_StartUndo doc) ( (lambda ( i / e ) (while (setq e (ssname ss (setq i (1+ i)))) (mapcar (function (lambda ( point rotation ) (_Insert block point rotation)) ) (if (vlax-curve-isClosed e) (list (vlax-curve-getStartPoint e)) (list (vlax-curve-getStartPoint e) (vlax-curve-getEndPoint e)) ) (mapcar (function (lambda ( param ) (_AngleAtParam e param)) ) (if (vlax-curve-isClosed e) (list (+ (vlax-curve-getStartParam e) 1e-4)) (list (+ (vlax-curve-getStartParam e) 1e-4) (- (vlax-curve-getEndParam e) 1e-4)) ) ) ) ) ) -1 ) (_EndUndo doc) ) ) (princ) ) Quote
Lee Mac Posted October 3, 2010 Posted October 3, 2010 As a reference to others, this thread continues here: http://www.cadtutor.net/forum/showthread.php?52992-Auto-insert-blocks-on-pline-points-possible FYI: The Polyline object is already included in the selectionset filter: 'LWPOLYLINE' - Polylines are not called 'PLINES'. The SelectionSet filter utilises the same data as can be found when querying an entity using entget, hence to check the entity name, use something like: (defun c:EName ( / e ) (while (setq e (car (entsel "\nSelect Entity: "))) (print (cdr (assoc 0 (entget e)))) ) (princ) ) Quote
asos2000 Posted August 22, 2012 Posted August 22, 2012 This lisp not working with REGION Could you please modify to deal with region This is probably quicker actually... ;;---------------------=={ EndBlock }==-----------------------;; 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.