Nate Holt's Blog

October 26, 2009

Vertical SCOOT work-around – AutoCAD Electrical

Filed under: Electrical, Tips — nateholt @ 9:23 am

Overriding a propensity for AutoCAD Electrical’s cool “Scoot” command to default to “horizontal” mode

This was another “head-scratcher”. The task seemed so simple. Just create a horizontal and vertical version of an electrical symbol to represent a multi-ratio current transformer. Should be easy, piece of cake…

… but, when finished and testing the results, the horizontal version worked great and SCOOTed great, but the vertical version behaved unexpectedly.

Here’s are a couple instances of the new horizontal symbol inserted into a bus wire. The Scoot command works as expected.


Right click on the symbol, select SCOOT command, and slide it over to the right…


… and click. Everything stretches/trims/reconnects nicely.


But not the Vertical version ( ! )

The vertical version wants to scoot horizontally on the horizontal connected wire. What’s going on??


The problem: the SCOOT command appears to have a built-in bias to default to horizontal scooting. If there are the same number of horizontal wire connection points as there are vertical wire connection points on a symbol, and at least one wire connects to each type, the SCOOT command defaults to horizontal scoot mode.

Here’s the exploded vertical version of the custom CT symbol:


There are two vertical wire connection attributes, X2TERM04 and X8TERM03 (where the 2nd character of 2 or 8 flags vertical). There are two horizontal wire connection attributes, X4TERM02 and X4TERM01 (where the 2nd character of 1 or 4 flags horizontal connection). So, equal number of horizontal and vertical… and the SCOOT command defaults to horizontal scooting.

The Work-around

On a tie vote, horizontal wins. So we need to stuff the ballot box with an extra “vote” for vertical. Here’s the work-around. Add a dummy vertical wire connection attribute to the symbol so that the vote will end up being 3 vertical versus 2 horizontal… and scoot will go with the vertical majority.

Add the unused dummy vertical wire connection attribute at a point on the symbol where it will likely not be accidentally used. Here’s the example for the above symbol:


Not necessary, but used an odd suffix value of “99” to make it “stand out” from the others.


Now, it scoots vertically, very nicely!


October 15, 2009

‘ZOOM to HANDLE’ utility

Filed under: Tips — nateholt @ 6:26 pm

Quickly create a tool to find and zoom to a given entity using its handle number.

You know an entity/object’s “handle” number, but where in the world is it in your jumbled drawing?

Complex library creation and testing has been on my plate for a couple weeks. The new code spits out the AutoCAD handle of various entities as processing proceeds. Sometimes there’s a need to go back in and find a problem entity on the drawing. Have the handle reference but that’s it. What is it, where is it?

Manual Method – Crude with  no-frills

Here’s the crude, no-frills way. Open the entity and display its guts in the command window.

Let’s say that you’ve run your program in a “debugging” mode and find that there is some issue with object handle “74F” in the active drawing. What and where is this entity?

Type this AutoLISP expression at the “Command:” prompt

Command: (entget (handent “74F”)) [Enter]

It returns this block of data about this entity.

((-1 . <Entity name: 7ef152f8>) (0 . “LINE”) (330 . <Entity name: 7ef11c10>) (5 . “74F”) (100 . “AcDbEntity”) (67 . 0) (410 . “Model”) (8 . “0”) (100 .
“AcDbLine”) (10 6.09375 13.5 0.0) (11 6.12676 13.5 0.0) (210 0.0 0.0 1.0))

The “0” entry flags the entity type: “LINE” and the “10” and “11” parts give the XYZ start and end points of the LINE segment.

Crude, but it does work.

Better Method: auto-ZOOM to the entity

Here’s a little AutoLISP utility thrown together to help in troubleshooting. It zooms in on the target object given the typed-in handle.

The syntax is pretty simple. After the utility is APPLOADed, type ZH at the AutoCAD command prompt and then enter the handle number at the next prompt…

Command: zh [Enter]
Handle  =74F [Enter]

The utility opens up the entity. If it is a simple graphical entity like an arc, text, block insert, line, then it opens it to find “where” it is.

Entity type: LINE XY=(6.11026 13.5 0.0)

… and then it issues a ZOOM “Centered” command to display the object in the middle of the screen. It then tries to highlight it. Now you can zoom in or out with “I” or “O” keystrokes or use your mouse “wheel” to take a better look in context.

Here’s the handle “74F” example… it was an incomplete wire connection on the high side of a control transformer.


Here’s the utility itself. Cut and paste into an ASCII text file, let’s call it “zh.lsp”.

; ** 13-Oct-09 NEHolt -
(defun c:zh ( / hdl xy enttype ed en xy2)
  ; ZOOM to entity "handle". Does not check model vs layout space.
  (while (/= (setq hdl (getstring (strcat
              "\nHandle " (if en "(or I=Zoom IN, O=Zoom out)" "") " ="))) "")
      ((= (strcase hdl) "I")(command "_.ZOOM" "1.5x"))
      ((= (strcase hdl) "O")(command "_.ZOOM" "0.75x"))
        (if (setq en (handent hdl)) ; convert handle string to its "entity name"
          (progn ; appears to be a valid handle number
            (if (setq ed (entget en)) ; open up the entity
              (progn ; success, okay to continue
                (setq xy nil)
                (setq enttype (cdr (assoc 0 ed))) ; extract the entity type
                (princ "\nEntity type: ")(princ enttype)
                (if (= enttype "INSERT")
                  (progn ; this is a block INSERT instance
                    (princ " blk nam=")
                    (princ (cdr (assoc 2 ed))) ; display block name
                ) )
                ; Figure where entity is located
                (if (cdr (assoc 10 ed))
                    (setq xy (cdr (assoc 10 ed))) ; 10 subrec often gives a location value
                    (if (= enttype "LINE")
                      (progn ; LINE entity. Reset to zoom to line's midpoint
                        (setq xy2 (cdr (assoc 11 ed))) ; XY of other end
                        ; Calc midpoint coordinate
                        (setq xy (list (+ (car xy) (* 0.5 (- (car xy2) (car xy))))
                                       (+ (cadr xy) (* 0.5 (- (cadr xy2) (cadr xy))))
                                       (+ (caddr xy) (* 0.5 (- (caddr xy2) (caddr xy))))))
                ) ) ) )
                (if xy
                  (progn ; Non-blank XY extracted from picked entity. Go ahead and
                           ; display the value and ZOOM in to that point on the drawing.
                    (princ " XY=")(princ xy)
                    (command "_.ZOOM" "_C" xy 1.0) ; use ZOOM CENTER command
                    (redraw en 3) ; trigger entity to "highlight"
                ) )
        ) ) ) )
  (command "_.REGEN") ; brute force - unhighlight everything
  (princ) ; quiet return

That should be it. APPLOAD this file and that should expose the utility to use on your active drawing.

UPDATE: typo introduced when the above program was cut/paste into this posting. Very sorry. Should be okay now. – Nate.

Create a free website or blog at