Results 1 to 7 of 7

Thread: Help wanted for a lisp - How to control dynamic props from a attribute tag

  1. #1
    Member
    Join Date
    2015-01
    Posts
    3
    Login to Give a bone
    0

    Default Help wanted for a lisp - How to control dynamic props from a attribute tag

    Hi from France

    I need help about a dynamic block . I'm not at ease with the LISP

    I created a dynamic block with a distance prop : "Distance1" + a visibility state "visibility1" + a flip state "flipstate1"

    My block has 3 attributes tag "DISTANCE" , "VISIBILITY", "FLIPSTATE"

    I want to put the value of these labels in the dynamic properties

    I tried this LISP:

    Code:
    ;; gc:GetDynProps
    ;; Retourne la liste des propriétés dynamiques de la référence de bloc
    ;; sous la forme d'une liste de paire pointées (PropertyName . DynamicBlockProperty)
    ;;
    ;; Argument
    ;; bref : référence de bloc (vla-object)
    (defun gc:GetDynProps (bref / lst)
      (foreach p (vlax-invoke bref 'getDynamicBlockProperties)
        (setq lst (cons (cons (vla-get-PropertyName p) p) lst))
      )
      (reverse lst)
    )
    
    ;; gc:GetAttributes
    ;; Retourne la liste des attributs de la référence de bloc
    ;; sous la forme d'une liste de paire pointées (TagString . AttributeReference)
    ;;
    ;; Argument
    ;; bref : référence de bloc (vla-object)
    (defun gc:GetAttributes (bref / lst)
      (foreach att (vlax-invoke bref 'GetAttributes)
        (setq lst (cons (cons (vla-get-TagString att) att) lst))
      )
      (reverse lst)
    )
    
    ;; gc:AttToDynProp
    ;; Attribut à chaque propriété dynamique de la liste la valeur de l'attribut correspondante
    ;;
    ;; Arguments
    ;; bref : référence de bloc (vla-object)
    ;; lst : une liste de paires pointées (TagString . PropertyName)
    (defun gc:AttToDynProp (bref lst / atts props att prop)
      (setq atts  (gc:GetAttributes bref)
            props (gc:GetDynProps bref)
      )
      (foreach p lst
        (if
          (and
            (setq att (assoc (car p) atts))
            (setq prop (assoc (cdr p) props))
          )
           (vl-catch-all-apply
             '(lambda (/ typ)
                (setq typ (vlax-variant-type (vla-get-Value (cdr prop))))
                (cond
                  ((< 1 typ 4)
                   (vla-put-Value (cdr prop) (atoi (vla-get-TextString (cdr att))))
                  )
                  ((< 3 typ 6)
                   (vla-put-Value (cdr prop) (atof (vla-get-TextString (cdr att))))
                  )
                  ((= 8 typ)
                   (vla-put-Value (cdr prop) (vla-get-TextString (cdr att)))
                  )
                )
              )
           )
        )
      )
    )
    
    (defun c:majdyn (/ lst ss)
      (vl-load-com)
      (or *acad* (setq *acad* (vlax-get-acad-object)))
      (or *acdoc* (setq *acdoc* (vla-get-ActiveDocument *acad*)))
    
      (setq lst '(
                  [surligneur]("DISTANCE" . "Distance1")
                  ("ETATD'INVERSION" . "Etatd'inversion1")
                  ("VISIBILITE" . "Visibilité1)[/surligneur]
                 )
      )
    
      
      (if (ssget '((0 . "INSERT") (66 . 1)))
        (progn
          (vlax-for bref (setq ss (vla-get-ActiveSelectionSet *acdoc*))
            (gc:AttToDynProp bref lst)
          )
          (vla-Delete ss)
        )
      )
      (princ)
    )
    Last edited by BlackBox; 2015-01-28 at 09:00 PM. Reason: Please use [CODE] Tags

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help wanted for a lisp - How to control dynamic props from a attribute tag

    Welcome to AUGI.

    Do you mind posting a link to where you found the code you posted?

    Also, it might help others to help you, if you can post a sample dynamic block.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2015-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: Help wanted for a lisp - How to control dynamic props from a attribute tag

    The lisp code was written by the famous French Gile (CADXP)

    I erased the [surligneur] and the [/surligneur] used in visual lisp not in lisp code


    Whith this code, I can set the distance prop and the visility state prop with the attribute's value

    However it doesn't set the flip state

    According my search the flip state is an integer 0 or 1

    But I don't know how to write such a value in my attribute label ( it seems to be a string not a integer but I'm not sure ...)

    You can try with the block in the attached file


    Thanks for your prompt reply


    Michel



    Here is the new code :


    Code:
    ;; gc:GetDynProps
    ;; Retourne la liste des propriétés dynamiques de la référence de bloc
    ;; sous la forme d'une liste de paire pointées (PropertyName . DynamicBlockProperty)
    ;;
    ;; Argument
    ;; bref : référence de bloc (vla-object)
    (defun gc:GetDynProps (bref / lst)
      (foreach p (vlax-invoke bref 'getDynamicBlockProperties)
        (setq lst (cons (cons (vla-get-PropertyName p) p) lst))
      )
      (reverse lst)
    )
    
    ;; gc:GetAttributes
    ;; Retourne la liste des attributs de la référence de bloc
    ;; sous la forme d'une liste de paire pointées (TagString . AttributeReference)
    ;;
    ;; Argument
    ;; bref : référence de bloc (vla-object)
    (defun gc:GetAttributes (bref / lst)
      (foreach att (vlax-invoke bref 'GetAttributes)
        (setq lst (cons (cons (vla-get-TagString att) att) lst))
      )
      (reverse lst)
    )
    
    ;; gc:AttToDynProp
    ;; Attribut à chaque propriété dynamique de la liste la valeur de l'attribut correspondante
    ;;
    ;; Arguments
    ;; bref : référence de bloc (vla-object)
    ;; lst : une liste de paires pointées (TagString . PropertyName)
    (defun gc:AttToDynProp (bref lst / atts props att prop)
      (setq atts  (gc:GetAttributes bref)
            props (gc:GetDynProps bref)
      )
      (foreach p lst
        (if
          (and
            (setq att (assoc (car p) atts))
            (setq prop (assoc (cdr p) props))
          )
           (vl-catch-all-apply
             '(lambda (/ typ)
                (setq typ (vlax-variant-type (vla-get-Value (cdr prop))))
                (cond
                  ((< 1 typ 4)
                   (vla-put-Value (cdr prop) (atoi (vla-get-TextString (cdr att))))
                  )
                  ((< 3 typ 6)
                   (vla-put-Value (cdr prop) (atof (vla-get-TextString (cdr att))))
                  )
                  ((= 8 typ)
                   (vla-put-Value (cdr prop) (vla-get-TextString (cdr att)))
                  )
                )
              )
           )
        )
      )
    )
    
    (defun c:majdyn (/ lst ss)
      (vl-load-com)
      (or *acad* (setq *acad* (vlax-get-acad-object)))
      (or *acdoc* (setq *acdoc* (vla-get-ActiveDocument *acad*)))
    
      (setq lst '(
                  ("DISTANCE" . "Distance1")
                  ("ETATD'INVERSION" . "Etatd'inversion1")
                  ("VISIBILITE" . "Visibilité1)
                 )
      )
    
      
      (if (ssget '((0 . "INSERT") (66 . 1)))
        (progn
          (vlax-for bref (setq ss (vla-get-ActiveSelectionSet *acdoc*))
            (gc:AttToDynProp bref lst)
          )
          (vla-Delete ss)
        )
      )
      (princ)
    )
    Attached Files Attached Files
    Last edited by BlackBox; 2015-01-29 at 02:05 PM. Reason: Please use [CODE] Tags

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help wanted for a lisp - How to control dynamic props from a attribute tag

    Quote Originally Posted by s2p.bet690394 View Post
    The lisp code was written by the famous French Gile (CADXP)
    Thanks for clarifying, as I recognized his code - Some might even accuse me of being a 'strong supporter' of Gile's work.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Member
    Join Date
    2015-01
    Posts
    3
    Login to Give a bone
    0

    Default Re: Help wanted for a lisp - How to control dynamic props from a attribute tag

    Is anybody able to explain me the lambda function


    specially the values of the conditions (( < 1 typ 4) ????? ((< 3 typ 6)????? and ((= 8 typ)?????


    In this code

    Code:
      (vl-catch-all-apply
             '(lambda (/ typ)
                (setq typ (vlax-variant-type (vla-get-Value (cdr prop))))
                (cond
                  ((< 1 typ 4)
                   (vla-put-Value (cdr prop) (atoi (vla-get-TextString (cdr att))))
                  )
                  ((< 3 typ 6)
                   (vla-put-Value (cdr prop) (atof (vla-get-TextString (cdr att))))
                  )
                  ((= 8 typ)
                   (vla-put-Value (cdr prop) (vla-get-TextString (cdr att)))
                  )
                )
              )
           )
        )
      )
    )
    I try to understand why the textstring is not converted into an integer

    Code:
    ((< 1 typ 4?????)
                   (vla-put-Value (cdr prop) (atoi (vla-get-TextString (cdr att))))
    The atoi function should convert the textstring into an integer

    and the flipstate should be modified

    Unfortunately


    regards

    Michel
    Last edited by BlackBox; 2015-01-31 at 02:13 PM.

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Help wanted for a lisp - How to control dynamic props from a attribute tag

    Quote Originally Posted by s2p.bet690394 View Post
    Is anybody able to explain me the lambda function
    That is an entire discussion unto itself... To start, you might consider Lee's excellent Mapcar & Lambda tutorial.



    Quote Originally Posted by s2p.bet690394 View Post
    specially the values of the conditions (( < 1 typ 4) ????? ((< 3 typ 6)????? and ((= 8 typ)?????


    In this code

    Code:
      (vl-catch-all-apply
             '(lambda (/ typ)
                (setq typ (vlax-variant-type (vla-get-Value (cdr prop))))
                (cond
                  ((< 1 typ 4)
                   (vla-put-Value (cdr prop) (atoi (vla-get-TextString (cdr att))))
                  )
                  ((< 3 typ 6)
                   (vla-put-Value (cdr prop) (atof (vla-get-TextString (cdr att))))
                  )
                  ((= 8 typ)
                   (vla-put-Value (cdr prop) (vla-get-TextString (cdr att)))
                  )
                )
              )
           )
        )
      )
    )
    I try to understand why the textstring is not converted into an integer

    Code:
    ((< 1 typ 4?????)
                   (vla-put-Value (cdr prop) (atoi (vla-get-TextString (cdr att))))
    The atoi function should convert the textstring into an integer

    and the flipstate should be modified
    I'm not sure on this, as I've not even downloaded your block yet, due to my working on an important submittal still. I will get back to this as time permits; hopefully someone else will be able to assist in that time.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    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: Help wanted for a lisp - How to control dynamic props from a attribute tag

    When playing with these dynamic properties a few years ago I found that the flip state was problematic.

    Even though 0 and 1 are integers, it didn't change when I used the vlax-put syntax.

    Playing around I found that the variant was different that way.

    The following code builds the correct variant to change the flip state.

    It is also general...

    Take a look.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to control dynamic block properties
    ; Written By: Peter Jamtgaard Copyright 2015 All rights reserved
    ; Syntax: (dynamicpropertiesput (vlax-ename->vla-object (car (entsel "select Dynamic Block"))) "Distance1" 240.0)
    ; Returns T for success (at least one property changed) or nil for failure
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to put a dynamic block property value given block instance object, wildcard propertyname and Value
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicPropertiesPut (objSelection 
                                 strWCProperty 
                                 Value 
                                 / 
                                 objDynamic
                                 strProperty
                                )  
     (and
      (vlax-property-available-p objSelection "IsDynamicBlock")   
      (= (vla-get-IsDynamicBlock objSelection) :vlax-true)
      (apply 'or
       (mapcar '(lambda (X)(DynamicPropertyPut X strWCProperty Value))
                (vlax-invoke objSelection "GetDynamicBlockProperties")
       )
      )
     )
    
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to put a dynamic block property value given Dynamic Block Property object, 
    ; wildcard propertyname and Value
    ; Returns T for success and nil for failure
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicPropertyPut (objDynamic
                               strWCProperty
                               Value
                               /
                               intVariantType
                               lstAllowedValues
                               strProperty
                               varOldValue
                              )
     (and 
      (vlax-property-available-p objDynamic "AllowedValues")
    
      (setq strProperty (vla-get-propertyname objDynamic))
      (/= strProperty "Origin"); <- Redundant Origin Property Removed
      (wcmatch (strcase strProperty)(strcase strWCProperty))
      (or (not (setq lstAllowedValues (vlax-get objDynamic "AllowedValues")))
          (member Value lstAllowedValues)
      )
      (setq varOldValue (vlax-get-property objDynamic "Value"))
      (setq intVariantType (vlax-variant-type varOldValue))
      (errortrap (quote (vlax-put-property objDynamic 
                                             "Value" 
                                             (vlax-make-variant Value 
                                              intVariantType)))
      )
      (equal (vlax-get-property objDynamic "Value")
             (vlax-make-variant Value intVariantType)
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to trap lisp errors (returns T or value for success and nil for failure)
    ;___________________________________________________________________________________________________________|
    
    
    (defun ErrorTrap (symFunction / objError result X9)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (X9)(set X9 (eval symFunction)))
                          (list 'result))))
      nil
      (if result result 'T)
     )
    )
    
    ; Function that converts a Value into a corresponding variant example.
    
    (defun VariantMake (varOldValue Value / intVariantType)
     (if (and
          (= (type varOldValue) 'variant)
          (= (type (vlax-variant-value varOldValue))
             (type Value)
          )
          (setq intVariantType (vlax-variant-type varOldValue))
         )
      (vlax-make-variant Value intVariantType) 
     ) 
    )
    
    
    
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2015-02-04 at 10:32 AM.
    AutomateCAD

Similar Threads

  1. Dynamic Block Attribute Control Issue
    By CAD-MAN II in forum Dynamic Blocks - Technical
    Replies: 4
    Last Post: 2011-05-19, 07:56 PM
  2. Layer Props dialog control?
    By awarren in forum AutoCAD Customization
    Replies: 8
    Last Post: 2008-11-10, 03:49 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. Wanted! Dynamic Steel Angle
    By Chris.N in forum Dynamic Blocks - Technical
    Replies: 16
    Last Post: 2006-12-13, 03:46 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
  •