Author Topic: BlockAtVertices  (Read 1571 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
BlockAtVertices
« on: February 28, 2017, 05:26:56 AM »
Hi i am using BlockAtVertices.lsp. But i need to do 2 changes .
1) When i have a close polyline puts me 2 points in fist vertex because the fist and the last vertex are same. I want to have one block (only for the close polylines the first and the last vertex to have one block)

2)I use annotated attribute blocks. When this routine insert the points convert my blocks to a new block so i can not channge them.I want to insert them as attribute blocks

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;;-----------------=={ Block At Vertices }==------------------;;
  3. ;; ;;
  4. ;; Inserts a Block at each vertex of selected Polylines, ;;
  5. ;; rotated to the angle of the segment following the vertex. ;;
  6. ;;------------------------------------------------------------;;
  7. ;; Author: Lee McDonnell, 2010 ;;
  8. ;; ;;
  9. ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
  10. ;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
  11. ;;------------------------------------------------------------;;
  12.  
  13. (defun c:BlockAtVertices ( / *error* _StartUndo _EndUndo _Insert _AngleAtParam doc block ss )
  14. ;; © Lee Mac 2010
  15.  
  16. (setq block "AnnotPoint.dwg") ;; << Block Name
  17.  
  18. (defun *error* ( msg )
  19. (and doc (_EndUndo doc))
  20. (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  21. (princ (strcat "\n** Error: " msg " **")))
  22. )
  23.  
  24. (defun _StartUndo ( doc ) (_EndUndo doc)
  25. )
  26.  
  27. (defun _EndUndo ( doc )
  28. (if (= 8 (logand 8 (getvar 'UNDOCTL)))
  29. )
  30. )
  31.  
  32. (defun _Insert ( block point rotation )
  33. (cons 0 "INSERT")
  34. (cons 2 block)
  35. (cons 10 point)
  36. (cons 50 rotation)
  37. (cons 41 1.0) ;; X Scale
  38. (cons 42 1.0) ;; Y Scale
  39. (cons 43 1.0) ;; Z Scale
  40. )
  41. )
  42. )
  43.  
  44. (defun _AngleatParam ( entity param )
  45. (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv entity param))
  46. )
  47.  
  48.  
  49. ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER))))))
  50.  
  51. (princ "\n** Current Layer Locked **")
  52. )
  53. ( (not
  54. (and (tblsearch "BLOCK" (vl-filename-base block))
  55. (setq block (vl-filename-base block))
  56. )
  57. (setq block
  58. (strcat block
  59. (if (eq "" (vl-filename-extension block)) ".dwg" "")
  60. )
  61. )
  62. )
  63. (
  64. (lambda ( / ocm )
  65. (setq ocm (getvar 'CMDECHO)) (setvar 'CMDECHO 0)
  66. (command "_.-insert" block) (command)
  67. (setvar 'CMDECHO ocm)
  68.  
  69. (tblsearch "BLOCK" (setq block (vl-filename-base block)))
  70. )
  71. )
  72. )
  73. )
  74. )
  75.  
  76. (princ "\n** Block not Found **")
  77. )
  78. ( (not (setq ss (ssget '((0 . "*POLYLINE")))))
  79.  
  80. (princ "\n*Cancel*")
  81. )
  82. (t
  83.  
  84. (_StartUndo doc)
  85.  
  86. (
  87. (lambda ( i / e )
  88. (while (setq e (ssname ss (setq i (1+ i))))
  89. (
  90. (lambda ( param end )
  91. (while (<= (setq param (1+ param)) end)
  92. (_Insert block (vlax-curve-getPointatParam e param) (_AngleAtParam e param))
  93. )
  94. )
  95. )
  96. )
  97. )
  98. -1
  99. )
  100.  
  101. (_EndUndo doc)
  102. )
  103. )
  104.  
  105. )
  106.  
  107.  

ronjonp

  • Needs a day job
  • Posts: 7531
Re: BlockAtVertices
« Reply #1 on: February 28, 2017, 08:54:59 AM »
If you don't want it to insert 2 blocks at start and end point, you could use something like this to check if the objects is closed.
Code - Auto/Visual Lisp: [Select]
  1. (defun _fuzzyclosed (ename fuzz)
  2. )
Then iterate (1- (vlax-curve-getendparam e)) if the object is closed.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: BlockAtVertices
« Reply #2 on: February 28, 2017, 09:21:06 AM »
Is it possible to understand the overlap polylines and not insert blocks in the same points ?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: BlockAtVertices
« Reply #3 on: February 28, 2017, 09:41:35 AM »
Just maintain a list of processed points .. if it's in the list skip else place the block.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: BlockAtVertices
« Reply #4 on: February 28, 2017, 01:28:32 PM »
Just maintain a list of processed points ..

Here are 2 similair iterative suggestions:

Code: [Select]
; Unique point list - iterative
(defun UqpL ( fuzz pL / L p )
  (while pL
    (setq p (car pL))
    (if (or (null L) (not (vl-some '(lambda (x) (equal x p fuzz)) L))) (setq L (cons p L)) )
    (setq pL (cdr pL))
  ); while
  (reverse L)
); defun UqpL

; Unique point list - iterative
(defun UqpL ( fuzz pL / L p )
  (while pL
    (setq p (car pL))
    (or (vl-some '(lambda (x) (equal x p fuzz)) (cdr pL)) (setq L (cons p L)) )
    (setq pL (cdr pL))
  ); while
  (reverse L)
); defun UqpL

I also tried recursively, but was not successful - since It requires building and checking the new list at the same time  :uglystupid2:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: BlockAtVertices
« Reply #5 on: February 28, 2017, 01:36:40 PM »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: BlockAtVertices
« Reply #6 on: February 28, 2017, 02:09:47 PM »
Others: http://lee-mac.com/uniqueduplicate.html
Nice Lee,
I've forgot that you had these (I only and always used the LM:Unique).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7531
Re: BlockAtVertices
« Reply #7 on: February 28, 2017, 02:44:36 PM »
Another offering:
Code - Auto/Visual Lisp: [Select]
  1. (defun uqpl1 (pl fuzz / l p)
  2.   (while (setq p (car pl))
  3.     (setq pl (vl-remove-if (function (lambda (x) (equal x p fuzz))) pl))
  4.     (setq l (cons p l))
  5.   )
  6.   (reverse l)
  7. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC