Jump to content

Dynamic properties based on attribute values


Recommended Posts

Posted

Hi all,

 

does anyone know of a lisp that would take all instances of a Dynamic block, read two attribute values and apply the values respectively to the dynamic property.

 

here is what I have to do....

 

I have a 100 blocks in a drawing with 2 attributes filled in.

 

I need to edit the block to include 2 more attributes and 2 dynamic stretch actions.

 

Using ATTOUT I can edit the new attributes using values in excel then import again with ATTIN

 

Once i have the values in the block I need to use these values to control the stretch actions.

 

Is this possible. I thought I might have some options using dimconstraints but without any luck.

 

I have no luck searching as I'm unsure exactly what I'm searching for

 

Any ideas?

 

thanks

Posted

any help on this one would be really appreciated.

 

thanks

Posted

The following code is what I have put together from my understanding (very limited of Visual lisp) through help from Alanjt amongst others.

 

Can anyone help me with fixing the code to do what I need? or point me to what I need to do.

I have a large number of dynamic blocks, with attributes filled in. I need to get these attribute values and use them for the dynamic property values to update the appearance of the block

 

I can get my selection set of dynamic blocks but then it falters thereafter and I do not know what I need to do.

 

 
;get seelection set from Ronjonp CAD tutor
(defun c:getblk    (/ e name n out ss x rjp-getblockname get-attribute1 get-attribute2 SetdynBlockRefPropertyValue1 SetdynBlockRefPropertyValue2)
 (defun rjp-getblockname (obj)
   (if    (vlax-property-available-p obj 'effectivename)
     (vla-get-effectivename obj)
     (vla-get-name obj)
   )
 )
 (if (setq x     (ssget '((0 . "INSERT")))
       x     (ssname x 0)
       name (rjp-getblockname (vlax-ename->vla-object x))
       ss     (ssget "_X" '((0 . "INSERT")))
       n     -1
       out     (ssadd)
     )
   (while (setq e (ssname ss (setq n (1+ n))))
     (if (= (rjp-getblockname (vlax-ename->vla-object e)) name)
   (ssadd e out)
     )
   )
 )
 (sssetfirst nil out)
 (princ)
)
;idea from Alanjt  (vlax-get <VLA-Object> 'GetAttributes)

;from martti.halminen  Autodesk forums
;get first att value
(defun get-attribute1 (obj breite / value1)
 ;; returns the value of the textstring property of the attribute reference
 (foreach a (vlax-invoke obj 'getattributes)
   (if (= (vlax-get a 'TagString) Anschlusswert)
       (setq value1 (vlax-get a 'textString))))
 value)
;get second att value
(defun get-attribute2 (obj länge / value2)
 ;; returns the value of the textstring property of the attribute reference
 (foreach a (vlax-invoke obj 'getattributes)
   (if (= (vlax-get a 'TagString) Rohenergie)
       (setq value2 (vlax-get a 'textString))))
 value)

;idea from Alanjt (vla-GetDynamicBlockProperties <VLA-Object>)
; Set the vlaue of a single dynamic block property object by name
(defun SetDynBlockRefPropertyValue1 (DynBlockRef Name Value1 / Anschlusswert)
(if (setq property (GetDynBlockRefProperty DynBlockref Name))
(progn
(vlax-put-property property 'Value NewValue)
(vlax-release-object Property)
)
)
)

(defun SetDynBlockRefPropertyValue2 (DynBlockRef Name Value2 / Rohenergie)
(if (setq property (GetDynBlockRefProperty DynBlockref Name))
(progn
(vlax-put-property property 'Value NewValue)
(vlax-release-object Property)
)
)
)

 

If anyone needs to see the drawing I can email it to them to see exactly what it is i am trying to do.

 

thanks

Posted

Hi

 

Not tested heavily but maybe somthing like this may be of help

 

 

(defun c:test ( / dynPropertyList tempSelectionSet i blkObject item attObjList newValue parmName dynmBlksList)

 ;>>Change dynPropertyList to suit, based on dynamic block properties
 ;1st item = Attribute Tag    2nd item = Corresponding Distance Label (Unique name)
 ;((attribute_Tag_01 . distance_label_name_01) (attribute_Tag_02 . distance_label_name_02)....)

 (setq dynPropertyList
 '(("LENGTH" . "Distance01")
   ("HEIGHT" . "Distance02")
  )
)
 
 (if

   (setq tempSelectionSet (ssget '((0 . "Insert"))))

   (progn

     (setq i 0)
     
     (repeat
(sslength tempSelectionSet)

(setq blkObject (vlax-ename->vla-object (ssname tempSelectionSet i))
      i (1+ i))
(if
  (and
    (= (vla-get-HasAttributes blkObject) :vlax-true)
    (= ( vla-get-IsDynamicBlock blkObject) :vlax-true)
    )
  
  (progn
    (setq attObjList (vlax-safearray->list (vlax-variant-value (vla-getattributes blkObject))))

    (foreach <att> attObjList

      (if
	(setq item (assoc (vla-get-TagString <att>) dynPropertyList))
	(progn
	  (setq newValue     (atof (vla-get-TextString <att>))
		parmName     (cdr item)
		dynmBlksList (vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties blkObject))))

	  (foreach <dyn> dynmBlksList

	    (if
	      (= parmName (vla-get-PropertyName <dyn>))
	      (vla-put-Value <dyn> newValue))
	    ))))))))))

Posted

Hi,

 

that was a quick response. hope all is well in the emerald isle.

 

it returns nil at the command line but unfortunately does not change the dynamic properties.

Posted
hope all is well in the emerald isle.

 

 

Its a bit wet outside but can't complain!

 

It returns nil at the command line but unfortunately does not change the dynamic properties.

 

Could you post a simplified version of the block? The particular information of interest would be attribute tag names & the corresponding dynamic paramater names

Posted (edited)

Jammie,

 

It works a treat......thank you so much.

 

After I dumbed the block down I had forgotten to do an attsync.

man oh man!

 

you deserve a pint for that one!

Edited by feargt
slight oversight

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