Select the block take the value of the attribute and enter another attribute as FIELD

Select the block take the value of the attribute and enter another attribute as FIELD

Anonymous
Not applicable
1,579 Views
7 Replies
Message 1 of 8

Select the block take the value of the attribute and enter another attribute as FIELD

Anonymous
Not applicable

Select the block, take the attribute value and enter another attribute as FIELD

Does anyone have any sub-function or function that I select the BLOCK ask for the tag value and insert as field in another block.

example:

(setq ent (car (entsel "Select block_01")))
;; {get ATT1 tag attribute value} ;; I don't know how to do it
(setq set_ (car (entsel "Select block_02"))
;; {set the field value in the ATT4 tag} ;; I don't know how to do it

Explain to me how I can do it is already of great help !!!

0 Likes
Accepted solutions (1)
1,580 Views
7 Replies
Replies (7)
Message 2 of 8

ronjonp
Mentor
Mentor

Use NENTSEL to get the attributes. No error checking but here's a quick example.

 

(defun c:foo (/ ent ent2)
  ;; RJP » 2020-10-13
  (if (and (setq ent (car (nentsel "Select block_01")))
	   (setq ent2 (car (nentsel "Select block_02")))
      )
    (vla-put-textstring
      (vlax-ename->vla-object ent2)
      (strcat "%<\\AcObjProp Object(%<\\_ObjId "
	      (itoa (vla-get-objectid (vlax-ename->vla-object ent)))
	      " >%).TextString>%"
      )
    )
  )
  (princ)
)

 

*You might have to regen to see the result.

0 Likes
Message 3 of 8

pbejse
Mentor
Mentor

HYG

 

(defun c:NowYouKnow ( / ent ObjetID set_)
(if
  (and
    	;;	Select the Source Attribute	;;;
    	(setq ent (car (nentsel "Select block_01")))
	(setq ObjetID (itoa (vla-get-objectid (vlax-ename->vla-object ent))))
	;;;	Select the Target Attribute	;;;
	(setq set_ (car (nentsel "Select block_02")))
	)

 (vla-put-textstring (vlax-ename->vla-object set_)
                    (strcat
                        "%<\\AcObjProp Object(%<\\_ObjId "
                        ObjetID
                        ">%).TextString>%"
                    )
                )
  (princ)
	)
  )

 

HTH 

 

EDIT: Oops, too slow 🙂

 

0 Likes
Message 4 of 8

Anonymous
Not applicable

thanks @pbejse  and @ronjonp 
That's almost! but it would be to select the block (entsel) not the attribute (nentsel).

0 Likes
Message 5 of 8

ronjonp
Mentor
Mentor

@Anonymous wrote:

thanks @pbejse  and @ronjonp 
That's almost! but it would be to select the block (entsel) not the attribute (nentsel).


How do you choose what attribute to map it to? You have two blocks with 4 distinct tag names.

 

Does this little snippet shed any light?

(if (and (setq e (car (entsel)))
	 (vlax-property-available-p (vlax-ename->vla-object e) 'hasattributes)
    )
  (setq atts (vlax-invoke (vlax-ename->vla-object e) 'getattributes))
)
0 Likes
Message 6 of 8

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

thanks @pbejse  and @ronjonp 
That's almost! but it would be to select the block (entsel) not the attribute (nentsel).


Not sure if this is what you need

(defun c:NowYouKnow ( / GetSetValue mySourceTag myTargetTag source mySourceID TargetBlocks)
(defun GetSetValue (e od tg)
	       (Vl-some '(lambda (v)
			    (cond
			       ((and
				(setq f (eq (vla-get-tagstring v) tg) ) od)
			        (vla-put-textstring v
					    (strcat "%<\\AcObjProp Object(%<\\_ObjId "  od
		                        		">%).TextString>%")
	                    		) tg
				    )
			         ( f  (itoa (vla-get-objectid v))
					)
				      )
			    )
		    (Vlax-invoke e 'GetAttributes)
		 )
	)
		    
(setq mySourceTag "ATT1"
      myTargetTag "ATT4")
(if
  (and
    (princ "\nSelect source block")
    (setq source (ssget "_+.:S:E" '((0 . "INSERT")(66 . 1))))
    (setq mySourceID (GetSetValue (vlax-ename->vla-object (ssname source 0)) nil mySourceTag))
    (princ "\nSelect target block(s)")
    (Setq TargetBlocks 	(ssget "_:L" '((0 . "INSERT")(66 . 1))))
    )
  (repeat (setq i (sslength TargetBlocks))
    	(setq et (vlax-ename->vla-object (ssname TargetBlocks (setq i (1- i)))))
    	(GetSetValue et mySourceID myTargetTag)
    	(command "_updatefield" (ssname TargetBlocks i) "")
    )
  )
  (princ)
  )

 

You  get to select the source block, as long as it has the tag "ATT1" it will continue to prompt for target block(s)

If any of those selected has "ATT4" it will be processsed.

 

Message 7 of 8

Anonymous
Not applicable

@pbejse  that's right, thank you very much!

0 Likes
Message 8 of 8

pbejse
Mentor
Mentor

@Anonymous wrote:

@pbejse  that's right, thank you very much!


Good for you. 

Happy to help.

 

 

0 Likes