Jump to content

Obtain ObjID from a Flip Parameter inside a block


svorgodne

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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