+ Reply to Thread
Page 1 of 7 1 2 3 ... LastLast
Results 1 to 10 of 62
  1. #1
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Apr 2010
    Posts
    14

    Default Lisp & Dynamic Block

    Registered forum members do not see this ad.

    I've looked for a code like this forever. Using lisp I'm looking to Insert a dynamic block, automatically select the stretch grip of the DB & When the lisp is done the DB will explode.
    Last edited by REID7800; 4th May 2010 at 04:54 pm.

  2. #2
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Apr 2010
    Posts
    14

    Default

    I know how to insert but I do not know how to select the dynamic grip after it has been inserted. That's all I'm really looking for

  3. #3
    Full Member Andrew1979's Avatar
    Computer Details
    Andrew1979's Computer Details
    Operating System:
    Windows 7
    CPU:
    AMD Phenom II 1090T @ 4.1GHz
    RAM:
    16GB
    Primary Storage:
    WD 64Gb Raptor
    Secondary Storage:
    WD 1Tb Black
    Monitor:
    HP
    Discipline
    Architectural
    Andrew1979's Discipline Details
    Occupation
    Architectural Student
    Discipline
    Architectural
    Using
    AutoCAD 2013
    Join Date
    Jun 2008
    Location
    Ballarat, Victoria, Australia
    Posts
    32

    Default

    Not sure how to do this or if it can be done, but is using the dynamic block necessary? You could just write a lisp routine to draw what it is you want. If you post the block, maybe I will be clearer in what you are trying to achieve.
    I have written lisp routines to draw floor joists from one to point to another, and able to enter the height. Happy to help if you post block.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    I'm not quite sure what you are trying to achieve using the LISP to select the grip - why not just select the grip manually?

    If you wanted to modify the properties you would need to look into the code for getting at Dynamic Block properties, I have written a plethora of code for such here:

    Code:
    ;; Retrieves All Properties from a Dynamic Block
    ;; Args: obj ~ Dynamic Block VLA-Object
    ;; Returns: ((<property name> <value>) ...)
    
    (defun GetDynProps (obj)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x / v)
            (list (vla-get-PropertyName x)
                  (if (= 8192 (logand 8192 (vlax-variant-type (setq v (vla-get-value x)))))
                    (vlax-safearray->list (vlax-variant-value v))
                    (vlax-variant-value v)))))
          
        (vlax-invoke obj 'GetDynamicBlockProperties)))
    
    ;; Retrieves All Properties from a Dynamic Block
    ;; Args: obj ~ Dynamic Block VLA-Object
    ;; Returns: ((<property name> <value>) ...)
    
    (defun GetDynProps (obj)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x) (list (vla-get-PropertyName x) (vlax-get x 'Value))))
    
        (vlax-invoke obj 'GetDynamicBlockProperties)))
    
    ;; Changes a Dynamic Block Property Value
    ;; Args: obj  ~ Dynamic Block VLA-Object
    ;;       prop ~ Property Name
    ;;       val  ~ New Value
    ;; Returns: New Value (val)
    
    (defun PutDynPropValue (obj prop val)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x)
            (if (eq (strcase prop) (strcase (vla-get-propertyName x)))
              (vla-put-value x
                (vlax-make-variant val
                  (vlax-variant-type (vla-get-value x)))))))
    
        (vlax-invoke obj 'GetDynamicBlockProperties)) val)
    
    ;; Retrieves the Allowed Values for a Specific Property
    ;; Args: obj  ~ Dynamic Block VLA-Object
    ;;       prop ~ Property Name
    ;; Returns: List of Allowed Values (or nil)
    
    (defun GetPropAllowedValues (obj prop / a)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x / w)
            (if (eq (strcase prop) (strcase (vla-get-propertyName x)))
              (setq a
                (mapcar
                  (function
                    (lambda (v)
                      (if (= 8192 (logand 8192 (vlax-variant-type v)))
                        (vlax-safearray->list (vlax-variant-value v))
                          (vlax-variant-value v))))
                  
                  (if (< 0 (vlax-safearray-get-u-bound
                             (setq w (vlax-variant-value
                                       (vla-get-AllowedValues x))) 1))
                    
                    (vlax-safearray->list w)))))))
        
        (vlax-invoke obj 'GetDynamicBlockProperties)) a)
    
    ;; Retrieves the Allowed Values for a Specific Property
    ;; Args: obj  ~ Dynamic Block VLA-Object
    ;;       prop ~ Property Name
    ;; Returns: List of Allowed Values (or nil)
    
    (defun GetPropAllowedValues (obj prop / a)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x)
            (if (eq (strcase prop) (strcase (vla-get-propertyName x)))
              (setq a (vlax-get x 'AllowedValues)))))
    
        (vlax-invoke obj 'GetDynamicBlockProperties)) a)
    
    ;; Retrieves the Allowed Values for all Properties
    ;; Args: obj  ~ Dynamic Block VLA-Object
    ;; Returns: ((<property name> (<Allowed Values>)) ...)
    
    (defun GetAllowedValues (obj)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x / w)
            (list (vla-get-propertyname x)
                  (mapcar
                    (function
                      (lambda (v)
                        (if (= 8192 (logand 8192 (vlax-variant-type v)))
                          (vlax-safearray->list (vlax-variant-value v))
                            (vlax-variant-value v))))
    
                    (if (< 0 (vlax-safearray-get-u-bound
                               (setq w (vlax-variant-value
                                         (vla-get-AllowedValues x))) 1))
                      
                      (vlax-safearray->list w))))))
        
        (vlax-invoke obj 'GetDynamicBlockProperties)))
    
    ;; Retrieves the Allowed Values for all Properties
    ;; Args: obj  ~ Dynamic Block VLA-Object
    ;; Returns: ((<property name> (<Allowed Values>)) ...)
    
    (defun GetAllowedValues (obj)
      ;; Lee Mac  ~  07.04.10
      (mapcar
        (function
          (lambda (x)
            (list (vla-get-propertyname x)
                  (vlax-get x 'AllowedValues))))
    
        (vlax-invoke obj 'GetDynamicBlockProperties)))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Apr 2010
    Posts
    14

    Default

    I'm trying to array db's. I work with people that only know basic Autocad commands. I'm trying to get something visual so that's why I went with the Dynamic block of a Dynamic block. This way they can see how far the block is going. When they're done stetching the block, just explode it and everything is back to normal.
    Attached Files

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    This might give you some food for thought:

    Code:
    (defun c:InsertBlock ( / block space point )
      (vl-load-com)
      ;; Lee Mac  ~  05.05.10
    
      (setq block nil) ;; Block Name or nil
    
      (setq space
        (if
          (or
            (eq AcModelSpace
              (vla-get-ActiveSpace
                (setq doc
                  (vla-get-ActiveDocument
                    (vlax-get-acad-object)
                  )
                )
              )
            )
            (eq :vlax-true
              (vla-get-MSpace doc)
            )
          )
          (vla-get-ModelSpace doc)
          (vla-get-PaperSpace doc)
        )
      )        
    
      (if (setq block (GetBlock block))
        (while
          (setq point
            (getpoint "\nSpecify Point for Insertion: "))
          
          (InsertBlock space block point)
        )
      )
      
      (princ)
    )
    
    (defun GetBlock ( block )
      ;; Lee Mac  ~  05.05.10
      (cond
        (
          (not
            (and
              (or block
                (setq block
                  (getfiled "Select Block" "" "dwg" 16)
                )
              )
              (or
                (and
                  (eq "" (vl-filename-extension block))
                  (or
                    (tblsearch "BLOCK" block)
                    (setq block
                      (findfile
                        (strcat block ".dwg")
                      )
                    )
                  )
                )
                (setq block (findfile block))
              )
            )
          )
         nil
        )
        ( block )
      )
    )
    
    (defun InsertBlock ( Block Name Point )
      (vla-InsertBlock Block
        (vlax-3D-point Point) Name 1. 1. 1. 0.
      )
    )
    I don't know the name of the tag you are trying to populate hence I cannot proceed any further with this code.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Apr 2010
    Posts
    14

    Default

    I wanted to array the block with lisp. That code above can get tedious when you have a long span. The Dynamic block is in the dwg above. Block name: panel
    Last edited by REID7800; 5th May 2010 at 01:40 pm.

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    An updated code to the above - it could be worked into an array:

    Code:
    (defun c:InsertBlock ( / block tag space point )
      (vl-load-com)
      ;; Lee Mac  ~  05.05.10
    
      (setq block "PANEL") ;; Block Name or nil
    
      (setq tag nil)   ;; Tag Name or nil
    
      (setq space
        (if
          (or
            (eq AcModelSpace
              (vla-get-ActiveSpace
                (setq doc
                  (vla-get-ActiveDocument
                    (vlax-get-acad-object)
                  )
                )
              )
            )
            (eq :vlax-true
              (vla-get-MSpace doc)
            )
          )
          (vla-get-ModelSpace doc)
          (vla-get-PaperSpace doc)
        )
      )        
    
      (if
        (and
          (setq block (GetBlock block))
          (setq *num*
            (1-
              (cond
                (
                  (getint
                    (strcat "\nSpecify Starting Number <"
                      (itoa
                        (setq *num*
                          (cond ( *num* ) ( 1 ))
                        )
                      )
                      "> : "
                    )
                  )
                )
                ( *num* )
              )
            )
          )
        )
    
        (while
          (setq *num* (1+ *num*)
                point (getpoint "\nSpecify Point for Insertion: "))
          
          (if (and (setq obj (InsertBlock space block point)) tag)
            (PutAttValue obj tag (itoa *num*))
          )
        )
      )
      
      (princ)
    )
    
    (defun PutAttValue ( object tag value )
      ;; Lee Mac  ~  05.05.10
      (mapcar
        (function
          (lambda ( attrib )
            (and
              (eq tag (vla-get-TagString attrib))
              (vla-put-TextString attrib value)
            )
          )
        )
        (vlax-invoke object 'GetAttributes)
      )
      value
    )
    
    (defun GetBlock ( block )
      ;; Lee Mac  ~  05.05.10
      (cond
        (
          (not
            (and
              (or block
                (setq block
                  (getfiled "Select Block" "" "dwg" 16)
                )
              )
              (or
                (and
                  (vl-position
                    (vl-filename-extension block) '("" nil)
                  )
                  (or
                    (tblsearch "BLOCK" block)
                    (setq block
                      (findfile
                        (strcat block ".dwg")
                      )
                    )
                  )
                )
                (setq block (findfile block))
              )
            )
          )
         nil
        )
        ( block )
      )
    )
    
    (defun InsertBlock ( Block Name Point )
      (if
        (not
          (vl-catch-all-error-p
            (setq result
              (vl-catch-all-apply (function vla-insertblock)
                (list Block (vlax-3D-point point) Name 1. 1. 1. 0.)
              )
            )
          )
        )
        result
      )
    )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  9. #9
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Apr 2010
    Posts
    14

    Default

    Not exactly what I was looking for... why is it counting?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,708

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by REID7800 View Post
    Not exactly what I was looking for... why is it counting?
    Dude - I'm going by what you posted previously - how to write the code better, which included a count.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. Dynamic block with dynamic attributes
    By Helenka in forum AutoCAD Drawing Management & Output
    Replies: 14
    Last Post: 28th Jul 2012, 09:56 am
  2. dynamic insert of a dynamic block.
    By Huibert in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 13th Jun 2010, 02:12 am
  3. LISP and Dynamic Block
    By guitarguy1685 in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 7th Jan 2010, 09:26 am
  4. multiple dynamic constraints in a dynamic block
    By Huibert in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 16th Jul 2009, 11:13 am
  5. Replies: 5
    Last Post: 26th Jun 2009, 04:50 pm

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