+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Senior Member
    Discipline
    Architectural
    svorgodne's Discipline Details
    Occupation
    Architect. Lisp developer
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    May 2007
    Location
    Vienna, Austria
    Posts
    155

    Default Obtain ObjID from a Flip Parameter inside a block

    Registered forum members do not see this ad.

    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.

    Code:
    (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.

    Code:
    (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

    Code:
    (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
    Attached Files

  2. #2
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    998

    Default

    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


    Code:
    (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)
    )

  3. #3
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    710

    Default

    this test assumes units in meters
    Code:
    (defun c:test (/ s en ob str SYM_ObjectID)
      (and 
           (setq en (car (entsel "\nReference object.. "))) ; polyline? region? block?
           (setq ob (vlax-ename->vla-object en)
    	     SYM_ObjectID (itoa (vla-get-ObjectID ob ))
                 str (cond ((vlax-property-available-p ob 'Area)
    			(strcat "%<\\AcObjProp Object(%<\\_ObjId " SYM_ObjectID ">%).Area \\f \"%lu2%pr2\">%")
    			)
    		       ((vl-some ''((x) (= (car x) "TestFlip")) (LM:getdynprops ob)) 
    			(strcat "%<\\AcObjProp Object(%<\\_ObjId " SYM_ObjectID ">%).Parameter(1).UpdatedFlip>%")
    			)
    		   )
    	 )
           (princ "\nPick destination attributed block ") ;SYM_Block? 
           (setq s (ssget "_:S:E:L+." '((0 . "INSERT") (66 . 1))))
           (vla-put-TextString
    	 (car (vlax-invoke (vlax-ename->vla-object (ssname s 0)) 'getattributes)) 
              ; your example has only one attribute, so we only need first item from the list
    	 str
    	 )
           )
        (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
      (princ)
      )
    
    
    ;; 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>) ... )
    (defun LM:getdynprops ( blk )
        (mapcar '(lambda ( x ) (cons (vla-get-propertyname x) (vlax-get x 'value)))
            (vlax-invoke blk 'getdynamicblockproperties)
        )
    )
    @rlx nice error handler
    _$ ( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" )
    ; error: too many arguments

  4. #4
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    998

    Default

    Registered forum members do not see this ad.

    @rlx nice error handler
    well thank you hanhphuc .... but its not my code (see link above the code)

Similar Threads

  1. Dynamic block - Door: Zero value linear parameter bug, stretch after flip flaw
    By Jooogyerek in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 21st Mar 2018, 02:17 pm
  2. Replies: 6
    Last Post: 5th Oct 2012, 06:15 pm
  3. Add an Item to flip parameter?
    By Lt Dan's legs in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 26th Aug 2011, 04:21 pm
  4. Flip Parameter
    By YZ in forum AutoCAD Drawing Management & Output
    Replies: 0
    Last Post: 15th Mar 2010, 11:54 pm
  5. dynamic block: bifold doors W/ flip parameter woes...
    By hazardman in forum AutoCAD General
    Replies: 4
    Last Post: 30th Aug 2007, 01:36 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts