- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I made this simple routine to set the scale in my dynamic scale block. I used some Lee Mac's routines for the dynamic block, so thanks to him for all the hard work.
I am having two problems, and your help will be very appreciated.
First problem: If the scale of the viewport is less than 10 (like 1, 2, 2.5, etc) the block does not change its scale. I tried but I did not found the way to solve this.
Second problem, If I have more than one viewport in the same layout, the block will be set to the scale of the first viewport drawn. So, I think in that case, it will be necessary to make a list with the viewports scales, and then compare the scales in that list. If they are different, (setq ss1 "INDIQUÉE") and (setq vis "INDIQUÉE"). If they are equals, take the scale value and put to ss1.
If you can help, or If you have a better way, I will be thankful. 🙂
See attached my scale block.
(defun c:VS (/ retab ss ss1) (setq retab (getvar 'CTAB)) (foreach layout (layoutlist) (setvar "ctab" layout) (if (and (= (getvar "tilemode") 0) (= (getvar "cvport") 1) (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 layout)))) );and (setq ss1 (rtos (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (ssname ss 0)))) 2 0)) );if (cond ((= (sslength ss) 1) (setq vis "AUCUNE") (MS:ChangeVisibility vis)) ;Without viewport ((> (sslength ss) 1) ;With viewport (cond ((= ss1 "1") (setq vis "1:1") (MS:ChangeVisibility vis)) ;Problem here ((= ss1 "2") (setq vis "1:2") (MS:ChangeVisibility vis)) ;Problem here ((= ss1 "2.5") (setq vis "1:2.5") (MS:ChangeVisibility vis)) ;Problem here ((= ss1 "3") (setq vis "1:3") (MS:ChangeVisibility vis)) ;Problem here ((= ss1 "5") (setq vis "1:5") (MS:ChangeVisibility vis)) ;Problem here ((= ss1 "7.5") (setq vis "1:7.5") (MS:ChangeVisibility vis)) ;Problem here ((= ss1 "10") (setq vis "1:10") (MS:ChangeVisibility vis)) ((= ss1 "15") (setq vis "1:15") (MS:ChangeVisibility vis)) ((= ss1 "20") (setq vis "1:20") (MS:ChangeVisibility vis)) ((= ss1 "25") (setq vis "1:25") (MS:ChangeVisibility vis)) ((= ss1 "30") (setq vis "1:30") (MS:ChangeVisibility vis)) ((= ss1 "40") (setq vis "1:40") (MS:ChangeVisibility vis)) ((= ss1 "50") (setq vis "1:50") (MS:ChangeVisibility vis)) ((= ss1 "75") (setq vis "1:75") (MS:ChangeVisibility vis)) ((= ss1 "100") (setq vis "1:100") (MS:ChangeVisibility vis)) ((= ss1 "125") (setq vis "1:125") (MS:ChangeVisibility vis)) ((= ss1 "150") (setq vis "1:150") (MS:ChangeVisibility vis)) ((= ss1 "200") (setq vis "1:200") (MS:ChangeVisibility vis)) ((= ss1 "250") (setq vis "1:250") (MS:ChangeVisibility vis)) ((= ss1 "300") (setq vis "1:300") (MS:ChangeVisibility vis)) ((= ss1 "350") (setq vis "1:350") (MS:ChangeVisibility vis)) ((= ss1 "400") (setq vis "1:400") (MS:ChangeVisibility vis)) ((= ss1 "500") (setq vis "1:500") (MS:ChangeVisibility vis)) ((= ss1 "600") (setq vis "1:600") (MS:ChangeVisibility vis)) ((= ss1 "750") (setq vis "1:750") (MS:ChangeVisibility vis)) ((= ss1 "1000") (setq vis "1:1000") (MS:ChangeVisibility vis)) ((= ss1 "2000") (setq vis "1:2000") (MS:ChangeVisibility vis)) ((= ss1 "2500") (setq vis "1:2500") (MS:ChangeVisibility vis)) );cond ) );cond );foreach (setvar "ctab" retab) (princ) ) ;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-visibility-states-in-dynamic-block/td-p/5322263 (defun MS:ChangeVisibility (vis / blk idx obj sel ) (setq blk "Tx - Échelle Métrique - Français") (if (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," blk)) (cons 410 (getvar "CTAB"))))) (repeat (setq idx (sslength sel)) (if (= (strcase blk) (strcase (LM:blockname (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))))) (LM:SetVisibilityState obj vis) ) ) ) (princ) ) ;; Block Name - Lee Mac ;; Returns the true (effective) name of a supplied block reference (defun LM:blockname ( obj ) (if (vlax-property-available-p obj 'effectivename) (defun LM:blockname ( obj ) (vla-get-effectivename obj)) (defun LM:blockname ( obj ) (vla-get-name obj)) ) (LM:blockname obj) ) ;; 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) ) ) ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;; Get Dynamic Block Property Allowed Values - Lee Mac ;; Returns the allowed values for a specific Dynamic Block property. ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; Returns: [lst] List of allowed values for property, else nil if no restrictions (defun LM:getdynpropallowedvalues ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues))) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;; 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))) ) )
Thanks
Marcelo
Solved! Go to Solution.