Jump to content

Auto insert blocks on pline points possible?


Recommended Posts

Posted

Wasn't sure if it I could have a better luck starting a new post (somewhat) continuing from

http://www.cadtutor.net/forum/newthread.php?do=newthread&f=21

..but as it goes Lee Mac posted one of my personal favorite lisps so far and I'm crossing my fingers to have it tweaked just a bit if it's even possible. As the code is..it imports a block to the endpoints of lines,arcs, and a few other entities; however the lisp will not completely function w/ plines and just adds the block to the endpoints of the pline. My question is...Is it possible to make this lisp import the block to points within a selected group of plines?..or doing the reverse of what the lisp will do now..and add the block to the points within the pline excluding the endpoints? Any suggestions are appreciated!

 

Below is Lee's masterpiece..and below that is a code that will insert blocks at nodes..(I was pondering all the possible solutions..but if theres a way to insert a node at points in a pline..ive come across a lisp that deletes all nodes...then I could use this?? idk.

 

 

 

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

;;;--- 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)
)

Posted

Yes, this can be done, my Point Manager program already has this functionality (and much more), although it doesn't rotate the blocks in any way (not sure if this is desired?)

 

See here for starters:

http://www.cadtutor.net/forum/showthread.php?42954-Point-Manager

Posted

I can't wait to go through it! No rotation needed at all..So cool! Thank you Lee

Posted

Or, very quickly for what you want:

 

;;-----------------=={ Block At Vertices }==------------------;;
;;                                                            ;;
;;  Inserts a Block at each vertex of selected Polylines,     ;;
;;  with the exclusion of start/end vertices                  ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;

(defun c:BlockAtVertices ( / *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 . "*POLYLINE")))))

     (princ "\n*Cancel*")
   )
   (t

     (_StartUndo doc)
    
     (
       (lambda ( i / e )
         (while (setq e (ssname ss (setq i (1+ i))))
           (
             (lambda ( param end )
               (while (< (setq param (1+ param)) end)
                 (_Insert block (vlax-curve-getPointatParam e param) (_AngleAtParam e param))
               )
             )
             (vlax-curve-getStartParam e) (vlax-curve-getEndParam e)
           )
         )
       )
       -1
     )

     (_EndUndo doc)
   )
 )

 (princ)
)

Bear in mind that the angle will be varied as the vertex is perhaps a point of inflection.

 

Or with no rotation:

 

;;-----------------=={ Block At Vertices }==------------------;;
;;                                                            ;;
;;  Inserts a Block at each vertex of selected Polylines,     ;;
;;  with the exclusion of start/end vertices                  ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;

;; Modified: Blocks inserted at Zero Rotation.

(defun c:BlockAtVertices ( / *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)
     )
   )
 )
 
 (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 . "*POLYLINE")))))

     (princ "\n*Cancel*")
   )
   (t

     (_StartUndo doc)
    
     (
       (lambda ( i / e )
         (while (setq e (ssname ss (setq i (1+ i))))
           (
             (lambda ( param end )
               (while (< (setq param (1+ param)) end)
                 (_Insert block (vlax-curve-getPointatParam e param) 0.0)
               )
             )
             (vlax-curve-getStartParam e) (vlax-curve-getEndParam e)
           )
         )
       )
       -1
     )

     (_EndUndo doc)
   )
 )

 (princ)
)

Posted

That's 100% it..Many thanks! My head might explode, but still can't wait to explore that first code:)

  • 2 years later...
Posted

Hello,

 

;;---------------------=={ 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") ;;

(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)

)

I have found this lisp usefull but is it possible to explode the block right after putting it in the dwg... ? Or maybe another solution... ?

What I want is to put the block with parameters so "endtick.dwg" would already have block defined in. Than lisp creates another block of it and I have to explode the block to get the parameters working.

 

Thanx in advance,

Posted (edited)
Hello,

 

 

I have found this lisp usefull but is it possible to explode the block right after putting it in the dwg... ? Or maybe another solution... ?

What I want is to put the block with parameters so "endtick.dwg" would already have block defined in. Than lisp creates another block of it and I have to explode the block to get the parameters working.

 

Thanx in advance,

 

try changing this: (command "_.-insert" block)

to this: (command "_.-insert" (strcat "*" block))

 

(untested)

 

edit: tested and not working for some reason

so I just put a (command "explode" (entlast)) one line before the last (princ). that worked, but it's ugly haha

Edited by fabriciorby
Posted

Hi,

 

Thanx for the reply. It works but somehow not completly :)

Im my case it explodes the block at the end of the line but not the one at starting point..

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