See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Place a Block at points along a Polyline

  1. #1
    Member
    Join Date
    2007-05
    Posts
    38
    Login to Give a bone
    0

    Default Place a Block at points along a Polyline

    Hello,

    I'm just taking my first steps in the autolisp world, so forgive me if I'm asking for something obvious.

    I'm trying to put blocks along a polyline (for example, let's take a rectangle 55x95) using autolisp. What I want the command to do is the following:

    1. select a (previously drawn) polyline (user input)
    2. place a block on every corner of that polyline
    3. Place the same blocks along every vertice of the polyline ( using 'divide'??) in a way that the distance between two blocks is never greater than 8.

    The result would then be a rectangular polyline, with blocks on every corner, 12 blocks along the long sides (every 7.91) and 7 blocks along the short sides (every 7.86).

    If someone could put me in the right direction, i would be very grateful.

  2. #2
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    I wrote something that does something very similar. It was actually for Land Desktop, and was designed to place points at various offsets along polylines.

    The code is available here. The utility functions that perform this task are primarily in the VLUtil.lsp file, and the usage can be seen by looking at the PGRD.lsp file. Without Land Desktop, you can simply ignore all the Point stuff and all the stuff in the LDUtil.lsp file, and just concentrate on that stuff in VLUtil.lsp.

  3. #3
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    1

    Default Re: Place a Block at points along a Polyline

    wbreedveld
    A sample DWG goes a long way to convey your needs.

    Is the polyline the outside of the wall or center of the wall?
    Do you have a block you need to use or will any do?
    Are you working in Feet or Inches for Units?
    Why are the Long sides different from the short sides for spacing?
    Do you base your spacing on a clockwise or CCW direction? Or other?
    Are the blocks to be placed on a specific layer?
    Is the poly line on a specific layer?


    BTW
    Welcome to AUGI LISP

  4. #4
    Member
    Join Date
    2007-05
    Posts
    38
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    Quote Originally Posted by sinc
    I wrote something that does something very similar. It was actually for Land Desktop, and was designed to place points at various offsets along polylines.
    I will look into it.
    thanks!

  5. #5
    Member
    Join Date
    2007-05
    Posts
    38
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    Quote Originally Posted by CAB2k
    wbreedveld
    A sample DWG goes a long way to convey your needs.
    done see attatchment
    Quote Originally Posted by CAB2k
    Is the polyline the outside of the wall or center of the wall?
    that doesn't matter. It is just a single line, no wall
    Quote Originally Posted by CAB2k
    Do you have a block you need to use or will any do?
    block name = "paal"
    Quote Originally Posted by CAB2k
    Are you working in Feet or Inches for Units?
    nope, metric 1:1
    Quote Originally Posted by CAB2k
    Why are the Long sides different from the short sides for spacing?
    That's because the maximum distance between two blocks is 8, and the blocks have to be divided along a line \. Different linelenghts -> different spacings between blocks.
    Quote Originally Posted by CAB2k
    Do you base your spacing on a clockwise or CCW direction? Or other?
    that does not matter, i think?
    Quote Originally Posted by CAB2k
    Are the blocks to be placed on a specific layer?
    would be nie. in the example, they are placed in layer "block"
    Quote Originally Posted by CAB2k
    Is the poly line on a specific layer?
    yes, in the example it's in layer "polyline"


    Quote Originally Posted by CAB2k
    BTW
    Welcome to AUGI LISP
    thanks
    Attached Files Attached Files

  6. #6
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    The DWG helped, thanks.
    Here is an example.
    Code:
    ;;  CAB  05.22.07
    ;;  Divide a dividable object based on segment length
    ;;  and max dist between blocks to be inserted
    ;;    -=<  NO ERROR CHECKING  >=-
    (defun c:DivideSegments () (c:DS))
    (defun c:DS (/ CNT DIST ENDPAR ENT IDX LEN MSTEP START STEP clay)
      (vl-load-com)
      (setq clay (getvar "clayer"))
      (if (and (setq ent (entsel "\nSelect object to divide."))
               (not (vl-catch-all-error-p
                      (setq start (vl-catch-all-apply
                                    'vlax-curve-getpointatparam
                                    (list (car ent) 0.0))))))
        (progn
          (command "._Undo" "_begin")
          (setvar "clayer" "block")  ; Block Layer
          (setq ent (car ent))
          (setq mStep 8)
          (setq endpar (vlax-curve-getendparam ent))
          (setq idx 0)
          (while (<= (setq idx (1+ idx)) endpar)
            (setq len (- (vlax-curve-getdistatparam ent idx)
                         (vlax-curve-getdistatparam ent (1- idx))))
            (setq step (/ len (fix (+ (/ len mstep) 0.99))))
            (setq cnt (fix (+ (/ len step) 0.99)))
            (setq dist (+ step (vlax-curve-getdistatparam ent (1- idx))))
            (repeat cnt
              (command "-insert" "paal" "_non" (vlax-curve-getpointatdist ent dist) "1" "" "")
              (setq dist (+ dist step))
            )
          )
          (setvar "clayer" clay)
          (command "._Undo" "_end")
        )
        (prompt "\n***   ERROR - Can not divide that object.  ***")
      )
      (princ)
    )
    <edit: revised code>
    Last edited by CAB2k; 2007-05-22 at 01:56 PM.

  7. #7
    Member
    Join Date
    2007-05
    Posts
    38
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    Quote Originally Posted by CAB2k
    The DWG helped, thanks.
    Here is an example.
    That works like a charm!
    I cannot thank you enough This wil save me soooo many hours a month calculating distances and copying blocks.

    Now i can spend the rest of my evening figuring out what the routine is actually doing

  8. #8
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    Glad it worked for you.
    There is room for improvement in the lisp but it gets the job done.

    I'm sure the one from sinc would also work with some mods. He is a smart guy.

  9. #9
    Member
    Join Date
    2007-05
    Posts
    38
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    I will certainly look into that one as well, but your routine looks a bit easier to understand for me, since I'm just a beginner is LISP. Tonight I'm going to figure out what all the variables are actually doing

    thanks again, both of you, for helping me out.!

  10. #10
    Member
    Join Date
    2007-05
    Posts
    38
    Login to Give a bone
    0

    Default Re: Place a Block at points along a Polyline

    already making modifications

    Some of the polylines used are open, come are closed. I would also like a block to be at the beginning of an "open" polyline, but doing so for a closed polyline would create a "double" block at the start (=end) point of the polyline.
    Reading the lisp manual I stumbled upon "vlax-curve-isClosed", which checks if a given entity is closed. The code now looks like this (also changed layernames and mStep to my specific needs):

    Code:
    ;;  CAB  05.22.07
    ;;  Divide a dividable object based on segment length
    ;;  and max dist between blocks to be inserted
    ;;    -=<  NO ERROR CHECKING  >=-
    (defun c:DivideSegments () (c:DS))
    (defun c:DS (/ CNT DIST ENDPAR ENT IDX LEN MSTEP START STEP clay)
      (vl-load-com)
      (setq clay (getvar "clayer"))
      (if (and (setq ent (entsel "\nSelect object to divide."))
               (not (vl-catch-all-error-p
                      (setq start (vl-catch-all-apply
                                    'vlax-curve-getpointatparam
                                    (list (car ent) 0.0))))))
        (progn
          (command "._Undo" "_begin")
          (setvar "clayer" "staalkabel")  ; Block Layer
          (setq ent (car ent))
          (setq mStep 8000)
          (setq endpar (vlax-curve-getendparam ent))
          (setq idx 0)
          (while (<= (setq idx (1+ idx)) endpar)
            (setq len (- (vlax-curve-getdistatparam ent idx)
                         (vlax-curve-getdistatparam ent (1- idx))))
            (setq step (/ len (fix (+ (/ len mstep) 0.99))))
            (setq cnt (fix (+ (/ len step) 0.99)))
            (setq dist (+ step (vlax-curve-getdistatparam ent (1- idx))))
    
    	; avoid double blocks on closed polylines
    	(if (vlax-curve-isClosed ent) ; check if polyline is closed
    	  () ;if polyline is closed, do nothing
    	  (command "-insert" "paal" "_non" (vlax-curve-getpointatdist ent 0) "1" "" "") ;if polyline is open, insert block at beginning of polyline
    	) ;end if
    	
    	(repeat cnt
              (command "-insert" "paal" "_non" (vlax-curve-getpointatdist ent dist) "1" "" "")
              (setq dist (+ dist step))
            ) ;end repeat
          ) ; end while
          (setvar "clayer" clay)
          (command "._Undo" "_end")
        )
        (prompt "\n***   ERROR - Can not divide that object.  ***")
      ) ; end if
      (princ)
    )
    <edit: typo's>
    Last edited by wbreedveld; 2007-05-22 at 04:46 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. 2013: DRAWING A POLYLINE THAT ATTACHES BLOCK AT POINTS
    By CIngalsb397420 in forum AutoCAD General
    Replies: 3
    Last Post: 2013-07-08, 01:09 PM
  2. Replies: 0
    Last Post: 2011-10-11, 08:38 AM
  3. Replies: 2
    Last Post: 2007-03-28, 11:12 AM

Posting Permissions

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