Get or Set Constraints with Visual Lisp / VBA

I write applications in Visual Lisp
Until recent I used often Dynamic Blocks in my applications.
In my applications I can get and set dynamic properties of dynamic blocks with Visual Lisp [ (vla-getdynamicblockproperties obj) etc. ]

Now I switched to Bricscad and thus want to switch from Autocad's dynamic blocks to Bricscad's parametric blocks.
Is it possible to get and set parameters of parametric blocks with Visual Lisp (or VBA) ?

Comments

  • To set parameter values you can use the _-BmParameters command.

    To get parameter values you can use the bmlispget Lisp function (see the LDSP for more info).

    Note: I am using V18. Things may have changed and improved in V19.

  • Thanks Roy.
    I found the section about bmlispget but I don't know how to use the features and input arguments to get results.

    Example:
    The attached block "Glas_0" has two parameters: Width and Height.
    When I bminsert it in a drawing I would like to get it's width and height.
    The name of the block then becomes then "Component_1:1"
    A second intance will become the name Component_1:2, etc.

    Can you give a small example how to get the width and height of each inserted block ?

  • Attach an example I created a few years back

    The LISP allows you to toggle the visibility of the elements of the north arrow.

    The AssemblyTree.lsp was provided to me from a Bricsys SR. It allows you to retrieve the assembly tree of an assembly.

    Regards,
    Jason Bourhill
    BricsCAD V19 Ultimate
    Quickly create HELP links on your forum posts

    CAD Concepts

  • Roy Klein Gebbinck
    edited September 2019

    The BmLispGet function is a bit strange in that it is actually a 'container' for multiple functions. I have never understood or liked this, but it does have built-in documentation: (BmLispGet "?"). You should definitely read this as the LDSP is some 20 months old and the BmLispGet function has been updated in the meantime. In V19 the KGA_Sys_InsertInstanceHandle function in the code below can be replaced by a BmLispGet sub-function I believe.

    To help you understand the objects involved:
    As far as I know at least 5 objects are involved in the BricsCAD component mechanism. Two of those (block definition and block reference) are no doubt familiar.

    Component definition. Can be external.
      Component. This is linked to a block definition.
        Component instance. This is linked to a block reference.
    

    Code:

    (defun KGA_Sys_InsertInstanceHandle (enm / elst)
      (if
        (and
          (setq elst (cdr (member '(102 . "{ACAD_REACTORS") (entget enm))))
          (= (caar elst) 330)
          (= "BmDbComponentInstance" (vla-get-objectname (vlax-ename->vla-object (cdar elst))))
        )
        (vla-get-handle (vlax-ename->vla-object (cdar elst)))
      )
    )
    
    ; (CollectCompProps (ssget '((0 . "INSERT") (102 . "{ACAD_REACTORS"))))
    (defun CollectCompProps (ss)
      (vl-remove
        nil
        (mapcar
          '(lambda (enm / compHnd instHnd)
            (if (setq instHnd (KGA_Sys_InsertInstanceHandle enm))
              (progn
                (setq compHnd (bmlispget "Component" instHnd))
                (cons
                  (bmlispget "InstanceName" instHnd)
                  (mapcar
                    '(lambda (nme)
                      (cons nme (bmlispget "ParameterValue" compHnd nme))
                    )
                    (bmlispget "Parameters" compHnd)
                  )
                )
              )
            )
          )
          (vle-selectionset->list ss)
        )
      )
    )
    
  • As so often, thanks a lot for the insight, Roy!
    FYI: On 19.2.15 Linux, KGA_Sys_InsertInstanceHandle throws
    ; error : Automation Error DISP_E_UNKNOWNNAME; [Unknown] identifier name not recognised in [OBJECTNAME] property.

    But CollectCompProps indeed runs fine if you replace KGA_Sys_InsertInstanceHandle by bmlispget "Instance".

  • aridzv
    edited January 2022

    The BmLispGet function is a bit strange in that it is actually a 'container' for multiple functions. I have never understood or liked this, but it does have built-in documentation: (BmLispGet "?"). You should definitely read this as the LDSP is some 20 months old and the BmLispGet function has been updated in the meantime. In V19 the KGA_Sys_InsertInstanceHandle function in the code below can be replaced by a BmLispGet sub-function I believe.

    To help you understand the objects involved:

    As far as I know at least 5 objects are involved in the BricsCAD component mechanism. Two of those (block definition and block reference) are no doubt familiar.

    Component definition. Can be external.
    Component. This is linked to a block definition.
    Component instance. This is linked to a block reference.
    ....
    Hi Roy.
    I'm Trying to get the efecttivename of a parametric block,
    and I found this topic.
    I see that you have a knowledge with this issue,
    and I will be grateful if you will be able to help me with it.
    I've opened a topic here in the forum and I wonder if you could help me there.
    thanks,
    Ari.
  • Roy Klein Gebbinck
    edited January 2022
    (defun KGA_Sys_InsertComponentName (enm)
      (bmlispget "ComponentName" (bmlispget "Component" (KGA_Sys_InsertInstanceHandle enm)))
    )
    
    (defun KGA_Sys_InsertInstanceHandle (enm / elst)
      (if
        (and
          (setq elst (cdr (member '(102 . "{ACAD_REACTORS") (entget enm))))
          (= (caar elst) 330)
          (= "BmDbComponentInstance" (vla-get-objectname (vlax-ename->vla-object (cdar elst))))
        )
        (vla-get-handle (vlax-ename->vla-object (cdar elst)))
      )
    )
  • aridzv
    edited January 2022

    (defun KGA_Sys_InsertComponentName (enm)
      (bmlispget "ComponentName" (bmlispget "Component" (KGA_Sys_InsertInstanceHandle enm)))
    )
    
    (defun KGA_Sys_InsertInstanceHandle (enm / elst)
      (if
        (and
          (setq elst (cdr (member '(102 . "{ACAD_REACTORS") (entget enm))))
          (= (caar elst) 330)
          (= "BmDbComponentInstance" (vla-get-objectname (vlax-ename->vla-object (cdar elst))))
        )
        (vla-get-handle (vlax-ename->vla-object (cdar elst)))
      )
    )
    Hi Roy and thanks for the answer.
    I can't get your LSP to run,and I don't know what I'm doing wrong.
    I've tried to copy your code in to my EF lsp,and then call KGA_Sys_InsertComponentName passing the block object from my code (obj object in my code),but I get this error:
    "error : no function definition ; expected FUNCTION at [eval]"

    here is the incorporated code:

    (defun c:EF4 ( / obj1 e1 e2)
    (vl-load-com)
    (setq obj1 (car (entsel "\nSelect a object")))
    (setq obj (vlax-ename->vla-object (Car (entsel))))
    ;(print (vla-get-effectivename obj))

    (defun KGA_Sys_InsertComponentName (enm)
    (bmlispget "ComponentName" (bmlispget "Component" (KGA_Sys_InsertInstanceHandle enm)))

    )

    (defun KGA_Sys_InsertInstanceHandle (enm / elst)
    (if
    (and
    (setq elst (cdr (member '(102 . "{ACAD_REACTORS") (entget enm))))
    (= (caar elst) 330)
    (= "BmDbComponentInstance" (vla-get-objectname (vlax-ename->vla-object (cdar elst))))
    )
    (vla-get-handle (vlax-ename->vla-object (cdar elst)))
    )
    )

    (setq e1 (KGA_Sys_InsertComponentName obj1))
    (print e1)
    (print enm)
    (print elst)
    )

    **The return from EF4 Is NIL.

    and here is the LSP that I'm using and get me the anonymous blocks *U* name:

    (defun c:EF ()
    (vl-load-com)
    (setq obj (vlax-ename->vla-object (Car (entsel))))
    (print (vla-get-effectivename obj))
    (princ)
    )

    Can you help me put your code in to mine (like I tried to do in EF4.lsp), and integrate the tow of them?
    Thanks,
    Ari.
  • (defun KGA_Sys_InsertComponentName (enm)
      (bmlispget "ComponentName" (bmlispget "Component" (KGA_Sys_InsertInstanceHandle enm)))
    )
    
    (defun KGA_Sys_InsertInstanceHandle (enm / elst)
      (if
        (and
          (setq elst (cdr (member '(102 . "{ACAD_REACTORS") (entget enm))))
          (= (caar elst) 330)
          (= "BmDbComponentInstance" (vla-get-objectname (vlax-ename->vla-object (cdar elst))))
        )
        (vla-get-handle (vlax-ename->vla-object (cdar elst)))
      )
    )
    
    (defun c:print-comp-name ( / enm)
      (if (setq enm (car (entsel)))
        (print (KGA_Sys_InsertComponentName enm))
      )
      (princ)
    )
  • aridzv
    edited January 2022

    (defun KGA_Sys_InsertComponentName (enm)
      (bmlispget "ComponentName" (bmlispget "Component" (KGA_Sys_InsertInstanceHandle enm)))
    )
    
    (defun KGA_Sys_InsertInstanceHandle (enm / elst)
      (if
        (and
          (setq elst (cdr (member '(102 . "{ACAD_REACTORS") (entget enm))))
          (= (caar elst) 330)
          (= "BmDbComponentInstance" (vla-get-objectname (vlax-ename->vla-object (cdar elst))))
        )
        (vla-get-handle (vlax-ename->vla-object (cdar elst)))
      )
    )
    
    (defun c:print-comp-name ( / enm)
      (if (setq enm (car (entsel)))
        (print (KGA_Sys_InsertComponentName enm))
      )
      (princ)
    )
    Hi Roy,and Thanks for the quick reply!!
    Still getting NIL..
    I'm attaching a sample drawing with 2 parametric blocks inserted.
    one block is before changing its parameters,
    and the other is the problematic one - after changing..

    Thanks,
    Ari.
  • I am using BricsCAD V18. The data structure for parametric components has apparently changed since then. So I am afraid I can't assist further.

    Maybe the built-in Help for the bmlispget function can provide some clues:
    (bmlispget "?")
  • I am using BricsCAD V18. The data structure for parametric components has apparently changed since then. So I am afraid I can't assist further.

    Thanks In any case for your help.
    I sent a support request on that issue,hope it will help...

    Maybe the built-in Help for the bmlispget function can provide some clues:
    (bmlispget "?")

    I've looked on it,It is a long list.... but I will definitely take the time to check it - Thanks!!
    Ari.