Jump to content

Get the value of a specific TAG from an attributed block and place in to another


Recommended Posts

Posted (edited)

Dear Users

I want to get the value of a specific TAG from an attributed block and place in to another specific TAG in a different block.

 

The following is the scripts I had made which is incomplete. I failed to get the value from the TAGS.

Please have a look and help me.

I had attached the attributed blocks which I want to use.

 

 

(defun c:SLD()
(setq osm (getvar "osmode"))
(setvar "osmode" 0)

(setq CP1 (getpoint "\nStart Point: "))
(setq CP2 (getpoint "\nEnd Point: "))

(setq eq1 (entsel "\nSelect first equipment: "))
(setq eqname1  (cdr (assoc 2 (entget (car eq1))))) filter the block name

; NEED THE FUNCTION.... get the attribute tag value of ETAG of the block eqname1


(setq eq2 (entsel "\nSelect second equipment: "))
(setq eqname2  (cdr (assoc 2 (entget (car eq2))))) filter the block name

; NEED THE FUNCTION.... get the attribute tag value of ETAG of the block eqname2

(command "line" CP1 CP2 "")
(setq CP3 (polar CP1 (angle CP1 CP2) (/ (distance CP1 CP2) 2)))

(command "_insert" "d:/stdBlk/Dyn/CTAG.dwg" CP3 1 1 "") ; insert the block 


; NEEDED FUNCTION.... need to replace the tag FROM & TO of the inserted block CTAG.dwg from the data retrieved 
; NEEDED FUNCTION.... from the tag ETAG of eqname1 & eqname2 


(SETVAR "OSMODE" OSM)
)

 

 

Thanks

CTAG.dwg

LIGHT 2x18.dwg

Edited by SLW210
Added Code Tags!
Posted

Try this UNTESTED codes and be careful to select the attribute in the block itself .

 

(defun c:CopyAtts (/ s ss)
 (if
   (and (setq
          s (car
              (nentsel "\n Select the Attribute value in First Block :")
            )
        )
        (if (eq (cdr (assoc 0 (entget s))) "ATTRIB")
          T
          (progn (princ "\n Missed the Attribute !") nil)
        )
        (setq ss
               (car
                 (nentsel "\n Select the Attribute value in Second Block :")
               )
        )
        (if (eq (cdr (assoc 0 (entget ss))) "ATTRIB")
          T
          (progn (princ "\n Missed the Attribute !") nil)
        )
   )
    (entmod (subst (assoc 1 (entget s))
                   (assoc 1 (entget ss))
                   (entget ss)
            )
    )
 )
 (command "_.regenall")
 (princ)
)

Posted

The programme is working fine. But what I am looking to is to get the value of a specific TAG and to replace on a TAG which is hidden on a block.

 

In the CTAG.dwg, you can find two TAGS which is FROM and TO.

 

The block will be inserted in such a way that

 

LIGHT 2x18.dwg‎ CTAG.dwg LIGHT 2x18.dwg‎ .... (may be other blocks instead of LIGHT 2x18.dwg‎) but the tag name ETAG remains the same.

 

I want to get the ETAG information of the tag in LIGHT 2x18.dwg‎ and place on the FROM value of CTAG.dwg

 

and get the ETAG information of the tag in 2nd LIGHT 2x18.dwg‎ and place on the TO value of CTAG.dwg

 

Can you please work out for the same and help me.

 

Thanks & Regards

Shyhas

 

 

Try this UNTESTED codes and be careful to select the attribute in the block itself .

 

(defun c:CopyAtts (/ s ss)
 (if
   (and (setq
          s (car
              (nentsel "\n Select the Attribute value in First Block :")
            )
        )
        (if (eq (cdr (assoc 0 (entget s))) "ATTRIB")
          T
          (progn (princ "\n Missed the Attribute !") nil)
        )
        (setq ss
               (car
                 (nentsel "\n Select the Attribute value in Second Block :")
               )
        )
        (if (eq (cdr (assoc 0 (entget ss))) "ATTRIB")
          T
          (progn (princ "\n Missed the Attribute !") nil)
        )
   )
    (entmod (subst (assoc 1 (entget s))
                   (assoc 1 (entget ss))
                   (entget ss)
            )
    )
 )
 (command "_.regenall")
 (princ)
)

Posted

Is the line created form cp1 and cp2 variable really necessary? or is it just a reference for CTAG insertion point?

Posted (edited)

output.jpgHello

The CP1 & CP2 are used to draw a line between 1st and 2nd equipment, also to get the insertion point of the block CTAG.

 

Instead of this CP1 & CP2 we can add a dynamic object in the CTAG Block.

 

Please see the attachment which will show you the final stage of the drawing. The Hidden attribute values are to create a table of connections & equipment.

 

Thanks & regards

shyhas

Edited by shyhas
Missing Attachment
Posted (edited)

So what value would go to CTAG tag, [one thats not invisible] the block / etag name of first selected or the second one?

 

What is the need for this ?

 

(setq eqname1 (cdr (assoc 2 (entget (car eq1)))))

 

Anyhoo....

(defun c:SLD ( / *error* _attfunc cp1 cp2 eqv1 data cp3 e)
(defun *error* (msg)  (command "._undo" "_end")
   (setvar 'osmode old_os)(setvar 'attreq old_atr)
   (setvar 'cmdecho 1)
 )
(defun _AttFunc	(en lst / vals v)
(mapcar (function
   (lambda (at)
     (setq vals (list (vla-get-tagstring at) (vla-get-textstring at)))
     (if (and lst (setq v (assoc (car vals) lst)))
(vla-put-textstring at (cadr v))
     )
     vals
   )
 )
 (vlax-invoke
   (if	(eq (type en) 'VLA-OBJECT)
     en
     (vlax-ename->vla-object en)
   )
   'Getattributes
 )
)
)
(setq ff nil  old_os (getvar 'osmode) old_atr (getvar 'Attreq))
     (setvar 'osmode 0)(setvar 'Attreq 0)(setvar 'cmdecho 0)
     (command "._undo" "_begin")
     
(if (and
       (or (tblsearch "Block" "Ctag")
       (setq ff (findfile "d:/stdBlk/Dyn/CTAG.dwg")))   
       (setq CP1 (getpoint "\nStart Point: "))
(setq CP2 (getpoint cp1 "\nEnd Point: "))
   	(setq data
(mapcar (function (lambda (itm)
  	(while itm
        	(if (and
                   (setq e (Car (entsel (Strcat "\nSelect " itm " equipment: "))))
                   (vlax-method-applicable-p (setq e (vlax-ename->vla-object e))  'GetAttributes)
                   (setq val (assoc "ETAG" (_attfunc e  nil))))
                 (setq itm nil)
                 (prompt "\nAttribute not found:")))
(if val (Cadr val)))) '("First" "Second")))
   	)
   (progn
         (command "line" CP1 CP2 "")
  (setq CP3 (polar CP1 (angle CP1 CP2) (/ (distance CP1 CP2) 2)))
  (command "_insert" (if ff ff "CTAG")  CP3 1 1 (/ (* (angle cp1 cp2) 180.0) pi) ) ; insert the block
(_attfunc
      (entlast)
      (list
            (list "CTAG" "Equipment Tag Value");<-- whatever that is
            (list "FROM" (car data))
            (list "TO" (cadr data))
            ))
)
   )
(princ)
)

Edited by pBe
Posted

Hello

The ETAG value of the first block goes to tag FROM value of CTAG and ETAG value of the second block goes to tag TO value of CTAG.

 

I tried the routine you had posted, but it stops after the selection of first object

 

Please reply

Thank you

Posted

That's odd, the way it was written it shouldn't just "stop" if the selection is not valid but instead prompt you again to select a valid object.

 

What is the error message if there's any?

Posted

Dear Friends

 

with all your help I managed to reach till inserting the block.

 

I have the data for FROM & TO

and I am not place it to the relevant TAG in the block CTAG

 

Pleaseeee help me for the same. :)

 

The data to paste in tag FROM of CTAG is eqname1

 

and

 

the data to paste in tag TO of CTAG is eqname2

 

 

(defun c:SLD ()

 

(setq osm (getvar "osmode"))

 

(setvar "osmode" 18)

 

(setq eq1 (nentsel "\nSelect first equipment Tag: ")) ; select the first equipment tag

(setq eqname1 (cdr (assoc 1 (entget (car eq1))))) ; need to get the tage name of first equipment

 

(setq eq2 (nentsel "\nSelect next equipment Tag: ")) ; select the second equipment tag

(setq eqname2 (cdr (assoc 1 (entget (car eq2))))) ; need to get the tag name of second equipment

 

(setq cp1 (getpoint "\nStart Point: ")) ; start point of the connector

 

(setq cp2 (getpoint "\nEnd Point: ")) ; end point of the connector

 

(command "line" cp1 cp2 "") ; drawing line between first & second equipment

 

 

(setq dist1 (distance cp1 cp2)) ; getting inesrtion point for cable tag

(setq ang (angle cp1 cp2))

(setq dist2 (polar cp1 ang (/ dist1 2)))

 

(command "_insert" "d:/stdBlk/Dyn/CTAG.dwg" dist2 "" "" "") ;inserting cable tag above cable

 

;; ****

 

(setvar "osmode" osm)

(princ)

 

)

 

 

 

 

shyhas,

 

Please read the Code posting guidelines and use Code Tags for your Code in the future.

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...