Jump to content
svorgodne

Obtain ObjID from a Flip Parameter inside a block

Recommended Posts

svorgodne

Hello everyone,

 

I have the next problem:

 

I have a dynamic "door block" which contains an attribute. (see attachment)

I want thru autolisp to assign the flip value to the attribute.

 

If I would do it manually, I can double click on the attribute, insert a field, choose the block itself and select the object type refering to the Flip Parameter, and get either "0" or "1". As you may have already noticed, I want to avoid that due to the ammount of doors I have in the project.

 

I already have the doors in the drawings that were coming from another office and it will take a lot of time to insert them again. I already know I could setup this behaviour in one block and just copy the door, but unfortunately, there are a lot of them in different drawings that it will take ages to do that and I have no time.

 

I thought on the other hand, making a program like the one that is linking a Polyline, Hatch or Region to an attribute inside a block. That is not a problem because the Objid from one of the first "area entities" is always reachable, right away. All I had to do in another lisp I developed, was to select both entities (Polyline and block) and connect them so it updates automatically if the hatch or polyline is modified.

 

(vla-put-textstring (vlax-ename->vla-object SYM_BlockEntityName)
 (cond
   (
     (= SYM_Units "Meters")
     ; m²
     (strcat
       "%<\\AcObjProp Object(%<\\_ObjId "
       SYM_ObjectID        ;<------------------------- I obtain the objid from the polyline
       ">%).Area \\f \""
       "%lu"
       "2" ; Format (Decimal)
       "%pr"
       "2" ;Precision
       "\">%"
     )
   )
   (
     (= SYM_Units "Centimeters")
     ; cm²--->m²
     (strcat
       "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
       SYM_ObjectID        ;<------------------------- or here if I want to convert cm² to m²
       ">%).Area \\f \""
       "%lu"
       "2" ; Format (Decimal)
       "%pr"
       "2" ;Precision
       "%ct8[0.0001]\">%"
     )
   )
 )
)

 

The problem is that I cannot reach the objid of the flip parameter within a block, because the objid I get when choosing the block, is always the objid from the block itself.

 

(setq SYM_Block (car (entsel)))
(setq SYM_ObjectID
 (itoa 
   (vla-get-ObjectID 
     (vlax-ename->vla-object 
       SYM_Block
     )
   )
 )
)

 

I would like THROUGH AUTOLISP, to iterate through all parameters inside the block until I find the correct objid flip parameter so I can add to my lisp program like this

 

(vla-put-textstring (vlax-ename->vla-object SYM_Ename)
 (strcat
   "%<\\AcObjProp Object(%<\\_ObjId "
   SYM_ObjectID        ;<------------------------- this should be the objid from the flip parameter inside a block
   ">%).Parameter(61).UpdatedFlip>%"
 )
)

 

If somebody has an idea how to iterate throuch entities inside the block until I find the right FLIP PARAMETER I need, I would very much appreciate your help, so I can pass the value to the attribute and it will change automatically when the door is flipped.

 

 

Thank you very much in advance

S

SampleFlipParameter.dwg

Share this post


Link to post
Share on other sites
rlx

can't test it because suddenly my block authoring pallet is empty (among other things) after latest IT update but maybe this can help you

 

 

http://forums.augi.com/archive/index.php/t-36347.html

 

 

(defun GetDynamicBlockPropertyList (objSelection / lstProperties)
(if (and (vlax-property-available-p objSelection "IsDynamicBlock")
         (= (vla-get-IsDynamicBlock objSelection) :vlax-true)
         (setq lstProperties (errortrap '(vlax-safearray->list 
                                          (variant-value 
                                           (vla-GetDynamicBlockProperties objSelection)
                                          )
                                         )
                            )
         )
    )
 (progn
  (mapcar '(lambda (x)(cons (vla-get-propertyname X)(variant-value (vla-get-value X)))) lstProperties)
 )
)
)
(defun GetDynamicBlockPropertyObjects (objSelection / lstProperties)
(if (and (vlax-property-available-p objSelection "IsDynamicBlock")
         (= (vla-get-IsDynamicBlock objSelection) :vlax-true)
         (setq lstProperties (errortrap '(vlax-safearray->list 
                                          (variant-value 
                                           (vla-GetDynamicBlockProperties objSelection)
                                          )
                                         )
                            )
         )
    )
 (progn
  (mapcar '(lambda (x)(cons (vla-get-propertyname X) X)) lstProperties)
 )
)
)

; Standardized Error Trap
(defun ErrorTrap (symFunction / objError result)
(if (vl-catch-all-error-p
     (setq objError (vl-catch-all-apply
                    '(lambda (X)(set X (eval symFunction)))
                     (list 'result))))
 (progn
  (if DEBUG
   (progn
    (princ "\n")
    (princ (vl-catch-all-error-message objError))
    (princ "\nWhile evaluating the expression: ")
    (princ symfunction)
    (princ "\n")
   )
  )
  nil  
 )
 (if result result 'T)
)
)
(defun c:t1 ( / obj props1 props2)
 (setq obj (vlax-ename->vla-object (car (entsel))))
 (setq props1 (GetDynamicBlockPropertyObjects obj))
 (setq props2 (GetDynamicBlockPropertyList obj))
 (princ)
)

Share this post


Link to post
Share on other sites
hanhphuc

this test assumes units in meters

(defun c:test (/ s en ob str SYM_ObjectID)
 (and 
      (setq en (car (entsel "\nReference object.. "))) [color="green"]; polyline? region? block?[/color]
      (setq ob (vlax-ename->vla-object en)
     SYM_ObjectID (itoa (vla-get-ObjectID ob ))
            str (cond ((vlax-property-available-p ob '[b][color="red"]Area[/color][/b])
		(strcat "%<\\AcObjProp Object(%<\\_ObjId " SYM_ObjectID ">%).Area \\f \"%lu2%pr2\">%")
		)
	       ((vl-some ''((x) (= (car x) [color="purple"]"[b]TestFlip[/b]"[/color])) ([color="blue"][b]LM:getdynprops[/b][/color] ob)) 
		(strcat "%<\\AcObjProp Object(%<\\_ObjId " SYM_ObjectID ">%).Parameter(1).UpdatedFlip>%")
		)
	   )
 )
      (princ "\nPick destination attributed block ")[color="green"] ;SYM_Block?[/color] 
      (setq s (ssget [color="purple"]"_:S:E:L+."[/color] '((0 . "INSERT") (66 . 1))))
      (vla-put-TextString
 (car (vlax-invoke (vlax-ename->vla-object (ssname s 0)) '[color="blue"]getattributes[/color])) [color="green"]
         ; your example has only one attribute, so we only need first item from the list[/color]
 str
 )
      )
   (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
 (princ)
 )


[color="green"];; Get Dynamic Block Properties  -  Lee Mac
;; Returns an association list of Dynamic Block properties & values.
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [lst] Association list of ((<prop> . <value>) ... )[/color]
(defun LM:getdynprops ( blk )
   (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
       (vlax-invoke blk 'getdynamicblockproperties)
   )
)

 

@rlx nice error handler

Share this post


Link to post
Share on other sites
rlx
@rlx nice error handler

well thank you hanhphuc .... but its not my code :D (see link above the code)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×