Lisp to perform an INSERT similar to ADDSELECTED

I couldn't figure out how the native "ADDSELECTED" command works in BricsCAD. I posted about it over in the BIM section.

I decided to write a simple Lisp that works for what I need. (Effectively doing the equivalent of an 'addselected', without the odd behavior.) This code will check for nil clicks as well as not run on anything that's not a simple door or window. Will fail on any door/window that doesn't have the H~MCAD and W~MCAD properties.

(defun c:as ( / keeplooping entity effectivetype effectivename height width)

(setq keeplooping "yes")
(while (= keeplooping "yes")
(if (/= (setq entity (entsel "Click a door or window to add another like it:")) nil)(setq keepLooping "no"))
);end while
(setq entity (car entity))
(setq effectiveType (getpropertyvalue entity "EffectiveType~Native"))
(if (or (= effectiveType "Door") (= effectiveType "Window"))
(progn
(setq effectiveName (getpropertyvalue entity "EffectiveName~Native"))
(setq height (getpropertyvalue entity "H~MCAD"))
(setq width (getpropertyvalue entity "W~MCAD"))
(command "-insert" effectiveName "_R" 0.0 "_S" 1.0 "E" "W" width "H" height "FINISH" )
);end progn
(progn
(alert "Not a Door or Window");comment this out if annoying
(print "Not a Door or Window")
);end progn
);endif
);end as

I have two questions:

1 - in regards to a BIM dump - is there a way to check if a propertyvalue exists before trying to issue a "getpropertyvalue"?

2 - Has someone documented a good way to show code in the forums? The right-click "format as inline code" doesn't appear to support indenting.

Comments

  • ALANH
    edited June 16

    I use Dumpit.lsp for properties and dumpall.

    ;;;===================================================================;
    ;;; DumpIt ;
    ;;;-------------------------------------------------------------------;
    ;;; Dump all methods and properties for selected objects ;
    ;;;===================================================================;
    (defun C:Dumpit ( / ent)
    (while (setq ent (entsel "\n pick object "))
    (vlax-Dump-Object
    (vlax-Ename->Vla-Object (car ent))
    )
    )
    (princ)
    )

    ;(dumpallproperties (car (entsel)))

    There is a check (if (= (vla-get-hasattributes obj) :vlax-true) check a block has attributes. Or (vlax-property-available-p obj "hasattributes") not sure if it helps for your objects don't have BIM.

    Most other forums have <> or ## for code.

    (setq height (getpropertyvalue entity "H~MCAD"))
    (setq width (getpropertyvalue entity "W~MCAD"))
    (if (or (= width nil)(= height nil))
    (progn (alert "No height or wdith available wil now exit ")(exit))
    (command "-insert" effectiveName "_R" 0.0 "_S" 1.0 "E" "W" width "H" height "FINISH" )
    )

  • Thanks for the response!

    The problem is that when I issue:

    (setq height (getpropertyvalue entity "H~MCAD"))

    the code will error if "entity" does not have the BIM-MCAD property value "H~MCAD".

    (vla-get-hasattributes) & (vlax-property-available-p) appear to verify if (I'm not sure the technical term) there are properties or fields that you'd sometimes find in the standard properties panel when clicking an object, such as "COLOR" or "LAYER"

    But they don't appear to be able to test if an object contains a property that only appears in the "dumpallproperties" output.

  • You may need to do a Error trap can then say stop proceeding. You will need to think about how you handle the error can add more to message say which value is missing.

    (defun trap (errmsg)
    (Alert "\nAn error has occured. \nWill now exit")
    (setq error temperr)

    (exit) ; will exit this lisp
    )

    (defun c:as ( / keeplooping entity effectivetype effectivename height width)
    (setq temperr error)
    (setq error trap)

  • After looking into it, it seems that when you change the parameters of a parametric block containing BIM objects, those blocks become unnamed, which causes ADDSELECTED to not work as expected.

    Considering how the system handles blocks with parameters, it seems best to use the Mech functions available in Pro and higher versions.

    (vl-load-mech)
    (setq ent (car (entsel)))
    (setq blkname (mech:get-effectiveblockrefname ent))
    (setq params (mech:get-componentparameternames ent))
    (foreach n params (princ (strcat n ":")) (princ (getpropertyvalue ent n)) (princ ", ")) ; check parameter value
    ; …