See the top rated post in this thread. Click here

Results 1 to 5 of 5

Thread: set distance by lisp in a dynamic block

  1. #1
    Member
    Join Date
    2017-08
    Posts
    19
    Login to Give a bone
    0

    Default set distance by lisp in a dynamic block

    Hi.
    Maybe someone here in this forum can help me.
    I'm trying to set the distance for a dynamic block of a single parameter; which is linear and is called Distance1.
    I do not know what I'm doing wrong, but I can not do it and change the desired distance.
    He helped me with the functions of Lee Mac, but something is wrong. Any help very similar, I will be completely grateful.


    Code:
    (defun c: ddd (/ obj dd)     
    
    (if (y (setq obj (car (entsel "\ ndynamic block:")              
    (setq dd (getdist "\ Length:"))))              
    (= "AcDbBlockReference" (vla- get-objectname (setq obj (vlax-esame-> vla-object obj))))              
    (=: vlax-true (vla-get-isdynamicblock obj))         
    )         
    
    (LM: setdynpropvalue obj "Distance1" dd)     
    )     
    
    (princ) 
    
    )
    
    
    (defun LM: setdynpropvalue (blk prp val)     
    (setq prp (strcase prp))     
    
    (vl-some        '(lambda (x)             
    (if (= prp (strcase (vla-get-propertyname x)))                 
    (progn                     
    (vla- put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x))))                     
    (cond (val) (t))                 
    )             
    )         
    )         
    (vlax-invoke blk 'getdynamicblockproperties)     ) ) 
    (vl-load-com) (princ)

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: set distance by lisp in a dynamic block

    Hi,

    Try this function.

    Code:
    (defun set:distance (blk dis)
      (vl-some '(lambda (x)
                  (and (eq "Distance1" (vla-get-propertyname x)) (vlax-put x 'Value dis))
                )
               (vlax-invoke (vlax-ename->vla-object blk) 'getdynamicBlockproperties)
               )
    ) (vl-load-com)
    Usage of above function:

    Code:
    (set:distance <BlockEntityName> <DistanceValue>)

  3. #3
    Member
    Join Date
    2016-02
    Posts
    3
    Login to Give a bone
    0

    Default Re: set distance by lisp in a dynamic block

    Both doesn't work.

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: set distance by lisp in a dynamic block

    Quote Originally Posted by sergpush36721006 View Post
    Both doesn't work.
    What do you mean by both?

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

    Default Re: set distance by lisp in a dynamic block

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2018 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Any use by unauthorized person or business is strictly prohibited.
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;  Function List Argument1 Argument2 Arguement3
    
    ;* (DynamicBlockPropertyPut objSelection strWCProperty sngValue)
    ;* Function to change (put) dynamic block property values
    
    ;* (ErrorTrap symFunction)
    ;* Function to trap errors
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to change (put) dynamic block property values
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicBlockPropertyPut (objSelection strWCProperty sngValue / lstDynamicBlockProperties objDynamicBlockProperty)
     (if (and (= (type objSelection) 'vla-object)
              (vlax-property-available-p objSelection "isdynamicblock")
              (= (vla-get-isdynamicblock objSelection) :vlax-true)
              (setq lstDynamicBlockProperties (vlax-invoke objSelection "getdynamicblockproperties"))
         )
      (foreach objDynamicBlockProperty lstDynamicBlockProperties
       (if (wcmatch (strcase (vla-get-propertyname objDynamicBlockProperty)) (strcase strWCProperty))
        (errortrap '(vla-put-value objDynamicBlockProperty sngValue))
       )
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; 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)
    Code:
    (DynamicBlockPropertyPut obj "Distance1" 180.0)
    
    where obj was a valid vla-object
    Worked for me...

    Also I saw a lot of typos in LM's code... He is usually good about testing his stuff... Maybe it copied wrong...
    Attached Files Attached Files
    Last edited by peter; 2018-08-19 at 10:55 PM.
    AutomateCAD

Similar Threads

  1. Replies: 1
    Last Post: 2015-05-11, 09:03 PM
  2. Dynamic Block Insertion lisp
    By LSElite in forum AutoLISP
    Replies: 2
    Last Post: 2012-11-28, 02:28 AM
  3. Using LISP to insert a Dynamic block
    By Ferroequine in forum Dynamic Blocks - Technical
    Replies: 10
    Last Post: 2010-03-25, 02:23 PM
  4. Replies: 10
    Last Post: 2006-12-28, 10:11 PM
  5. Obtaining dynamic block name through LISP
    By cadconcepts in forum AutoLISP
    Replies: 1
    Last Post: 2006-10-03, 01:24 PM

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
  •