Author Topic: Naming LWPOLY Lines  (Read 3663 times)

0 Members and 1 Guest are viewing this topic.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Naming LWPOLY Lines
« on: June 19, 2016, 01:27:31 PM »
Anyone ever try using the DXF 310 value to name a LWPOLYLINE object.  I would like to try it to be able to quickly retrieve the vertex point coordinates of that particular LWPolyline.

Pros /Cons


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Naming LWPOLY Lines
« Reply #1 on: June 19, 2016, 02:03:19 PM »
Not knowing your exact need ... have you looked into exploiting groups? ... saving the handles of entities in dictionaries ... etc?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Naming LWPOLY Lines
« Reply #2 on: June 19, 2016, 02:14:56 PM »
Not knowing your exact need ... have you looked into exploiting groups? ... saving the handles of entities in dictionaries ... etc?

MP,

Thanks for the input, I need to be able to retrieve the vertex information in subsequent editing sessions (after exiting Cad etc.) so as far as I know the groups method is out.  In this application the LWPOLYLINE is within a block, and there could be multiple similar blocks (not copies of the same one) in a single drawing, so I am leary of using the dictionary option in this case.  I do use dictionaries extensively for other purposes, I have over a hundred values etc stored in custom dictionaries in each drawing. The other option I was thinking about was creating an invisible attribute while creating the block to store the entity name.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Naming LWPOLY Lines
« Reply #3 on: June 19, 2016, 03:31:32 PM »
If the entities of interest weren't nested in blocks groups could work session to session. That said, you would still need some means to store the group name (or use a consistently named group). As the entities are nested within blocks you either have to record the handles in a dictionary (what I'd likely do) or flag the entities via xdata or an extension dictionary. Recording the handles in a dictionary would realize faster retrieval after the fact, as you wouldn't have to iterate block definitions looking for flagged entities. I personally would not go the route of an attribute; too easily abused and/or revealed, invisible or not. Don't know if this was coherent, I've a smashing headache today. fwiw cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Naming LWPOLY Lines
« Reply #4 on: June 19, 2016, 03:57:19 PM »
with gc 310 aren't you restricted to hex values?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Naming LWPOLY Lines
« Reply #5 on: June 19, 2016, 04:08:21 PM »
70 72 6F 62 6C 65 6D 3F
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Naming LWPOLY Lines
« Reply #6 on: June 19, 2016, 07:28:21 PM »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Naming LWPOLY Lines
« Reply #7 on: June 19, 2016, 10:59:58 PM »
 :whistling:  :2funny:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Naming LWPOLY Lines
« Reply #8 on: June 20, 2016, 12:17:20 AM »

I usually name mine after Homers characters. The Greek is conducive to some excellent puns.
 
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Naming LWPOLY Lines
« Reply #9 on: June 20, 2016, 12:44:32 AM »
Not a pun but 'Hector the vector' quickly springs to mind for some reason.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Naming LWPOLY Lines
« Reply #10 on: June 20, 2016, 03:27:45 AM »
70 72 6F 62 6C 65 6D 3F
Since the OP doesn't refer to hex values I was wondering if gc 310 will accept any string. Note: BricsCAD does not allow gc 310 values for 'standard' graphical entities.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Naming LWPOLY Lines
« Reply #11 on: June 20, 2016, 07:04:02 AM »
I haven't attempted this yet, just in reviewing the acad docs, thought that 310 was a usable gc that one could use for an LWPolyline ent. value.  I will attempt others also to find one that works in both AC & BC.  I am looking to store a string, but if needs to be converted to hex. thats would work also.  MP thanks for the ideas, I'm with you on the attributes, much to easy for the curious user to mess with.

I'll try using the gc 102 series of codes and see what happens, I know (if successful) that it would work in Bricscad as well, a requite detail.

I'll post the results back here.
« Last Edit: June 20, 2016, 07:37:10 AM by snownut2 »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Naming LWPOLY Lines
« Reply #12 on: June 20, 2016, 07:53:37 AM »
Personally, I would opt to store handles as MP has suggested above - handles are already a unique 'name' for every entity in a drawing.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Naming LWPOLY Lines
« Reply #13 on: June 20, 2016, 08:53:58 AM »
I haven't attempted this yet, just in reviewing the acad docs, thought that 310 was a usable gc that one could use for an LWPolyline ent. value.  I will attempt others also to find one that works in both AC & BC.  I am looking to store a string, but if needs to be converted to hex. thats would work also.  MP thanks for the ideas, I'm with you on the attributes, much to easy for the curious user to mess with.

I'll try using the gc 102 series of codes and see what happens, I know (if successful) that it would work in Bricscad as well, a requite detail.

I'll post the results back here.

Just to be clear -- those hex values were anted up in jest -- I would not use 310 data for the need you've floated herein -- period.

... record the handles in a dictionary ...

For the performance and the effort this is your best bet.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Naming LWPOLY Lines
« Reply #14 on: June 20, 2016, 09:29:12 AM »

-- those hex values were anted up in jest -- I would not use 310 data for the need you've floated herein -- period.


No problems.. thanks for input, I'll look at the handles in dict.


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 »