March 22, 2021

ACA: Using AutoLISP to Change the Swing of all Swinging Doors

There was a request to change the "swing angle" of all of the Doors in a file to 30 degrees. Building on code I previously wrote for changing the heights of Doors a given style, I put together a command function in AutoLISP that does that. One thing to know before embarking on this particular task is that while all of the 20 built-in Door Types appear to have a SwingAngle property (I did not check all 20, so do not hold me to that), only five of those types (Single, Double, Double Opposing, Uneven and Uneven Opposing) will accept a change to that property; the other 15 types will throw an error and crash the routine. There are four additional types (Single-Dhung, Double-Dhung, Uneven-Dhung and Communicating) that are in fact swinging Doors, but for some reason were not included when the SwingAngle property was introduced. (See comments at the end of the article for more on that.) The "swing" of these types can be changed using the OpenPercent property; a value of 16 approximates 30 degrees. No change is made to the other 11 types of Doors.

The following code defines a command called DRSW that will change the "swing" of Doors of one of the nine types previously mentioned to 30 degrees/16 percent. That amount is hard-coded, on the assumption that this would be part of a larger automation task meant to run unattended (or that you always wanted the same degree/percent values). Collecting user input would be easy enough to add at the beginning if you want to specify the angle/percent each time you run the program.
(defun C:DRSW (                         ; No arguments.
                iCount                  ; Loop counter [integer].
                iDType                  ; Door Type [integer].
                iMax                    ; Total number of Doors in file [integer].
                iProc                   ; Number of Doors processed [integer].
                objDoor                 ; Door object being processed.
                objDStyle               ; Door Style of the object being processed.
                ss1                     ; All Doors in the file [selection set].
              ) ;_ End arguments and local variables.
  (setq        ss1 (ssget "_X" '((0 . "AEC_DOOR"))))
    ((not ss1)                          ; No Doors in drawing.
     (alert "Drawing file has no Door objects.\nNothing to do!")
    ) ;_ End condition A1.
    (T                                  ; Else, continue.
     (setq iMax          (sslength ss1)
           iCount 0
           iProc  0
     ) ;_ End setq.
     (while (< iCount iMax)
       (setq objDoor    (vlax-ename->vla-object (ssname ss1 iCount))
	     objDStyle	(vlax-get-property objDoor 'Style)
	     iDType	(vlax-get-property objDStyle 'Type)
       ) ;_ End setq.
       (if (or
	     (= iDType 1)               ; Single.
	     (= iDType 2)               ; Double.
	     (= iDType 5)               ; Double Opposing.
	     (= iDType 6)               ; Uneven.
	     (= iDType 8)               ; Uneven Opposing.
	   ) ;_ End or.
	   (vlax-put-property objDoor 'SwingAngle 30)
	   (setq iProc (1+ iProc))
	 ) ;_ End progn.
	 (if (or
	     (= iDType 3)               ; Single-Dhung.
	     (= iDType 4)               ; Double-Dhung.
	     (= iDType 7)               ; Uneven-Dhung.
	     (= iDType 20)              ; Communicating.
	   ) ;_ End or.
	     (vlax-put-property objDoor 'OpenPercent 16)
	     (setq iProc (1+ iProc))
	   ) ;_ End progn.
	 ) ;_ End if.
       ) ;_ End if.
       (setq iCount (1+ iCount))
     ) ;_ End while.
    ) ;_ End condition A2.
  ) ;_ End cond A.
      "\nDRSW function completed:  "
      (itoa iProc)
      " Door(s) of "
      (itoa iCount)
      " total Door(s) processed. "
    ) ;_ End strcat.
  ) ;_ End prompt.
) ;_ End C:DRSW.

Originally, all Door Types controlled how open they appeared using the Opening percent property on the Properties palette (or its prior equivalent). 100% open for a swinging door meant a 180-degree swing. So a 90-degree swing would be 50%. Some users complained that may make sense to a programmer, but they thought of door swings in terms of degrees, not percentages. So at some point (I do not recall which release), a SwingAngle property was added to Door objects, and, for the five Door types noted above, Swing angle replaced Opening percent on the Properties palette. For those five Door types, the two values are linked - change one and the other changes, too. (That is how I determined that 16% was the right value for 30 degrees - that is the value for OpenPercent that the program shows when the SwingAngle is set to 30.) I have no idea why the three Dhung and the Communicating Door Types were omitted from the change to SwingAngle. Perhaps the original complainants rarely, if ever, used those types and so they were not in the original request. Or maybe the way things were set up in the program, it was easy to make the change for the five types that were changed, but not for the other four. Whatever the reason, things are the way they are, and the code above accommodates that.

1 comment:

JMays said...

This is a routine I've wanted forever, thanks. One question, this changes the swing in standard and medium detail display but does not change it in Presentation...any way to make that work?

Many Thanks!