Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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 ?

    dwg
    dwg
    Glas-0.dwg
    25K
  • 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

    zip
    zip
    North-Source.zip
    540K
    lsp
    lsp
    AssemblyTree.lsp
    3K
    dwg
    dwg
    NorthArrow_Visibility_Example.dwg
    50K
    lsp
    lsp
    AssemblyTree.lsp
    3K
    NorthArrow.gif
    432 x 284 - 545K
  • edited September 13

    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".

Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam