Results 1 to 4 of 4

Thread: Insert blocks along a polyline

  1. #1
    Member
    Join Date
    2016-03
    Posts
    2
    Login to Give a bone
    0

    Default Insert blocks along a polyline

    Hey, i want to insert different blocks along a polyline at different distances. I am new to LISP routines and the closest thing i found is a routine called put.

    Code:
    (defun C:PUT (/ os ce bm blk ent obj ppt dst ept ref len ipt par slp ang)
      (command "_.undo" "_be")
      (setq os (getvar "osmode")
            ce (getvar "cmdecho")
            bm (getvar "blipmode")
            blk ""
      );;setq
      (if (not bk)(setq bk ""))
      (setvar "osmode" 0)
      (setvar "cmdecho" 0)
      (setvar "blipmode" 0)
      (while (not (setq ent (entsel "\nSelect object near reference end: "))))
      (while
        (and
          (not (tblsearch "block" blk))
          (not (findfile (strcat blk ".dwg")))
        );;and
        (setq blk (getstring (strcat "\nBlock to use <" bk ">: ")))
        (if (> blk "")(setq bk blk)(setq blk bk))      
      );;while
      (setq obj (car ent)
            ppt (osnap (cadr ent) "nea")
            dst (getdist "\nDistance to Block Insertion: ")
            ept (vlax-curve-getEndPoint obj)
            ref (vlax-curve-getDistAtPoint obj ppt)
            len (vlax-curve-getDistAtPoint obj ept)
      );;setq
      (if (> ref (/ len 2.0))
        (setq dst (- len dst))
      );;setq
      (setq ipt (vlax-curve-getPointAtDist obj dst)
            par (vlax-curve-getParamAtPoint obj ipt)
            slp (vlax-curve-getFirstDeriv obj par)
            ang (atan (/ (cadr slp)(car slp)))
      );;setq
      (entmake
        (list
          '(0 . "INSERT")
          (cons 2 blk)
          (cons 10 ipt)
          (cons 50 ang)
        );;list
      );;entmake
      (setvar "osmode" os)
      (setvar "cmdecho" ce)
      (setvar "blipmode" bm)
      (command "_.undo" "_e")
      (princ)
    )
    (alert
      (strcat
        "PUT.LSP ver. 2.0 (c) 2005 Tee Square Graphics"
        "\n\n            Type PUT to begin."
      )
    )
    The problem is, I have to select the polyline each time I run it. I want to be able to insert many blocks into the same polyline from a text file like a script, or a spreasheet. Is there a way to do that? Thanks.

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Insert blocks along a polyline

    Wrap it all in while loop...

    Code:
    (defun C:PUT (/ os ce bm blk ent obj ppt dst ept ref len ipt par slp ang)
      (command "_.undo" "_be")
      (setq os (getvar "osmode")
            ce (getvar "cmdecho")
            bm (getvar "blipmode")
            blk ""
      );;setq
      (if (not bk)(setq bk ""))
      (setvar "osmode" 0)
      (setvar "cmdecho" 0)
      (setvar "blipmode" 0)
      (while (not (setq ent (entsel "\nSelect object near reference end: "))))
      (while
        (and
          (not (tblsearch "block" blk))
          (not (findfile (strcat blk ".dwg")))
        );;and
        (setq blk (getstring (strcat "\nBlock to use <" bk ">: ")))
        (if (> blk "")(setq bk blk)(setq blk bk))      
        (setq obj (car ent)
              ppt (osnap (cadr ent) "nea")
              dst (getdist "\nDistance to Block Insertion: ")
              ept (vlax-curve-getEndPoint obj)
              ref (vlax-curve-getDistAtPoint obj ppt)
              len (vlax-curve-getDistAtPoint obj ept)
        );;setq
        (if (> ref (/ len 2.0))
          (setq dst (- len dst))
        );;setq
        (setq ipt (vlax-curve-getPointAtDist obj dst)
              par (vlax-curve-getParamAtPoint obj ipt)
              slp (vlax-curve-getFirstDeriv obj par)
              ang (atan (/ (cadr slp)(car slp)))
        );;setq
        (entmake
          (list
            '(0 . "INSERT")
            (cons 2 blk)
            (cons 10 ipt)
            (cons 50 ang)
          );;list
        );;entmake
      );;while
      (setvar "osmode" os)
      (setvar "cmdecho" ce)
      (setvar "blipmode" bm)
      (command "_.undo" "_e")
      (princ)
    )
    (alert
      (strcat
        "PUT.LSP ver. 2.0 (c) 2005 Tee Square Graphics"
        "\n\n            Type PUT to begin."
      )
    )

  3. #3
    Member
    Join Date
    2016-03
    Posts
    2
    Login to Give a bone
    0

    Default Re: Insert blocks along a polyline

    Thanks for the reply. I ran the program and even though it's been modified seems to be working the same way. I want to make 2 modifications to it. I want to be able to pick the object first (which i forgot to mention in my first post), and only select it once, and then for it to ask for the block and distance continuously. That way, I can insert all the blocks I need at once by using a script, which is an easier way for me since I'm more familiar with it. I see with your suggestion you intended to make the second modification I wanted, but it didn't seem to work.

  4. #4
    Woo! Hoo! my 1st post
    Join Date
    2019-07
    Posts
    1
    Login to Give a bone
    0

    Default Re: Insert blocks along a polyline

    Quote Originally Posted by MarceloR7 View Post
    Thanks for the reply. I ran the program and even though it's been modified seems to be working the same way. I want to make 2 modifications to it. I want to be able to pick the object first (which i forgot to mention in my first post), and only select it once, and then for it to ask for the block and distance continuously. That way, I can insert all the blocks I need at once by using a script, which is an easier way for me since I'm more familiar with it. I see with your suggestion you intended to make the second modification I wanted, but it didn't seem to work.
    see if it works
    Code:
    ;| PUT.LSP ver. 2.0 (c) 2005 Tee Square Graphics
        Improved version of PUT.LSP originally published in 1998. This
        version avoids the use of the native MEASURE command, using instead
        the curve functions of Visual LISP (VLISP).
        
        PUT places a single block insertion a user-specified distance from
        the selected end of a non-closed AutoCAD object (i.e., ARC, LINE, 
        POLYLINE, LWPOLYLINE, SPLINE).
    |;
    
    (defun C:PUT (/ os ce bm blk ent obj ppt dst ept ref len ipt par slp ang)
      (command "_.undo" "_be")
      (setq os (getvar "osmode")
            ce (getvar "cmdecho")
            bm (getvar "blipmode")
            blk ""
      );;setq
      (if (not bk)(setq bk ""))
      (setvar "osmode" 0)
      (setvar "cmdecho" 0)
      (setvar "blipmode" 0)
      (while (not (setq ent (entsel "\nSelect object near reference end: "))))
      (while
        (and
          (not (tblsearch "block" blk))
          (not (findfile (strcat blk ".dwg")))
        );;and
        (setq blk (getstring (strcat "\nBlock to use <" bk ">: ")))
        (if (> blk "")(setq bk blk)(setq blk bk))      
      );;while
    (while
    (setq obj (car ent)
            ppt (osnap (cadr ent) "nea")
            dst (getdist "\nDistance to Block Insertion: ")
            ept (vlax-curve-getEndPoint obj)
            ref (vlax-curve-getDistAtPoint obj ppt)
            len (vlax-curve-getDistAtPoint obj ept)
      );;setq
      (if (> ref (/ len 2.0))
        (setq dst (- len dst))
      );;setq
      (setq ipt (vlax-curve-getPointAtDist obj dst)
            par (vlax-curve-getParamAtPoint obj ipt)
            slp (vlax-curve-getFirstDeriv obj par)
            ang (atan (/ (cadr slp)(car slp)))
      );;setq
      (entmake
        (list
          '(0 . "INSERT")
          (cons 2 blk)
          (cons 10 ipt)
          (cons 50 ang)
        );;list
      );;entmake
    )
      (setvar "osmode" os)
      (setvar "cmdecho" ce)
      (setvar "blipmode" bm)
      (command "_.undo" "_e")
      (princ)
    )
    (alert
      (strcat
        "PUT.LSP ver. 2.0 (c) 2005 Tee Square Graphics"
        "\n\n            Type PUT to begin."
      )
    )
    Last edited by Opie; 2020-01-30 at 03:28 PM. Reason: [code] tags added

Similar Threads

  1. insert block on polyline
    By ezhilanand10674421 in forum AutoLISP
    Replies: 4
    Last Post: 2015-08-11, 02:37 AM
  2. Replies: 0
    Last Post: 2015-03-19, 11:57 PM
  3. Insert a Block at each point along a Polyline
    By DMoore.67173 in forum AutoLISP
    Replies: 34
    Last Post: 2010-10-24, 09:25 AM
  4. Insert Arch when editing a Polyline
    By hiwamura in forum CAD Management - General
    Replies: 12
    Last Post: 2008-10-02, 07:41 PM
  5. VBA project - draw a line of polyline, then insert a block
    By jbortoli in forum VBA/COM Interop
    Replies: 0
    Last Post: 2007-05-14, 08:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •