Dimensions extract of a dynamic block

Dimensions extract of a dynamic block

tarin_lc
Participant Participant
656 Views
6 Replies
Message 1 of 7

Dimensions extract of a dynamic block

tarin_lc
Participant
Participant

Hello everyone,
I'm trying to create a command that can extract X and Y distance information from a dynamic block. This information can be found in the properties of the block under the names "Distance" and "Distance1" giving the size of the dynamic block. To find this block, I've been advised to use the command (vla-get-effectiveName item) instead of (vla-get-Name item). Would there be a similar command allowing me to extract the x and y dimensions of the block please?
Then, with these distances, I'd like a custom paper format for printing to be directly adapted to these data.
I hope I've made my request clear...
Thanks in advance!

 

Translated with DeepL.com (free version)

0 Likes
657 Views
6 Replies
Replies (6)
Message 2 of 7

devitg
Advisor
Advisor

@tarin_lc   please upload your sample dwg 

Message 3 of 7

Sea-Haven
Mentor
Mentor

Like devitg post a dwg.

 

When using a dynamic block it becomes known as "Uxx" etc as a name so you need to get blocks then check their effective name for a match, then you can get "distance" and "distance1".  I use lee-mac get dynamic block properties.lsp as the Bricscad I use does not support the getproperty shortcut.

 

Sounds like your using it for a title block. Yes can then do a custom plot.lsp.

 

Example not full code.

(setq ss (ssget '((0 . "INSERT"))))
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq bname (vlax-get obj 'effectivename))
(if (= bname "Cartouche_dynamique")
get distance & distance1
do something
etc etc
) ; repeat

 

0 Likes
Message 4 of 7

EnM4st3r
Advocate
Advocate

i dont understand, why would you need the effiective name to get individual dynamic block information. Because the indidividual BlockReference information is not stored in the original Block definition is it?

Edit: Ah, the effectiveName is only to check for the Match, makes sense

I thougth you would need to go with

 

 

 

(vlax-safearray->list (vlax-variant-value (vla-getdynamicblockproperties obj)))
;foreach item vla-get-value
;....

 

 

 

where obj is the blockreference.
Maybe also use vla-get-PropertyName to filter only the wanted properties out ("Distance", "Distance1").

0 Likes
Message 5 of 7

EnM4st3r
Advocate
Advocate

so i thougth to get the dynamic properties like this:

(defun c:getdynamicprop (/ obj props)
  (setq obj (vlax-ename->vla-object (car (entsel))))
  (setq props (vl-remove nil
                (mapcar '(lambda (propObj / pname)
                          (setq pname (vla-get-propertyname propObj))             
                          (if (wcmatch pname "Dist*") ; filter for propertyname
                            (cons pname (vlax-variant-value (vla-get-value propObj)))
                          )
                        )
                        (vlax-safearray->list (vlax-variant-value (vla-getdynamicblockproperties obj)))
                )
              )
  )
)
0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant

Well, following this visual lisp road you've started, which might not be the simplest, you might take the shortcut and look here to Lee's public library.

 

https://lee-mac.com/dynamicblockfunctions.html

 

Then it's simple...

 

(defun c:find_block ( / acad doc layouts block layout-names pos x y dx dy)
  (vl-load-com)
  (setq acad (vlax-get-acad-object))
  (setq doc (vla-get-ActiveDocument acad))
  (setq layouts (vla-get-Layouts doc))
  (setq block nil)
  (setq layout-names (list (getvar 'ctab))) ;; current layout/model
  (vlax-for layout layouts
    (if (member (vla-get-Name layout) layout-names)
      (vlax-for item (vla-get-Block layout)
	(if (= (vla-get-ObjectName item) "AcDbBlockReference")
	  (if (or (= (vla-get-Name item) "BL_lum")
		  (= (vla-get-effectiveName item) "BL_lum")
		  )
	    (setq block item)
	    )
	  )
	)
      )
    )
  (if block
    (progn
      (setq pos (vlax-get block 'InsertionPoint))
      (setq x (car pos))
      (setq y (cadr pos))
      (princ (strcat "\nX: " (rtos x 2 4) "\nY: " (rtos y 2 4)))
      
      (if (and (setq dx (LM:getdynpropvalue block "Position1 X"))
	       (setq dy (LM:getdynpropvalue block "Position1 Y"))
	       )
	(princ (strcat "\nDX: " (rtos dx 2 4) "\nDY: " (rtos dy 2 4)))
	
	
	
	)
      )
    (alert "Bloc dynamique 1 non trouvé dans les layouts spécifiés.")
    )
  (princ)
  
  )


;; https://lee-mac.com/dynamicblockfunctions.html

;; 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 7 of 7

Sea-Haven
Mentor
Mentor

Like BeekeeCZ you can get just the desired block in a layout by adding to the ssget filter so if looping through multiple layouts you do not need to manually select.

 

(setq ss (ssget "X" '((0 . "INSERT")(cons 410 (getvar 'ctab))))

 Then as above check for correct effective name.

0 Likes