Results 1 to 3 of 3

Thread: Dynamic Block Insertion lisp

  1. #1
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Dynamic Block Insertion lisp

    Hey Guys

    I am very green when it comes to autolisp and I am trying to write a program to insert a dynamic block and prompt the user for the value and then place the value into the blocks properties.
    Ive tried using numerous autolisp fuctions to place information into block properties and im still coming up short.
    Ive attached my attempt at the lisp below aswell as a test drawing containing the block I am trying to make the lisp for.
    The property i am trying to control is the "Width".
    Any help I could get would be greatly appreciated.

    Cheers
    Attached Files Attached Files

  2. #2
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    0

    Default Re: Dynamic Block Insertion lisp

    Give the following a try. Note that Get-Dynprops is a general-use function I wrote some time ago, and C:MMDL has been revised only as much as I found necessary to make it work with my function (i.e. it has no error-handling, and is generally not robust). It may help you to get started, though...


    Code:
    ;;=============================================================================================
    ;; GET-DYNPROPS CREATES AND RETURNS AN ASSOCIATION LIST OF THE PROPERTIES OF A REFERENCE OF A
    ;; DYNAMIC BLOCK (ASSOCIATED WITH PROPERTYNAME, FOR EACH PROPERTY). RETURNS NIL IF THE BLOCK
    ;; REFERENCED IS NOT DYNAMIC
    (defun get-dynprops (blkins / CONS-X DYNLN DYNPROPARR DYNPROPLST
                         DYNPROPVAR N OUTLST PROPX PROPX-NM)
      (cond ((equal (vla-get-isdynamicblock blkins) ':vlax-false) nil); first condition
            ((vl-catch-all-error-p
               (setq dynpropvar
                      (vl-catch-all-apply
                        'vla-getdynamicblockproperties
                        (list blkins)
                      ); vl-catch-all-apply
               ); setq
             ); vl-catch-all-error-p
             nil
            ); second condition
            (t
             (setq dynproparr (vlax-variant-value dynpropvar)
                   dynproplst (vl-catch-all-apply 'vlax-safearray->list (list dynproparr))
                   dynln      (cond ((vl-catch-all-error-p dynproplst) 0)
                                    (t (length dynproplst))
                              ); cond
                   n          0
             ); setq
             (while (< n dynln)
               (setq propx    (nth n dynproplst)
                     propx-nm (vla-get-propertyname propx)
                     cons-x   (cons propx-nm propx)
                     outlst   (append outlst (list cons-x))
                     n        (1+ n)
               ); setq
             ); while
            ); third condition
      ); cond
      outlst
    ); defun
    
    (defun c:mmdl ( / BLK BLKPROPS INPUT P1 WIDTHPROP)
      (setq p1 (getpoint "\nPick Insertion Point ")
    	input 400
    	); setq
      (command "-insert" "MM_DuctDraw_Straight" p1 "" "" "")
      (setq blk (vlax-ename->vla-object (ssname (ssget "L") 0))
    	blkprops (get-dynprops blk)
    	widthprop (cdr (assoc "Width" blkprops))
    	); setq
      (vla-put-value widthprop (vlax-make-variant (* input 1.0)))
      (vla-regen (vla-get-activedocument (vlax-get-acad-object)) AcActiveViewport)
      ); defun

  3. #3
    I could stop if I wanted to
    Join Date
    2012-11
    Location
    Brisbane, Australia
    Posts
    239
    Login to Give a bone
    0

    Default Re: Dynamic Block Insertion lisp

    you are an absolute legend, Ill be able to work with this.
    Cheers mate.

Similar Threads

  1. Modify Insertion Name? of Dynamic block
    By dmleves in forum AutoLISP
    Replies: 3
    Last Post: 2012-12-12, 01:11 AM
  2. Attribute in Dynamic Block does not prompt on insertion
    By matthew g. in forum AutoCAD Customization
    Replies: 9
    Last Post: 2010-09-03, 05:36 PM
  3. Insertion of dynamic block from Excel
    By nilesh33 in forum Dynamic Blocks - Technical
    Replies: 1
    Last Post: 2009-08-26, 05:36 PM
  4. Dynamic Block and Insertion Point Help (Please)
    By DW2Whittle in forum VBA/COM Interop
    Replies: 1
    Last Post: 2009-01-29, 10:04 PM
  5. Loose dynamic states from sub block after insertion into master block
    By ANRCREATIONS in forum Dynamic Blocks - Technical
    Replies: 5
    Last Post: 2005-11-15, 02:41 PM

Posting Permissions

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