Viewport Scale

Viewport Scale

msarqui
Collaborator Collaborator
3,660 Views
17 Replies
Message 1 of 18

Viewport Scale

msarqui
Collaborator
Collaborator

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

0 Likes
Accepted solutions (1)
3,661 Views
17 Replies
Replies (17)
Message 2 of 18

hmsilva
Mentor
Mentor

Hi Marcelo,
just for debugging, if you select a viewport with

 

(rtos (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (car (entsel))))) 2 0)


what's the return?

 

Henrique

EESignature

0 Likes
Message 3 of 18

msarqui
Collaborator
Collaborator
Hi Henrique,
It returns...
"1" for scale 1:1
"2" for scale 1:2
"3" for scale 1:2.5
"8" for scale 1:7.5
"100" for scale 1:100
...
0 Likes
Message 4 of 18

hmsilva
Mentor
Mentor

Did you test it?

Is it possible to attach a sample dwg with a few layouts and viewports?

 

Henrique

EESignature

0 Likes
Message 5 of 18

msarqui
Collaborator
Collaborator

Here it goes...

Let me know if you need something more 🙂

0 Likes
Message 6 of 18

hmsilva
Mentor
Mentor

Marcelo, try this quickly revised code

 

(defun c:VS (/ retab ss ss1)
    (setq retab (getvar 'CTAB))
    (foreach layout (layoutlist) ;(setq layout "G02")
        (setvar "ctab" layout)
        (if (and (= (getvar "tilemode") 0)
                 (= (getvar "cvport") 1)
                 (setq ss (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 layout) (cons -4 "!=") (cons 69 1))))
                 (setq ss1 (rtos (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (ssname ss 0)))) 2 0))
            ) ; and
            (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
            (MS:ChangeVisibility "AUCUNE") ;Without viewport
        ) ; if
    ) ;foreach
    (setvar "ctab" retab)
    (princ)
)

 ;https://forums.autodesk.com/t5/visual-lisp-autoli?sp-and-general/changing-visibility-states-in-dynam?ic-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)))
    )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 7 of 18

msarqui
Collaborator
Collaborator

Henrique,
Tested in my sample and:
Page G03 not working. In case of multiple viewports with different scales we need to put the scale block to "INDIQUÉE" (it means AS SHOWN in english, because I will add later a specific scale bar for each viewport). So, in this case, (setq ss1 "INDIQUÉE"). 
Page G05 not working. If the scale of the viewport is not on the routine's list, put the scale block to "AUCUNE" (It means NONE in english). So in this case,(setq ss1 "AUCUNE")

Also, scales 1:1, 1:2, 1:2.5, 1:3... (lower than 1:10) are not working. Attached a new sample with viewports in those scales.

Thanks!!!

0 Likes
Message 8 of 18

hmsilva
Mentor
Mentor

@msarqui wrote:

Henrique,
Tested in my sample and:
Page G03 not working. In case of multiple viewports with different scales we need to put the scale block to "INDIQUÉE" (it means AS SHOWN in english, because I will add later a specific scale bar for each viewport). So, in this case, (setq ss1 "INDIQUÉE"). 
Page G05 not working. If the scale of the viewport is not on the routine's list, put the scale block to "AUCUNE" (It means NONE in english). So in this case,(setq ss1 "AUCUNE")

Also, scales 1:1, 1:2, 1:2.5, 1:3... (lower than 1:10) are not working. Attached a new sample with viewports in those scales.

Thanks!!!


Marcelo,

in your original code, you don't have 'tests' for those situations... later, I'll see what I can do.

 

Henrique

EESignature

0 Likes
Message 9 of 18

ВeekeeCZ
Consultant
Consultant

@msarqui wrote:

...

Also, scales 1:1, 1:2, 1:2.5, 1:3...... are not working. Attached a new sample with viewports in those scales.

 


Look inside your block, there is no such VISIBILITY STATES defined.

 

And some other notes:

 

Spoiler
;Make sure that DIMZIN variable have correct value... if you're using rtos and the the result for later comparation
(setq ss1 (rtos (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (ssname ss 0)))) 2 0))


; I would prefer keep numpers as far as possible: 
(setq ss1 (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (ssname ss 0)))))


; Then these two lines...
(if (member ssi '(1 2 2.5 3 5 7.5 10 15 20 25 30 40 50 75 100 125 150 200 250 300 350 400 500 600 750 1000 2000 2500))
  (MS:ChangeVisibility (strcat "1:" (rtos ss1 2 0))))


; ... can replace whole these....
(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

 

0 Likes
Message 10 of 18

msarqui
Collaborator
Collaborator

Well... I am reeeealy embarrassed     Smiley Embarassed

 

I started this post at home and continued at work, so I took the wrong block here.
Attached the new file with the right block.
But still... In the Henrique's code, if the viewport scale is 1:2.5, the block change to 1:3

 

I will give a try on yours BeekeeCZ 

 

Thanks!

0 Likes
Message 11 of 18

ВeekeeCZ
Consultant
Consultant

@msarqui wrote:

...

 if the viewport scale is 1:2.5, the block change to 1:3

...


If you descibe your problem like this, then is the reason obvious. (and I copycat the same)

 

; Then these two lines...
(if (member ssi '(1 2 2.5 3 5 7.5 10 15 20 25 30 40 50 75 100 125 150 200 250 300 350 400 500 600 750 1000 2000 2500))
  (MS:ChangeVisibility (strcat "1:" (rtos ss1 2 1))))

 

0 Likes
Message 12 of 18

msarqui
Collaborator
Collaborator
This change will bug the scales higher than 1:10
I think we need to find the middle term between one and two digits.
0 Likes
Message 13 of 18

hmsilva
Mentor
Mentor

Marcelo,

perhaps something like this

(defun c:VS (/ i lst pos retab sc ss vis)
    (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) (cons -4 "!=") (cons 69 1))))
            ) ; and
            (progn
                (setq lst nil)
                (repeat (setq i (sslength ss))
                    (setq sc  (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
                          lst (cons sc lst)
                    )
                )
                (cond ((and (vl-every (function (lambda (x) (equal x sc))) lst)
                            (setq pos (vl-position
                                          sc
                                          '(1.0     2.0     2.5     3.0     5.0     7.5     10.0    15.0    20.0    25.0    30.0    40.0    50.0    75.0
                                            100.0   125.0   150.0   200.0   250.0   300.0   350.0   400.0   500.0   600.0   750.0   1000.0  2000.0  2500.0
                                           )
                                      )
                            )
                            (setq vis (nth pos
                                           '("1:1"      "1:2"      "1:2.5"    "1:3"      "1:5"      "1:7.5"    "1:10"     "1:15"     "1:20"     "1:25"
                                             "1:30"     "1:40"     "1:50"     "1:75"     "1:100"    "1:125"    "1:150"    "1:200"    "1:250"    "1:300"
                                             "1:350"    "1:400"    "1:500"    "1:600"    "1:750"    "1:1000"   "1:2000"   "1:2500"
                                            )
                                      )
                            )
                       )
                       (MS:ChangeVisibility vis)
                      )
                      (T
                       (MS:ChangeVisibility "INDIQUÉE")
                      )
                )
            )
            (MS:ChangeVisibility "AUCUNE")
        ) ; if
    ) ;foreach
    (setvar "ctab" retab)
    (princ)
)

 ;https://forums.autodesk.com/t5/visual-lisp-autoli?sp-and-general/changing-visibility-states-in-dynam?ic-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)))
    )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 14 of 18

msarqui
Collaborator
Collaborator

@msarqui wrote:

Henrique,
Tested in my sample and:
Page G03 not working. In case of multiple viewports with different scales we need to put the scale block to "INDIQUÉE" (it means AS SHOWN in english, because I will add later a specific scale bar for each viewport). So, in this case, (setq ss1 "INDIQUÉE"). Perfect, now it is working here.
Page G05 not working. If the scale of the viewport is not on the routine's list, put the scale block to "AUCUNE" (It means NONE in english). So in this case,(setq ss1 "AUCUNE") It is still not workin here. Instead of AUCUNE it gave me INDIQUÉE. In this scenario, it must be AUCUNE, because the viewport do not has a valid scale. So, I can not use the scale bar to mesure the printed sheet.

Also, scales 1:1, 1:2, 1:2.5, 1:3... (lower than 1:10) are not working. Attached a new sample with viewports in those scales. Perfect, now it is working here.


Almost there Henrique! 

0 Likes
Message 15 of 18

hmsilva
Mentor
Mentor
Accepted solution

Revised

 

(defun c:VS (/ i lst pos retab sc ss vis)
    (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) (cons -4 "!=") (cons 69 1))))
            ) ; and
            (progn
                (setq lst nil)
                (repeat (setq i (sslength ss))
                    (setq sc  (/ 1 (vla-get-CustomScale (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
                          lst (cons sc lst)
                    )
                )
                (if (vl-every (function (lambda (x) (equal x sc))) lst)
                    (if (and
                            (setq pos (vl-position
                                          sc
                                          '(1.0     2.0     2.5     3.0     5.0     7.5     10.0    15.0    20.0    25.0    30.0    40.0    50.0    75.0
                                            100.0   125.0   150.0   200.0   250.0   300.0   350.0   400.0   500.0   600.0   750.0   1000.0  2000.0  2500.0
                                           )
                                      )
                            )
                            (setq vis (nth pos
                                           '("1:1"      "1:2"      "1:2.5"    "1:3"      "1:5"      "1:7.5"    "1:10"     "1:15"     "1:20"     "1:25"
                                             "1:30"     "1:40"     "1:50"     "1:75"     "1:100"    "1:125"    "1:150"    "1:200"    "1:250"    "1:300"
                                             "1:350"    "1:400"    "1:500"    "1:600"    "1:750"    "1:1000"   "1:2000"   "1:2500"
                                            )
                                      )
                            )
                        )
                        (MS:ChangeVisibility vis)
                        (MS:ChangeVisibility "AUCUNE")
                    )
                    (MS:ChangeVisibility "INDIQUÉE")
                )
            )
            (MS:ChangeVisibility "AUCUNE")
        ) ; if
    ) ;foreach
    (setvar "ctab" retab)
    (princ)
)

 ;https://forums.autodesk.com/t5/visual-lisp-autoli?sp-and-general/changing-visibility-states-in-dynam?ic-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)))
    )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 16 of 18

msarqui
Collaborator
Collaborator
Testing...
0 Likes
Message 17 of 18

msarqui
Collaborator
Collaborator

Working pretty nice.

Many many thanks Henrique. Smiley Very Happy

 

 

0 Likes
Message 18 of 18

hmsilva
Mentor
Mentor

@msarqui wrote:

Working pretty nice.

Many many thanks Henrique. Smiley Very Happy

 

 


You're welcome, Marcelo!
Glad I could help

Henrique

EESignature

0 Likes