Jump to content

Recommended Posts

Posted

So dealing with mlines specifically..I was hoping to insert a block specified in the code at the endpoints only.. Lee's been a huge help..actually just today helping me with the following to insert a block on everything but the endpoints, which is perfect for inserting ftgs! This potential code could help us to insert a point load/# of studs (a 4" solid square block) at the end of all beams/hdrs that we draw with mlines. This would be such a big help as I alone go through about 200 of these in a day..that could potentially be completed with 3 clicks..fingers crossed..Any help is appreciated.

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

 

(These two codes may be from Alanjt though not positive..maybe from a thread he referenced but have since lost that page..sorry!)

 

 (defun c:aaa ()
   (vl-load-com)
   (setq *model-space* 
          (vla-get-modelspace 
             (vla-get-activedocument 
                (vlax-get-acad-object))))
   (setq obj (vlax-ename->vla-object (car (entsel))))
   (setq c (vlax-get obj "Coordinates") i 0)
   (repeat (/ (length c) 3)
     (setq x (nth i c) y (nth (1+ i) c) z (nth (+ 2 i) c))
     (vla-addtext *model-space* (rtos z 2) (vlax-3d-point (list x y 0.0)) 3.0)
     (setq i (+ i 3)) 
   )
   (princ)
 )

 

 (defun c:aaaa ()
   (vl-load-com)
   (setq *model-space* (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
   (setq obj (vlax-ename->vla-object (car (entsel))))
   (setq c (vlax-get obj "Coordinates") i 0)
   (repeat (/ (length c) 2)
     (setq x (nth i c) y (nth (1+ i) c))
     (vla-addcircle *model-space* (vlax-3d-point (list x y 0.0)) 3.0)
     (setq i (+ i 2)) 
   )
   (princ)
 )

Posted

I should probably mention that the 2nd code can insert text at the endpoints of an mline though no block and 3rd code inserts a symbol only on one end(probably could have left that off..I tried to replace "vla-addtext *model-space* amongst other things..though no luck..noob on the loose!

Posted
(These two codes may be from Alanjt though not positive..maybe from a thread he referenced but have since lost that page..sorry!)

Not from me.

Posted
Not from me.

 

I was going to say - those didn't look like your 'style'.

 

Its funny, even without the creds you can usually tell who wrote the code...

Posted (edited)

Quick mod:

 

;;-----------------=={ 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 to Include MLines, blocks inserted at zero rotation.

(defun c:BlockAtVertices ( / *error* _StartUndo _EndUndo _Insert _MAssoc 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 _MAssoc ( key lst )
   (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) key)) lst))
 )

 (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,MLINE")))))

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

     (_StartUndo doc)
    
     (
       (lambda ( i / e )
         (while (setq e (ssname ss (setq i (1+ i))))
           (if (wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE")
             (
               (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)
             )
             (foreach x (cdr (reverse (cdr (_MAssoc 11 (entget e)))))
                (_Insert block x 0.0)
             )
           )
         )
       )
       -1
     )

     (_EndUndo doc)
   )
 )

 (princ)
)

Edited by Lee Mac
Posted

Certainly a big difference in the two codes Alan..I believe you had a "updated" that code big time...I still can't find that original page..but you had listed this code at

http://forums.augi.com/showthread.php?p=1100574#post1099766

.

 

Reading through to your post in 5. "That was fun." comment. :lol: hahha

 

thanks Lee! Trying it out, there's no error being reported, though the block doesn't seem to come in. Hopefully figure something..I could explode them if necessary? Not the most preferred method but certainly an option..as always, much thanks.

Posted
thanks Lee! Trying it out, there's no error being reported, though the block doesn't seem to come in. Hopefully figure something..I could explode them if necessary? Not the most preferred method but certainly an option..as always, much thanks.

 

Be sure to check the block name at the top of the code. I had left it set to a block I was using for testing. It perhaps may have said 'Block not found' at the command line.

Posted

No I picked up on that..While I was screwing around with it I had deleted the following snippet at the end of the code..and it would insert the block, again just at the vertices..so it's recognizing the block..

 

(foreach x (cdr (reverse (cdr (_MAssoc 11 (entget e)))))
                (_Insert block x 0.0)

Posted

Seems to work for me - bear in mind that it is ignoring the endpoints of the MLine.

Posted

haha, Your helping me too much! Any way for only the endpoints? With all these reference codes I'm posting and the code yesterday very similar..can see the mixup.

Posted
;;-----------------=={ Block At EndPoints }==-----------------;;
;;                                                            ;;
;;  Inserts a Block at the start/end vertices of a polyline   ;;
;;  or mline                                                  ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;

(defun c:BlockAtEnds ( / *error* _StartUndo _EndUndo _Insert _MAssoc 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 _MAssoc ( key lst )
   (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= (car x) key)) lst))
 )

 (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,MLINE")))))

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

     (_StartUndo doc)
    
     (
       (lambda ( i / e p )
         (while (setq e (ssname ss (setq i (1+ i))))
           (mapcar
             (function
               (lambda ( p ) (_Insert block p 0.0))
             )
             (if (wcmatch (cdr (assoc 0 (entget e))) "*POLYLINE")
               (list
                 (vlax-curve-getStartPoint e)
                 (vlax-curve-getEndPoint   e)
               )
               (progn (setq p (_MAssoc 11 (entget e)))
                 (list (car p) (last p))
               )
             )
           )
         )
       )
       -1
     )

     (_EndUndo doc)
   )
 )

 (princ)
)

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