Reactor LISP to automatically change viewport scale of other viewports

Reactor LISP to automatically change viewport scale of other viewports

Anonymous
Not applicable
1,508 Views
4 Replies
Message 1 of 5

Reactor LISP to automatically change viewport scale of other viewports

Anonymous
Not applicable

Hey everyone,

 

This is a bit of a long shot here, but I'm having a difficult time thinking through this one. This is one question in a series of upgrades we're trying to make to our workflow.

 

We have a plan and profile drawing template set up for everyone here. We also have a dynamic scale bar linked to our plan view port.

 

We've had some instances where drafters have changed the scale of the plan view port and forgotten to change the scale of the profile view port as well. EX: Plan view port gets changed to 1" = 20' but the Profile view port is left at 1" = 40'.

 

Does anyone know of a way to use a reactor LISP to link the view ports together so that if I change the scale of one, it will automatically match the scale with the other view port in the layout?

 

Alternatively: I'll post some code below (Much thanks to Lee Mac), where I was thinking that I could change the visibility state of some dynamic blocks based on the view port scales. If I could get that to work, I think I have a workaround for my problem.

 

 

(defun c:changevis ( / blk idx obj sel vis )
    
    (setq blk "SEI_Scale" ;; Block Name
          vis "1\" = 10'"    ;; <---AUTOMATICALLY GRAB CORRECT SCALE HERE
    )
    (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)))
    )
)

(vl-load-com) (princ)

 

Accepted solutions (1)
1,509 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Advisor
Advisor

@Anonymous ,

 

Sorry nobody has responded to your request so far. People who know about using reactors are a fairly slim group. I have never personally had to use one. We normally have the opposite problem where I work, where people change the viewport, but not the scale Lol.

 

As an alternate solution, I'm not sure how many VP scales you use, but if it's only a couple then perhaps you could create a dynamic block with different visibilities, then place your VPs and scales in the different visibilities, then the user could select the correct visibility, but they would HAVE to explode the block afterward.

 

That's the best solution I can think of for something like this.

 

OR if you're using a vertical of AutoCAD w/ AEC objects, I believe you can dynamically link your scale to your VP.. then all the user would have to do is worry about the VP instead of your scale.

 

Best,

~DD

Message 3 of 5

john.uhden
Mentor
Mentor
Accepted solution

I don't know what all that dynamic block stuff has to do with viewport scales, but it seems to me a reactor could work.  Do you have a situation where each plan/profile layout has just two (2) viewports, one for plan and one for profile?

I think we could write a reactor such that if the plan scale were changed, then the profile viewport could be changed to match.  But I don't think it can work in either direction, because the change would affect the object of the reaction, which is not progammatically allowed.  But if all the viewports in the drawing were intended to match the LTSCALE, then we could handle all the viewports with one reaction.  Of course that won't work to your satisfaction if you include layouts for your title sheet and details in the same drawing.  Then again, locking viewports might put the kabosh on your plans, though maybe we could program our way through that obstacle.  Sorry I don't have a quick answer for you.  I am getting old and rusty.  Reaching back for some youth, I just bought a Sunfish to race at my yacht club.  I used to sail M-Scows years ago, but I can't afford one of them, even used.  Anyway, the name for it came to me almost instantly... "Auld Phart."  I'm sure my daughter and her girls will get a huge kick out of it when they come to visit from Maine next weekend.

John F. Uhden

Message 4 of 5

Sea-Haven
Mentor
Mentor

I think your on the money about locking viewport a lisp would allow pick a viewport unlock change scale then set all viewports in that layout to same relocking viewports.

 

Its a pain when viewports are not locked and you dont realise till the mess you just made with scale.

 

Ps for me a Mosquito two on trapeze, kids on trap hanging off side 3' in air flying a hull, was a thrill for them.

Message 5 of 5

Anonymous
Not applicable

After playing around with this, I think I can get it to work for our situation. Thanks for the help!

0 Likes