Author Topic: Naming LWPOLY Lines  (Read 3662 times)

0 Members and 1 Guest are viewing this topic.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Naming LWPOLY Lines
« Reply #15 on: June 22, 2016, 03:24:13 PM »
Ok hit a snag, I thought I had read that handle names change once a block is created for the entities within the block, well it is true.  So.. is there a way of tracking what the new handle names are, or is it necessary to find the handle after block creation by comparing the vertex's?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Naming LWPOLY Lines
« Reply #16 on: June 22, 2016, 05:06:28 PM »
If you create objects in the block using the copyobjects method, the order of the new objects should match the order of source objects as they appear in the array or list. Translating 'old' handles to 'new' handles should therefore be possible.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Naming LWPOLY Lines
« Reply #17 on: June 22, 2016, 05:50:03 PM »
Thanks Roy, I'm creating the entities with entmake, so the last LWPOLYLINE entity made will be the last LWPOLYLINE listed in the block def.  I'll try that, it will not be hard to entmake the one I need to track last.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Naming LWPOLY Lines
« Reply #18 on: June 23, 2016, 01:53:05 PM »
Ok, here's what I've cobbled together so far, many thanks to the functions available on LeeMac's site.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.         ;=========================  Begin < Mk-Pt-Lst >  Function  =============================;
  3.         ;       Function to retrieve vertex point data from Pline in the listed block           ;
  4.         ;               The Pline handle name is stored in the SADATA_DICT                      ;
  5.         ;        Syntax for function call;                                                      ;
  6.         ;                               (Mk-Pt-Lst < Block Name >)                              ;
  7.         ;        Example - (Mk-Pt-Lst "Septic AssistantESStandard6x35Level")                    ;
  8.         ;                                                                                       ;
  9.         ;                                                                                       ;
  10.  
  11. (defun Mk-Pt-Lst ( blk /  a  i  e  q  LM:RotateByMatrix  Mk-PL-EntLst  ent-lst  pnt-lst
  12.                                                  LM:TranslateByMatrix  LM:ApplyMatrixTransformation  )(vl-load-com)
  13.  
  14.   (defun Mk-PL-EntLst ( blk / ss lst)
  15.     (if (and (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blk))))
  16.              (setq ss (cdr (assoc 2 (entget (ssname ss 0)))))
  17.              )
  18.       (progn
  19.         (vlax-for
  20.                   x
  21.                   (vla-item (vla-get-blocks
  22.                               (vla-get-ActiveDocument (vlax-get-acad-object))
  23.                               )
  24.                             ss
  25.                             )
  26.           (if (= (vla-get-objectname x) "AcDbPolyline")
  27.             (setq lst (cons (vlax-vla-object->ename x)  lst))
  28.             ) ;_  if
  29.           ) ;  vlax-for
  30.         )
  31.       )
  32.     );defun (setq ent-lst(Mk-PL-EntLst "Septic AssistantESStandard6x35Level"))
  33.  
  34.         ;========================== Begin < LM:mAssoc >  Function ==============================;
  35.         ;                                                                                       ;
  36.         ; Increments the value of a key in an association list if present,                      ;
  37.         ; else adds key to the list.                                                            ;
  38.         ; key - [any] Key of an element in the list                                             ;
  39.         ; lst - [lst] Association list (may be nil)                                             ;
  40.         ;                               mAssoc  -  Lee Mac                                      ;
  41.         ;               Returns all associations of a key in an association list                ;
  42.         ;                       http://www.lee-mac.com/assocplusplus.html                       ;
  43.         ;                                                                                       ;
  44.  
  45.   (defun LM:mAssoc ( key lst / itm)
  46.     (if (setq itm (assoc key lst))
  47.       (cons (cdr itm) (LM:mAssoc key (cdr (member itm lst))))
  48.       )
  49.     );defun
  50.  
  51.         ;                                                                                       ;
  52.         ;                                                                                       ;
  53.         ;=========================== End < LM:mAssoc > Function ================================;
  54.  
  55.  
  56.         ;;----------------=={ Translate by Matrix }==-----------------;;
  57.         ;;                                                            ;;
  58.         ;;  Translates a VLA-Object or Point List using a             ;;
  59.         ;;  Transformation Matrix                                     ;;
  60.         ;;------------------------------------------------------------;;
  61.         ;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
  62.         ;;------------------------------------------------------------;;
  63.         ;;  Arguments:                                                ;;
  64.         ;;  target - VLA-Object or Point List to transform            ;;
  65.         ;;  p1, p2 - Points representing vector by which to translate ;;
  66.         ;;------------------------------------------------------------;;
  67.  
  68.   (defun LM:TranslateByMatrix ( target p1 p2 )
  69.     (LM:ApplyMatrixTransformation target
  70.       (list
  71.         (list 1. 0. 0.)
  72.         (list 0. 1. 0.)
  73.         (list 0. 0. 1.)
  74.         )
  75.       (mapcar '- p2 p1)
  76.       )
  77.     )
  78.  
  79.         ;;------------------=={ Rotate by Matrix }==------------------;;
  80.         ;;                                                            ;;
  81.         ;;  Rotates a VLA-Object or Point List using a                ;;
  82.         ;;  Transformation Matrix                                     ;;
  83.         ;;------------------------------------------------------------;;
  84.         ;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
  85.         ;;------------------------------------------------------------;;
  86.         ;;  Arguments:                                                ;;
  87.         ;;  target - VLA-Object or Point List to transform            ;;
  88.         ;;  p1     - Base Point for Rotation Transformation           ;;
  89.         ;;  ang    - Angle through which to rotate object             ;;
  90.         ;;------------------------------------------------------------;;
  91.  
  92.   (defun LM:RotateByMatrix ( target p1 ang )
  93.     (LM:ApplyMatrixTransformation target
  94.       (setq m
  95.          (list
  96.            (list (cos ang) (- (sin ang)) 0.)
  97.            (list (sin ang)    (cos ang)  0.)
  98.            (list    0.           0.      1.)
  99.            )
  100.          )
  101.       (mapcar '- p1 (mxv m p1))
  102.       )
  103.     )  
  104.  
  105.         ;;-----------=={ Apply Matrix Transformation }==--------------;;
  106.         ;;                                                            ;;
  107.         ;;  Transforms a VLA-Object or Point List using a             ;;
  108.         ;;  Transformation Matrix                                     ;;
  109.         ;;------------------------------------------------------------;;
  110.         ;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
  111.         ;;------------------------------------------------------------;;
  112.         ;;  Arguments:                                                ;;
  113.         ;;  target - VLA-Object or Point List to Transform            ;;
  114.         ;;  matrix - 3x3 Matrix by which to Transform object          ;;
  115.         ;;  vector - 3D translation vector                            ;;
  116.         ;;------------------------------------------------------------;;
  117.  
  118.   (defun LM:ApplyMatrixTransformation ( target matrix vector )
  119.     (cond
  120.       ( (eq 'VLA-OBJECT (type target))
  121.  
  122.        (vla-TransformBy target
  123.          (vlax-tMatrix
  124.            (append (mapcar '(lambda ( x v ) (append x (list v))) matrix vector)
  125.              '((0. 0. 0. 1.))
  126.              )
  127.            )
  128.          )
  129.        )
  130.       ( (listp target)
  131.  
  132.        (mapcar
  133.          (function
  134.            (lambda ( point ) (mapcar '+ (mxv matrix point) vector))
  135.            )
  136.          target
  137.          )
  138.        )
  139.       )
  140.     )
  141.  
  142.         ;; Matrix x Vector - Vladimir Nesterovsky       ;;
  143.         ;; Args: m - nxn matrix, v - vector in R^n      ;;
  144.  
  145.   (defun mxv ( m v )
  146.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  147.     )
  148.  
  149.   (if (tblsearch "block" blk)
  150.     (progn
  151.       (setq i '(0 0 0)                                                                  ; insert point where block was created          ;
  152.             e (ssname (ssget "_X" (list '(0 . "INSERT") (cons 2 blk)))0)                ; block entity name                             ;
  153.             q (cdr(assoc 10(entget e)))                                                 ; insert point of block                         ;
  154.             a (cdr(assoc 50(entget e)))                                                 ; insert angle of block                         ;
  155.             ent-lst (reverse (Mk-PL-EntLst blk))                                        ; makes entity list of Plines in block          ;
  156.             pnt-lst (LM:mAssoc 10 (entget (last ent-lst)))                              ; list of verticies of last LWPOLYLINE created  ;
  157.             pnt-lst (LM:TranslateByMatrix pnt-lst (trans i 1 0) (trans q 1 0)))         ; Points translated to insert point of block    ;
  158.       (LM:RotateByMatrix pnt-lst (trans q 1 0) a)                                       ; points rotated to insert angle of block       ;
  159.     )
  160.     (progn
  161.       (alert (strcat "Block < " blk " > does not exist !"))
  162.       (exit)
  163.       )      
  164.     )    
  165.   );defun  (setq pt (Mk-Pt-Lst "Septic AssistantESStandard6x35Level"))
  166.  

This code will return a list of vertices from the LWPOLYLINE specified in a block, at the transformed coordinates, I usually construct my blocks at the origin, so that is my block creation point, just keeps things a lot simpler.
« Last Edit: June 23, 2016, 01:57:02 PM by snownut2 »