Insert multiple blocks based on single client input

Insert multiple blocks based on single client input

werner.bianca
Contributor Contributor
844 Views
5 Replies
Message 1 of 6

Insert multiple blocks based on single client input

werner.bianca
Contributor
Contributor

Good afternoon!
I'm back with more questions.
My newer lisp project is based on detail drawing that have multiple dimensions involved.
Now the dimensions base we use are not set to a perfect scale. So they are not ordinary dims.
However I made a block out of them. A dynamic block that has all dimensions included in it separated by visibility states, one for each dimension for height and length.
But since each detail drawing most likely having multiple dimensions including multiple heights (74 variations) and lengths (46 variations) it becomes too complicated to set up variations in the visibility states.
My plan is to have a lisp to insert that single dynamic block multiple times but at different visibility states based on user input.
That would be set up with two repeating client get int.
First one for Heights, 0 or any invalid input should jump to the second step, Lengths, 0 or any invalid input would then insert all selected heights and lengths selected by client at a insertion point selected by client, rotation 0 and explode all blocks inserted.

I found this post about Inserting Dynamic Block with Visibility State Pre-selected here as a good starting point, but haven't figured out a way to insert multiple blocks based upon one (actually two) looping client input and most important aspect of this question, a single insertion point selection.


Any help would be greatly appreciated 🙂

0 Likes
845 Views
5 Replies
Replies (5)
Message 2 of 6

werner.bianca
Contributor
Contributor

Follows attached the DWG with the dynamic block mentioned above

0 Likes
Message 3 of 6

Sea-Haven
Mentor
Mentor

If you get a copy of www.lee-mac.com  dynamic block lisp it has the code in it to update your block dynamic values

 

 (LM:setdynpropvalue  blk prp val ) vl-block-selected dynvaraiablename value

 

 (LM:setdynpropvalue  BLK "dims" "21 H")

 

 

Message 4 of 6

werner.bianca
Contributor
Contributor

I'm struggling trying to apply LM's lisp even to just simply insert one block with pre-selected visual state. 😓
I want to be able to select the state during the insertion command.
The plan was to actually start the command with picking the insertion point, then enter as a list of states to be used(10, 22, 23, 28, 31, 34 for example enter after every entry and end it by hitting enter twice). Then insert all the heights selected. I'm separating it so its one command for inserting the height and another for the length. Specially since the heights are named "21 H" and the lengths "21 L". But a figure a concatenate could put together the name of the block visual state. Still would need to make a list based on used input before inserting the blocks in the visual state associated list based on user entry.

0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant

First, HERE is direct lint to Lee's dynblock library.

And here is short example of usage:

 

(defun c:ShortExample ()
  
  (command-s "_.insert" "MyDynamicBlock")
  (LM:SetVisibilityState (vlax-ename->vla-object (entlast)) "MyTheMostFavouriteVisibilityState")
  (princ)

  )

;       ----------------------------------------------------------------------------------------------  

;; http://www.lee-mac.com/dynamicblockfunctions.html#setvisibilitystate


;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; blk - [vla] VLA Dynamic Block Reference object
;; val - [str] Visibility State Parameter value
;; Returns: [str] New value of Visibility Parameter, else nil

(defun LM:SetVisibilityState ( blk val / vis )
    (if
        (and
            (setq vis (LM:getvisibilityparametername blk))
            (member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)))
        )
        (LM:setdynpropvalue blk vis val)
    )
)

;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil

(defun LM:getvisibilityparametername ( blk / vis )  
    (if
        (and
            (vlax-property-available-p blk 'effectivename)
            (setq blk
                (vla-item
                    (vla-get-blocks (vla-get-document blk))
                    (vla-get-effectivename blk)
                )
            )
            (= :vlax-true (vla-get-isdynamicblock blk))
            (= :vlax-true (vla-get-hasextensiondictionary blk))
            (setq vis
                (vl-some
                   '(lambda ( pair )
                        (if
                            (and
                                (= 360 (car pair))
                                (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
                            )
                            (cdr pair)
                        )
                    )
                    (dictsearch
                        (vlax-vla-object->ename (vla-getextensiondictionary blk))
                        "ACAD_ENHANCEDBLOCK"
                    )
                )
            )
        )
        (cdr (assoc 301 (entget vis)))
    )
)

;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

(defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
        (vlax-invoke blk 'getdynamicblockproperties)
    )
)
0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

A bit more on Beekeecz

 

(setq lst '(10 22 23 28 31 34))
(command-s "_.insert" "MyDynamicBlock")
(repeat (setq x (length lst))
  (LM:SetVisibilityState (vlax-ename->vla-object (entlast)) (nth (setq x (- x 1) lst)))
  (princ)
)

 

0 Likes