Jump to content

Object Data (OD) attributes to Block attributes


mpozauko

Recommended Posts

Hey guys.

I wonder if anyone can help me with my situation. I am using AC Map 2008 and i have 3D plines each one defined with some OD Attributes. What i would like to do is to put some text from OD into block attributes and then insert that block on start of the pline.

 

I already use LeeMacs lisp to insert block but then i have to first use ATTSYNC command and manualy fill in block attributes with the data from OD. Lisp i use:

 

;;-------------------=={ Block At Ends }==--------------------;;
;;                                                            ;;
;;  Inserts a Block at each endpoint of a polyline            ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;

(defun c:BlockAtEnds ( / *error* _StartUndo _EndUndo _Insert _AngleAtParam doc block ss )
 (vl-load-com)
 ;; © Lee Mac 2010

 (setq block "profilD_fi110_fi50_fi40.dwg") ;; << Block Name

 (defun *error* ( msg )
   (and doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 (defun _Insert ( block point rotation )
   (entmakex
     (list
       (cons 0 "INSERT")
       (cons 2  block)
       (cons 10 point)
       (cons 50 rotation)
     )
   )
 )

 (defun _AngleatParam ( entity param )
   (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv entity param))
 )       

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (cond
   ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER))))))

     (princ "\n** Current Layer Locked **")
   )
   ( (not
       (or
         (and (tblsearch "BLOCK" (vl-filename-base block))
           (setq block (vl-filename-base block))
         )
         (and
           (setq block
             (findfile
               (strcat block
                 (if (eq "" (vl-filename-extension block)) ".dwg" "")
               )
             )
           )
           (
             (lambda ( / ocm )
               (setq ocm (getvar 'CMDECHO)) (setvar 'CMDECHO 0)
               (command "_.-insert" block) (command)
               (setvar 'CMDECHO ocm)
               
               (tblsearch "BLOCK" (setq block (vl-filename-base block)))
             )
           )
         )
       )
     )

     (princ "\n** Block not Found **")
   )
   ( (not (setq ss (ssget '((0 . "*POLYLINE")))))

     (princ "\n*Cancel*")
   )
   (t

     (_StartUndo doc)
    
     (
       (lambda ( i / e )
         (while (setq e (ssname ss (setq i (1+ i))))
           (foreach param (list (vlax-curve-getStartParam e) )
             (_Insert block (vlax-curve-getPointatParam e param) (_AngleAtParam e param))             
           )
         )
       )
       -1
     )

     (_EndUndo doc)
   )
 )

 (princ)
)

 

Block "profilD_fi110_fi50_fi40.dwg" has 3 tags FI110, FI50, FI40 which i would like to fill with text from OD with FI110, FI50, FI40 OD Field names. These fields are filled with letter "o" that represents number of pipes with defined diameter.

So basically i would fill in number of pipes for all 3dPlines (sections of pipeline) in OD Fields and when i would use lisp routine it would place blocks with correct attributes from OD on the start of the section (3dPline).

 

I attached DWG drawing "test.dwg" with containing block and some sections of pipeline filled with number of pipes in OD Fields. I also attached one picture of OD Table structure.

 

Hope i was clear enough.

test.dwg

OD_table.JPG

Link to comment
Share on other sites

  • 11 years later...
9 hours ago, Dien nguyen said:

I have the same problem but copy block attribute value to object data, please help!

 

image.png.bdb29f9c84b533522609a2e81dd22bab.png

att.dwg 950.25 kB · 1 download

With your exemple, this can do the job

(defun c:att2OD ( / ss n ent obj)
  (vl-load-com)
  (setq ss
    (ssget
      '(
        (0 . "INSERT") (66 . 1) (2 . "K-D-PARCEL")
      )
    )
  )
  (cond
    (ss
      (repeat (setq n (sslength ss))
        (setq obj (vlax-ename->vla-object (setq ent (ssname ss (setq n (1- n))))))
          (mapcar 
            '(lambda (att)
              (if (eq (vlax-get att 'TagString) "level1")
                (ade_odsetfield ent "def" "level" 0 (atof (vlax-get att 'TextString)))
              )
            )
            (vlax-invoke obj 'GetAttributes)
          )
      )
    )
  )
  (prin1)
)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...