Author Topic: AEC_PolyGon, AEC_Space, LTPOLYLINE vertices.  (Read 1763 times)

0 Members and 1 Guest are viewing this topic.

mhutchinson

  • Guest
AEC_PolyGon, AEC_Space, LTPOLYLINE vertices.
« on: April 21, 2014, 01:38:20 PM »
Keith Brown suggested I post here...
 
Code below works to get the vertices of AEC_PolyGon, AEC_Space, or LTPOLYLINE vertices.
I have a move function to adjust the vertices to the right coordinates for AEC_PolyGon and AEC_Space... however, I don't have a rotate function.
could someone set give me a leg up?
Maybe there's a better method too - I know move function is probably the long way around?

Code - Auto/Visual Lisp: [Select]
  1. (defun MEPObjVertices (/ Obj Vla-Obj ObjType Vla-BasePro IsPoly BasePnt BaseProfile coords Rotation xylist)
  2.         (setq Obj (car (entsel "\nSelect an AEC_PolyGon, AEC_Space, or a LTPolyline: ")))
  3.         (setq Vla-Obj (vlax-ename->vla-object Obj))
  4.         (setq ObjType (cdr (assoc '0 (entget Obj))))
  5.         (setq Vla-BasePro (cond ((wcmatch ObjType "AEC_POLYGON")
  6.                                                 (vlax-get-property Vla-Obj 'Profile)
  7.                                                 )
  8.                                                 ((wcmatch ObjType "AEC_SPACE")
  9.                                                 (vlax-get-property Vla-Obj 'BaseProfile)
  10.                                                 )
  11.                                                 ((setq IsPoly (wcmatch ObjType "LWPOLYLINE"))
  12.                                                 (vlax-get-property Vla-Obj 'Coordinates)
  13.                                                 )
  14.                         )
  15.         )
  16.         (if     (not IsPoly)
  17.                 (setq   Vla-Base (vlax-get-property Vla-Obj 'Location)
  18.                          BasePnt (vlax-safearray->list (vlax-variant-value Vla-Base))
  19.                           coords (vlax-get-property Vla-BasePro 'Coordinates)
  20.                           coords (vlax-safearray->list (vlax-variant-value coords))
  21.                         Rotation (vlax-get-property Vla-Obj 'Rotation)
  22.                 )
  23.                 (setq coords    (vlax-safearray->list (vlax-variant-value Vla-BasePro)))
  24.         )      
  25.         (setq xylist (lst2lists coords 2))
  26.         (if (not IsPoly)(setq xylist (move (list 0 0) BasePnt xylist)))
  27.         (setq xylist (LM:UniqueFuzz xylist 0.09))
  28.         xylist
  29. ):
  30. : thanks from http://www.lee-mac.com/uniqueduplicate.html to eliminate nearly coincident vertices.
  31. ;
  32. (defun LM:UniqueFuzz ( l f / x r )
  33.     (while l
  34.         (setq x (car l)
  35.               l (vl-remove-if (function (lambda ( y ) (equal x y f))) (cdr l))
  36.               r (cons x r)
  37.         )
  38.     )
  39.     (reverse r)
  40. )
  41. (defun move (FROMPNT TOPNT PNTLIST / DIST)
  42.   (setq PNTLIST (reverse PNTLIST))
  43.   (setq DIST (distance FROMPNT TOPNT))
  44.   (reverse (mapcar '(lambda     (X)
  45.                                                 (polar X (angle FROMPNT TOPNT) DIST)
  46.                                         )
  47.                                  PNTLIST
  48.                  )
  49.         )
  50. )
  51. (defun lst2lists (LST     ; LiST to DIVide into list of lists
  52.                   DIV /   ; integer qnt of elements to put in each list
  53.                   INC     ; INCrement
  54.               LSTPART     ; LiST PART length of which = DIV
  55.                RETLST)    ; the RETurned LiST of lists
  56.   (setq INC 0)
  57.   (while (setq LSTPART (sublst LST INC DIV))
  58.      (setq RETLST (cons LSTPART RETLST)
  59.               INC (+ INC DIV))
  60.   )
  61.   (reverse RETLST)
  62. )
  63. (defun sublst (LST     ; LiST to operate on
  64.                  N     ; "N"th atom to start with - 0 being the first one
  65.              NUM /     ; NUMber of atoms to get in sequence
  66.                 L)     ; sub List
  67.     (if (and NUM (< (+ N NUM)(length LST)))  
  68.       (repeat NUM
  69.          (setq L (cons (nth N LST) L) N (1+ N)))
  70.       (repeat (- (length LST) N)
  71.          (setq L (cons (nth N LST) L) N (1+ N)))
  72.     )
  73.   (setq L (reverse L))
  74. )
  75. ; go is a check function so long as 'pnts' var stores the vertices
  76. ;
  77. (defun c:go ()
  78.         (command "pline" (car pnts))
  79.         (setq newpnts (cdr pnts))
  80.         (foreach pnt newpnts
  81.                 (command pnt)
  82.         )
  83.         (command)
  84. )
  85.  
« Last Edit: April 21, 2014, 01:41:25 PM by mhutchinson »