Results 1 to 5 of 5

Thread: Dynamic Block Values with Lisp

  1. #1
    Member
    Join Date
    2014-10
    Posts
    12
    Login to Give a bone
    0

    Post Dynamic Block Values with Lisp

    Hello AUGI Users –

    I’m looking for some help to grab information from a dynamic block and place that information into an attributed table in the same drawing.

    The dynamic block has 2 stretch parameters and 2 linear parameters. These parameters allow the user to stretch the polyline to the desired width and height. I’m looking to grab the ‘Value’ from each of linear parameters and place those values into the attributed table (I have included the dynamic block linear properties below from the attached drawing. The format of those values should be fractional (precision set to 1/32).

    I have attached a sample drawing with both blocks mentioned above.

    Thank you in advanced for your help with this.

    Code:
    ; IAcadDynamicBlockReferenceProperty: AutoCAD Dynamic Block Property Interface
    ; Property values:
    ;   AllowedValues (RO) = nil
    ;   Description (RO) = ""
    ;   PropertyName (RO) = "Unit Height"
    ;   ReadOnly (RO) = 0
    ;   show (RO) = -1
    ;   UnitsType (RO) = 2
    ;   Value = 8.87409
    ; No methods
    
    
    ; IAcadDynamicBlockReferenceProperty: AutoCAD Dynamic Block Property Interface
    ; Property values:
    ;   AllowedValues (RO) = nil
    ;   Description (RO) = ""
    ;   PropertyName (RO) = "Unit Width"
    ;   ReadOnly (RO) = 0
    ;   show (RO) = -1
    ;   UnitsType (RO) = 2
    ;   Value = 6.25492
    ; No methods
    Attached Files Attached Files
    Last edited by r.zinke; 2019-02-06 at 08:14 PM. Reason: Please use [CODE] Tags

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu Hawaii
    Posts
    1,028
    Login to Give a bone
    0

    Default Re: Dynamic Block Values with Lisp

    Something like this

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2019 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Any use by unauthorized person or business is strictly prohibited.
    ; Include Shorthand.lsp
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Comand line function list
    ;___________________________________________________________________________________________________________|
    
    ;* C:Augi5
    ;* Command line function to read a dynamic block and put height and width into an attributes block
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;  Function List Argument1 Argument2 Arguement3
    
    ;* (AttributeSublists objSelection)
    ;* Function to get attribute sublists ('tagstring 'textstring obj)
    
    ;* (DynamicPropertiesList objDynamicBlock)
    ;* Function to Get a list of sublists including dynamic block property names and objects.
    
    ;* (ErrorTrap symFunction)
    ;* Function to trap errors
    
    
    ;$ EndHeader
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function to change attributes to be width and height of dynamic block
    ;___________________________________________________________________________________________________________|
    
    (defun C:Augi5 (/ entSelection 
                      lstDynamics
                      lstOfSublists
                      lstSublist 
                      objBlockInfill 
                      objDynamicBlock 
                      sngUnitHeight 
                      sngUnitWidth 
                      ssSelections
                   )
     (and (princ "\nSelect Boundary Dynamic Block: ")
          (setq ssSelections    (ssget ":S:E" (list (cons 0 "insert"))))
          (setq entSelection    (ssname ssSelections 0))
          (setq objDynamicBlock (vlax-ename->vla-object entSelection))
          (setq lstDynamics     (DynamicPropertiesList objDynamicBlock))
          (setq sngUnitWidth    (cadr (assoc "Unit Width"  lstDynamics)))
          (setq sngUnitHeight   (cadr (assoc "Unit Height" lstDynamics)))
          (setq ssSelections    (ssget "x" (list (cons 0 "insert")(cons 2 "Infill_Row"))))
          (setq entSelection    (ssname ssSelections 0))
          (setq objBlockInfill  (vlax-ename->vla-object entSelection))
          (setq lstOfSublists   (AttributeSublists objBlockInfill))
          (setq lstSublist      (assoc "U_WIDTH" lstOfSublists))
          (errortrap           '(vla-put-textstring (caddr lstSublist) (rtos sngUnitWidth 2 2)))
          (setq lstSublist      (assoc "U_HEIGHT" lstOfSublists))
          (errortrap           '(vla-put-textstring (caddr lstSublist) (rtos sngUnitHeight 2 2)))
     )
    )
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get attribute sublists ('tagstring 'textstring obj)
    ;___________________________________________________________________________________________________________|
    
    (defun AttributeSublists (objSelection / lstAttributes);
     (if (and (= (vla-get-hasattributes objSelection) :vlax-true)
              (setq lstAttributes (vlax-invoke objSelection "getattributes"))
         )
      (mapcar '(lambda (objAttribute) (list (strcase (vla-get-tagstring  objAttribute))
                                            (vla-get-textstring  objAttribute)
                                            objAttribute
                                      )
               )
               lstAttributes
      )
     )
    )
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to Get a list of sublists including dynamic block property names and objects.
    ;___________________________________________________________________________________________________________|
    
    
    (defun DynamicPropertiesList (objDynamicBlock 
                                  / 
                                  lstProperties
                                  X
                                  lstReturn
                                 )
    
     (if (and (vlax-property-available-p objDynamicBlock "IsDynamicBlock")
              (= (vla-get-IsDynamicBlock objDynamicBlock) :vlax-true)
              (setq lstProperties (errortrap  '(vlax-safearray->list 
                                                (variant-value 
                                                 (vla-GetDynamicBlockProperties objDynamicBlock)
                                                )
                                               )
                                  )
              )
              (setq lstReturn (mapcar '(lambda (x)(list (vla-get-propertyname X) (vlax-get X "value"))) lstProperties))
         )
      (while (setq lstSublist (assoc "Origin" lstReturn))
       (setq lstReturn (vl-remove lstSublist lstReturn))
      )
     )
     lstReturn
    )
    
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to trap errors
    ;___________________________________________________________________________________________________________|
    
    (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))))
      nil
      (if result result 'T)
     )
    )
    
    (princ)
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2019-02-07 at 04:23 PM.
    AutomateCAD

  3. #3
    Member
    Join Date
    2014-10
    Posts
    12
    Login to Give a bone
    0

    Default Re: Dynamic Block Values with Lisp

    Peter –

    Thank you for your fast reply. I tried the code and receive the following error after I select the dynamic block:

    ; error: no function definition: TOOBJECT

    Also could the code be changed to select the dynamic block without any action from the user? Then the attributed block would automatically populate.

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu Hawaii
    Posts
    1,028
    Login to Give a bone
    0

    Default Re: Dynamic Block Values with Lisp

    You can just remove that line it is unnecessary.

    I revised my post before to erase that line and add a header.

    P=
    AutomateCAD

  5. #5
    Member
    Join Date
    2014-10
    Posts
    12
    Login to Give a bone
    0

    Default Re: Dynamic Block Values with Lisp

    Peter -

    I removed that line and the program works. Thank you!!

    One last question for you... when you run the program can the dynamic block be selected WITHOUT action by the user? This program will be used as part of a batch process. I tried an ssget and that does not seem to work. Most likely I have the format wrong. See below:

    (setq ssSelections (ssget ":S:E" (list (cons 0 "insert")))) your code
    (setq ssSelections (ssget "x" (list (cons 0 "insert") (cons 2 "Unit_Size")))) my try
    Last edited by r.zinke; 2019-02-08 at 02:51 PM.

Similar Threads

  1. Dynamic block with attributes that display X, Y, and Z values
    By sammyz28 in forum Dynamic Blocks - Technical
    Replies: 25
    Last Post: 2015-12-03, 05:37 AM
  2. How to change dynamic block attribute default values based on block selected?
    By zeirz109180 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2013-12-13, 02:20 PM
  3. Using Attribute values to control Dynamic Block actions
    By bshank.140587 in forum Dynamic Blocks - Technical
    Replies: 5
    Last Post: 2007-06-17, 02:12 AM
  4. Extract Dynamic Block Attributes, values change as Block changes
    By dave.buckberry in forum Dynamic Blocks - Technical
    Replies: 11
    Last Post: 2006-09-05, 04:38 PM
  5. Replies: 6
    Last Post: 2006-04-03, 07:19 AM

Tags for this Thread

Posting Permissions

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