Author Topic: Parameter ID from Block  (Read 2179 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Parameter ID from Block
« on: September 26, 2023, 05:38:54 PM »
I am hoping that someone can help me with this:

I have a Constraint Parameter in several of my blocks, in this example it is called "SIZE_1" and I want to create a leader that is not inside the block that shows its value and updates automatically.

I have managed to cobble together some code from Lee Mac that gets me most of the way there, but it returns:
%<\AcObjProp Object(%<\_ObjId 2826983275840>%).SIZE_1 \f "%lu6%qf1">%

If I manually select the object, I get:
%<\AcObjProp Object(%<\_ObjId 2826983275840>%).Parameter(692).UpdatedDistance \f "%lu2">%

Code: [Select]
;;======================================================================;;
;;  Quick Field Program  -  Lee Mac                                     ;;
;;======================================================================;;
;;                                                                      ;;
;;  Program Description                                                 ;;
;;  -------------------------------                                     ;;
;;                                                                      ;;
;;  This function is designed to enable the user to quickly create      ;;
;;  custom  programs for inserting multiple fields into a drawing.      ;;
;;                                                                      ;;
;;  This could be for use in situations in which the user is required   ;;
;;  to create many fields in a drawing, with each field referencing     ;;
;;  the same object property, and continued use of the Field Command    ;;
;;  Dialog can become tedious.                                          ;;
;;                                                                      ;;
;;  Custom programs can be created by calling the 'LM:quickfield'       ;;
;;  function with a string describing the object property to be         ;;
;;  referenced by the field; a string describing the field formatting;  ;;
;;  and an integer to determine how the field will be created.          ;;
;;                                                                      ;;
;;  When creating the custom field programs, the user is advised to     ;;
;;  first use the Field Command dialog with all settings set to create  ;;
;;  the desired field, then make note of the Field Expression           ;;
;;  displayed at the bottom of the dialog. The required QuickField      ;;
;;  parameters may then be read directly from this Field Expression.    ;;
;;                                                                      ;;
;;  Each parameter is described in more detail below.                   ;;
;;                                                                      ;;
;;======================================================================;;
;;  Notes on QuickField Parameters                                      ;;
;;======================================================================;;
;;                                                                      ;;
;;  'prop'    [STR]                                                     ;;
;;                                                                      ;;
;;  This parameter is a string describing the object property to be     ;;
;;  referenced by the field.                                            ;;
;;                                                                      ;;
;;  Example:                                                            ;;
;;  ------------------                                                  ;;
;;  Field Expression displayed in Field Command Dialog:                 ;;
;;                                                                      ;;
;;  %<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%    ;;
;;                                                                      ;;
;;  For the above expression, the object property is "Area"             ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;                                                                      ;;
;;  'format'  [STR]                                                     ;;
;;                                                                      ;;
;;  This parameter is a string describing the field formatting for the  ;;
;;  object property that is to be displayed.                            ;;
;;                                                                      ;;
;;  If no formatting is to be used, 'format' should be an empty         ;;
;;  string ("").                                                        ;;
;;                                                                      ;;
;;  Example:                                                            ;;
;;  ------------------                                                  ;;
;;  Field Expression displayed in Field Command Dialog:                 ;;
;;                                                                      ;;
;;  %<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%    ;;
;;                                                                      ;;
;;  For the above expression, the field formatting is "%lu6%qf1"        ;;
;;  This formatting string indicates that the Area property of the      ;;
;;  object will be displayed using the current units and precision in   ;;
;;  the drawing.                                                        ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;                                                                      ;;
;;  'mode'    [INT]                                                     ;;
;;                                                                      ;;
;;  This integer parameter determines how the field should be created   ;;
;;  in the drawing.                                                     ;;
;;                                                                      ;;
;;  mode = 1  :  Replace Existing Text / MText / Attribute string.      ;;
;;                                                                      ;;
;;               This mode will prompt the user to select an existing   ;;
;;               object to contain the field.                           ;;
;;                                                                      ;;
;;  mode = 2  :  Create Text Object                                     ;;
;;                                                                      ;;
;;               The user will be prompted to pick a point at which a   ;;
;;               Text Object containing the field will be created.      ;;
;;                                                                      ;;
;;  mode = 3  :  Create MText Object                                    ;;
;;                                                                      ;;
;;               This user will be prompted to pick a point at which    ;;
;;               an MText Object containing the field will be created.  ;;
;;                                                                      ;;
;;                                                                      ;;
;;======================================================================;;
;;  Example Custom Field Programs                                       ;;
;;======================================================================;;
;;                                                                      ;;
;;  Example Program #1:                                                 ;;
;;  -----------------------------------                                 ;;
;;                                                                      ;;
                                                                     
    (defun c:test1 ( ) (LM:QuickField "SIZE_1" "%lu6%qf1" 1))       
                                                                     
;;                                                                      ;;
;;  Here,                                                               ;;
;;                                                                      ;;
;;     prop   =  "Area"                                                 ;;
;;     format =  "%lu6%qf1"                                             ;;
;;     mode   =  2                                                      ;;
;;                                                                      ;;
;;  This program will hence prompt the user to select an object with    ;;
;;  the "Area" property, then prompt for a point at which to create a   ;;
;;  Text Object (mode=2) containing the field.                          ;;
;;                                                                      ;;
;;  The displayed Area will be formatted using the current settings     ;;
;;  for Units and Precision.                                            ;;
;;                                                                      ;;
;;======================================================================;;
 
;;--------------------------=={ Quick Field }==-------------------------;;
;;                                                                      ;;
;;  Creates a field using the method encoded by the 'mode' argument,    ;;
;;  using the supplied field property and format strings.               ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2011  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;  prop    -  Object Property to link to field (e.g. "Area")           ;;
;;  format  -  Field formatting string (use "" for none)                ;;
;;  mode    -  Integer to determine how the field is created            ;;
;;                                                                      ;;
;;             mode=1 : Replace Existing Text, MText, Attribute         ;;
;;             mode=2 : Create Text Object                              ;;
;;             mode=3 : Create MText Object                             ;;
;;----------------------------------------------------------------------;;
;;  Returns:  -None-                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2012-04-20                                      ;;
;;                                                                      ;;
;;  - First release.                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.2    -    2015-10-10                                      ;;
;;                                                                      ;;
;;  - Program updated to account for selection of annotation objects    ;;
;;    which already contain a field expression.                         ;;
;;----------------------------------------------------------------------;;
;;  Version 1.3    -    2016-04-10                                      ;;
;;                                                                      ;;
;;  - Program updated to incorporate UPDATEFIELD command when inserting ;;
;;    a field into attribute content.                                   ;;
;;----------------------------------------------------------------------;;
 
(defun LM:quickfield ( prop format mode / ent ins obj str ) 
    (if (setq str (LM:quickfield:constructfieldstring prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:quickfield:selectifhasprop "Textstring" nentsel))
                    (progn
                        (setq obj (vlax-ename->vla-object ent))
                        (vla-put-textstring obj "") ;; To clear any existing field
                        (vla-put-textstring obj str)
                        (if (= "ATTRIB" (cdr (assoc 0 (entget ent))))
                            (vl-cmdf "_.updatefield" ent "")
                        )
                    )
                )
            )
            (   (= 2 mode)
                (if (setq ins (getpoint "\nSpecify point for text: "))
                    (vla-addtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        str (vlax-3D-point (trans ins 1 0)) (getvar 'textsize)
                    )
                )
            )
            (   (= 3 mode)
                (if (setq ins (getpoint "\nSpecify point for mtext: "))
                    (vla-addmtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        (vlax-3D-point (trans ins 1 0)) 0.0 str
                    )
                )
            )
        )
    )
    (princ)
)
 
(defun LM:quickfield:selectifhasprop ( prop func / ent )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (func (strcat "\nSelect object with " prop " property: "))))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                    (princ (strcat "\nSelected object does not have " prop " property."))
                )
            )
        )
    )
    ent
)
 
(defun LM:quickfield:acdoc nil
    (eval (list 'defun 'LM:quickfield:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:quickfield:acdoc)
)
 
(defun LM:quickfield:constructfieldstring ( prop format / ent dynProps dynProp ParamID)
    ;;Based off of:
  ;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

(defun BDG_GetProp ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) x))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)
    (setq ent (car (entsel (strcat "\nSelect object with " prop " property: "))))
    (setq dynProp (BDG_GetProp (vlax-ename->vla-object ent) prop))
    (if dynProp ; If the dynamic property was found
      (progn
        (BDG_Checker (vla-get-propertyname dynProp) nil)
        (if (and dynProp paramId) ; If the dynamic property and parameter ID were found
            (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                (if (vlax-method-applicable-p    (vla-get-utility (LM:quickfield:acdoc)) 'getobjectidstring)
                    (vla-getobjectidstring (vla-get-utility (LM:quickfield:acdoc)) (vlax-ename->vla-object ent) :vlax-false)
                    (itoa (vla-get-objectid (vlax-ename->vla-object ent)))
                )
                ">%).Parameter(" (itoa paramId) ").UpdatedDistance"
                (if (/= "" format) (strcat " \\f \"" format "\">%") ">%")
            )
        )
      )
    )
)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

kozmos

  • Newt
  • Posts: 114
Re: Parameter ID from Block
« Reply #1 on: September 27, 2023, 10:51:42 AM »
can you share the dynamic block?
KozMos Inc.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Parameter ID from Block
« Reply #2 on: September 27, 2023, 11:01:26 AM »
This is one of many dynamic blocks, but sure.

steve.carson

  • Newt
  • Posts: 108
Re: Parameter ID from Block
« Reply #3 on: September 27, 2023, 11:26:16 AM »
Have you tried calling Lee's function like this?

Code - Auto/Visual Lisp: [Select]
  1. (LM:QuickField "Parameter(692).UpdatedDistance" "%lu2" 1)
  2.  

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Parameter ID from Block
« Reply #4 on: September 27, 2023, 11:45:33 AM »
Have you tried calling Lee's function like this?

Code - Auto/Visual Lisp: [Select]
  1. (LM:QuickField "Parameter(692).UpdatedDistance" "%lu2" 1)
  2.  
But the parameter may not always be 692, it is in this case, but another block it may be 873 or whatever, I need it based on the name of the parameter called SIZE_1 in this instance.

steve.carson

  • Newt
  • Posts: 108
Re: Parameter ID from Block
« Reply #5 on: September 27, 2023, 12:03:22 PM »
If SIZE_1 is a variable that that contains "Parameter(###).UpdatedDistance", then have you tried calling Lee's function like this?

Code - Auto/Visual Lisp: [Select]
  1. (LM:QuickField SIZE_1 "%lu2" 1)
  2.  

Note that I just took the quotes off the SIZE_1 variable. Keep in mind I'm no expert on fields, just trying to help troubleshoot your issue.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Parameter ID from Block
« Reply #6 on: September 27, 2023, 01:20:18 PM »
Unfortunately, all that does is treat SIZE_1 like a variable with a nil setting.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Parameter ID from Block
« Reply #7 on: September 27, 2023, 07:33:00 PM »
With an assist from some google searches and ChatGPT, I have come up with a setup that works, but I am sure improvements can be made:

Code: [Select]
;;======================================================================;;
;;  Quick Field Program  -  Lee Mac                                     ;;
;;======================================================================;;
;;                                                                      ;;
;;  Program Description                                                 ;;
;;  -------------------------------                                     ;;
;;                                                                      ;;
;;  This function is designed to enable the user to quickly create      ;;
;;  custom  programs for inserting multiple fields into a drawing.      ;;
;;                                                                      ;;
;;  This could be for use in situations in which the user is required   ;;
;;  to create many fields in a drawing, with each field referencing     ;;
;;  the same object property, and continued use of the Field Command    ;;
;;  Dialog can become tedious.                                          ;;
;;                                                                      ;;
;;  Custom programs can be created by calling the 'LM:quickfield'       ;;
;;  function with a string describing the object property to be         ;;
;;  referenced by the field; a string describing the field formatting;  ;;
;;  and an integer to determine how the field will be created.          ;;
;;                                                                      ;;
;;  When creating the custom field programs, the user is advised to     ;;
;;  first use the Field Command dialog with all settings set to create  ;;
;;  the desired field, then make note of the Field Expression           ;;
;;  displayed at the bottom of the dialog. The required QuickField      ;;
;;  parameters may then be read directly from this Field Expression.    ;;
;;                                                                      ;;
;;  Each parameter is described in more detail below.                   ;;
;;                                                                      ;;
;;======================================================================;;
;;  Notes on QuickField Parameters                                      ;;
;;======================================================================;;
;;                                                                      ;;
;;  'prop'    [STR]                                                     ;;
;;                                                                      ;;
;;  This parameter is a string describing the object property to be     ;;
;;  referenced by the field.                                            ;;
;;                                                                      ;;
;;  Example:                                                            ;;
;;  ------------------                                                  ;;
;;  Field Expression displayed in Field Command Dialog:                 ;;
;;                                                                      ;;
;;  %<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%    ;;
;;                                                                      ;;
;;  For the above expression, the object property is "Area"             ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;                                                                      ;;
;;  'format'  [STR]                                                     ;;
;;                                                                      ;;
;;  This parameter is a string describing the field formatting for the  ;;
;;  object property that is to be displayed.                            ;;
;;                                                                      ;;
;;  If no formatting is to be used, 'format' should be an empty         ;;
;;  string ("").                                                        ;;
;;                                                                      ;;
;;  Example:                                                            ;;
;;  ------------------                                                  ;;
;;  Field Expression displayed in Field Command Dialog:                 ;;
;;                                                                      ;;
;;  %<\AcObjProp Object(%<\_ObjId 2129673136>%).Area \f "%lu6%qf1">%    ;;
;;                                                                      ;;
;;  For the above expression, the field formatting is "%lu6%qf1"        ;;
;;  This formatting string indicates that the Area property of the      ;;
;;  object will be displayed using the current units and precision in   ;;
;;  the drawing.                                                        ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;                                                                      ;;
;;  'mode'    [INT]                                                     ;;
;;                                                                      ;;
;;  This integer parameter determines how the field should be created   ;;
;;  in the drawing.                                                     ;;
;;                                                                      ;;
;;  mode = 1  :  Replace Existing Text / MText / Attribute string.      ;;
;;                                                                      ;;
;;               This mode will prompt the user to select an existing   ;;
;;               object to contain the field.                           ;;
;;                                                                      ;;
;;  mode = 2  :  Create Text Object                                     ;;
;;                                                                      ;;
;;               The user will be prompted to pick a point at which a   ;;
;;               Text Object containing the field will be created.      ;;
;;                                                                      ;;
;;  mode = 3  :  Create MText Object                                    ;;
;;                                                                      ;;
;;               This user will be prompted to pick a point at which    ;;
;;               an MText Object containing the field will be created.  ;;
;;                                                                      ;;
;;                                                                      ;;
;;======================================================================;;
;;  Example Custom Field Programs                                       ;;
;;======================================================================;;
;;                                                                      ;;
;;  Example Program #1:                                                 ;;
;;  -----------------------------------                                 ;;
;;                                                                      ;;
                                                                     
    (defun c:test1 ( ) (LM:QuickField "SIZE_1" "%lu6%qf1" 1))
                                                                     
;;                                                                      ;;
;;  Here,                                                               ;;
;;                                                                      ;;
;;     prop   =  "Area"                                                 ;;
;;     format =  "%lu6%qf1"                                             ;;
;;     mode   =  2                                                      ;;
;;                                                                      ;;
;;  This program will hence prompt the user to select an object with    ;;
;;  the "Area" property, then prompt for a point at which to create a   ;;
;;  Text Object (mode=2) containing the field.                          ;;
;;                                                                      ;;
;;  The displayed Area will be formatted using the current settings     ;;
;;  for Units and Precision.                                            ;;
;;                                                                      ;;
;;======================================================================;;
 
;;--------------------------=={ Quick Field }==-------------------------;;
;;                                                                      ;;
;;  Creates a field using the method encoded by the 'mode' argument,    ;;
;;  using the supplied field property and format strings.               ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2011  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;  prop    -  Object Property to link to field (e.g. "Area")           ;;
;;  format  -  Field formatting string (use "" for none)                ;;
;;  mode    -  Integer to determine how the field is created            ;;
;;                                                                      ;;
;;             mode=1 : Replace Existing Text, MText, Attribute         ;;
;;             mode=2 : Create Text Object                              ;;
;;             mode=3 : Create MText Object                             ;;
;;----------------------------------------------------------------------;;
;;  Returns:  -None-                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2012-04-20                                      ;;
;;                                                                      ;;
;;  - First release.                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.2    -    2015-10-10                                      ;;
;;                                                                      ;;
;;  - Program updated to account for selection of annotation objects    ;;
;;    which already contain a field expression.                         ;;
;;----------------------------------------------------------------------;;
;;  Version 1.3    -    2016-04-10                                      ;;
;;                                                                      ;;
;;  - Program updated to incorporate UPDATEFIELD command when inserting ;;
;;    a field into attribute content.                                   ;;
;;----------------------------------------------------------------------;;
 
(defun LM:quickfield ( prop format mode / ent ins obj str )
    (if (setq str (LM:quickfield:constructfieldstring prop format))
        (cond
            (   (= 1 mode)
                (if (setq ent (LM:quickfield:selectifhasprop "Textstring" nentsel))
                    (progn
                        (setq obj (vlax-ename->vla-object ent))
                        (vla-put-textstring obj "") ;; To clear any existing field
                        (vla-put-textstring obj str)
                        (if (= "ATTRIB" (cdr (assoc 0 (entget ent))))
                            (vl-cmdf "_.updatefield" ent "")
                        )
                    )
                )
            )
            (   (= 2 mode)
                (if (setq ins (getpoint "\nSpecify point for text: "))
                    (vla-addtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        str (vlax-3D-point (trans ins 1 0)) (getvar 'textsize)
                    )
                )
            )
            (   (= 3 mode)
                (if (setq ins (getpoint "\nSpecify point for mtext: "))
                    (vla-addmtext
                        (vlax-get-property (LM:quickfield:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        (vlax-3D-point (trans ins 1 0)) 0.0 str
                    )
                )
            )
        )
    )
    (princ)
)
 
(defun LM:quickfield:selectifhasprop ( prop func / ent )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (func (strcat "\nSelect object with " prop " property: "))))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (not (vlax-property-available-p (vlax-ename->vla-object ent) prop))
                    (princ (strcat "\nSelected object does not have " prop " property."))
                )
            )
        )
    )
    ent
)
 
(defun LM:quickfield:acdoc nil
    (eval (list 'defun 'LM:quickfield:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:quickfield:acdoc)
)


(defun LM:quickfield:constructfieldstring ( prop format / ent dynProps dynProp ParamID)
    ;;Based off of:
  ;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
;; Returns: [lst] List of allowed values for property, else nil if no restrictions

  (setq ent (car (entsel (strcat "\nSelect object with " prop " property: "))))
  (setq ParamID (BDG_GetParamID ent prop))
  (BDG_Checker ParamID nil)
  (if ParamID
    (strcat "%<\\AcObjProp Object(%<\\_ObjId "
        (if (vlax-method-applicable-p    (vla-get-utility (LM:quickfield:acdoc)) 'getobjectidstring)
            (vla-getobjectidstring (vla-get-utility (LM:quickfield:acdoc)) (vlax-ename->vla-object ent) :vlax-false)
            (itoa (vla-get-objectid (vlax-ename->vla-object ent)))
        )
        ">%).Parameter(" (itoa ParamID) ").UpdatedDistance " (if (/= "" format) (strcat " \\f \"" format "\">%") ">%")
    )
  )
)


;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

;; getDynBlockRecord
;; Returns the dynamic block record
;;
;; Argument
;; blockRef: Block reference
(defun getDynBlockRecord (blockRef / elst xDictionary blockRep repData blockRecord block)
  (if (= (cdr (assoc 0 (setq elst (entget blockRef)))) "INSERT")
    (if (and (setq xDictionary (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") elst))))
     (setq blockRep (cdr (assoc 360 (member '(3 . "AcDbBlockRepresentation") (entget xDictionary)))))
)
      (setq repData (cdr (assoc 360 (member '(3 . "AcDbRepData") (entget blockRep))))
    blockRecord (entget (cdr (assoc 340 (entget repData))))
      )
      (setq block (entget (tblobjname "block" (cdr (assoc 2 elst))))
    blockRecord (entget (cdr (assoc 330 block)))
      )
    )
  )
)


;; getDynPropParams
;; Returns a list of lists: one list for each dynamic parameter
;; (parameterType parameterName1 [parameterName2] [(valueNames ...)])
(defun BDG_GetParameterID_2 (blockRecord ParameterName / xDictionary enhancedBlock Name_1 Name_2)
  (if (and (setq xDictionary (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") blockRecord))))
   (setq enhancedBlock (cdr (assoc 360 (member '(3 . "ACAD_ENHANCEDBLOCK") (entget xDictionary)))))
      )
    (vl-remove
      nil
      (mapcar
'(lambda (pair / elst)
   (setq elst  (entget (cdr pair))
param (cdr (assoc 0 elst))
   )
       (if (setq Name_1 (cdr (assoc 300 elst)))
         (setq Name_1 (strcase Name_1))
       )
       (if (setq Name_2 (cdr (assoc 305 elst)))
         (setq Name_2 (strcase Name_2))
       )
       (setq ParameterName (strcase ParameterName))
        (if (or (= Name_1 ParameterName) (= Name_2 ParameterName))
          (setq Result (cdr (assoc 90 elst)))
        )
)
(vl-remove-if-not
  '(lambda (x) (= (car x) 360))
  (entget enhancedBlock)
)
      )
    )
  )
  Result
)

(defun BDG_GetParamID (Ent ParameterName / ent blockRec)
  (setq Results nil)
  (if (and ent
   (setq blockRec (getDynBlockRecord ent))
      )
    (setq Results (BDG_GetParameterID_2 blockRec ParameterName))
  )
  Results
)

kozmos

  • Newt
  • Posts: 114
Re: Parameter ID from Block
« Reply #8 on: September 28, 2023, 09:53:07 AM »
My version, I have converted the indice into string so can directly strcat:
Code - Auto/Visual Lisp: [Select]
  1. (Defun GetUpdatedParameterIndex (blk / RTN OTT)
  2.   (foreach abc
  3.            (vl-remove-if-not
  4.              (function (lambda (x) (= (car x) 360)))
  5.              (dictsearch
  6.                (cdr
  7.                  (assoc
  8.                    360
  9.                    (entget
  10.                      (cdr
  11.                        (assoc 330
  12.                               (entget (tblobjname
  13.                                         "block"
  14.                                         (vla-get-effectivename
  15.                                           (vlax-ename->vla-object blk)
  16.                                         )
  17.                                       )
  18.                               )
  19.                        )
  20.                      )
  21.                    )
  22.                  )
  23.                )
  24.                "acad_enhancedblock"
  25.              )
  26.            )
  27.     (setq abc (entget (cdr abc))
  28.           ott (cdr (assoc 0 abc))
  29.           ott (cdr (assoc (if (= ott "BLOCKVISIBILITYPARAMETER")
  30.                             301
  31.                             305
  32.                           )
  33.                           abc
  34.                    )
  35.               )
  36.           rtn (cons (cons (if ott
  37.                             ott
  38.                             (cdr (assoc 300 abc))
  39.                           )
  40.                           (itoa (cdr (assoc 90 abc)))
  41.                     )
  42.                     rtn
  43.               )
  44.     )
  45.   )
  46.   rtn
  47. )
  48.  
  49. Example:
  50. _$ (GETUPDATEDPARAMETERINDEX (car (entsel)))
  51. (("Move1" . "163") ("UpdatedEndY" . "162") ("UpdatedEndX" . "161") ("End Grip" . "160") ("Z" . "159") ("Stretch5" . "158") ("UpdatedEndY" . "157") ("UpdatedEndX" . "156") ("End Grip" . "155") ("ZH" . "154") ("Stretch4" . "153") ("Stretch3" . "148") ("Array4" . "147") ("Distance5" . "143") ("Array1" . "142") ("Distance3" . "138") ("Array8" . "137") ("Array2" . "136") ("Array" . "135") ("Distance2" . "130") ("Array7" . "129") ("Distance1" . "125") ("Array3" . "84") ("Distance4" . "80") ("Move" . "73") ("Stretch2" . "72") ("Stretch1" . "71") ("UpdatedEndY" . "70") ("UpdatedEndX" . "69") ("End Grip" . "68") ("X2" . "67") ("Stretch" . "50") ("UpdatedEndY" . "49") ("UpdatedEndX" . "48") ("End Grip" . "47") ("Y" . "46") ("UpdatedY" . "4") ("UpdatedX" . "3") ("Grip" . "2") ("VIS" . "1"))
  52. _$
  53.  

KozMos Inc.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Parameter ID from Block
« Reply #9 on: September 28, 2023, 06:45:06 PM »
Thank you, that works quite well.

ETA:
I just realized I almost ended up using your code for fields from: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-field-linked-object/m-p/1829333/highlight/true#M228109 as a starting point instead of Lee Mac's version....small world.
« Last Edit: September 28, 2023, 07:23:50 PM by cmwade77 »