lisp - insert block symbol manager, take elevation

Discussion in 'AutoCAD' started by WILLIE, Jul 9, 2004.

  1. WILLIE

    WILLIE Guest

    I have a spot elevation block that I use to label elevations in the
    drawings. I do my drawings with 3dpolylines. I have to go to many nodes in
    the drawing and insert the block there and then change the text to match
    what the 3dpolyline elevation is at that node. I would like to be able to
    insert the block at a particular node and the attribute would take on that
    elevation. If I could use the lisp routine in the symbol manager then it
    would be even better. I have my block in the symbol manager so that I can
    insert multiple blocks at the drawing scale, and then enter the rotation
    angle that I choose. I would be in forever indebted to anyone that would be
    able to help me out.

    TIA ,I hope
     
    WILLIE, Jul 9, 2004
    #1
  2. WILLIE

    andywatson Guest

    Willie,
    Because you would like to continue to use the Symbol Manager program to insert your blocks, writing a program to automatically fill in the elevation AS the block is inserted would be complicated. You'd have to use these nasty things called reactors.
    In my opinion, you may want to focus on a program that you can run AFTER the blocks have been inserted. So, say you insert 20 or so blocks at elevation...you would then run the routine which would then fill in each block's attributes with their elevations.

    The code might go something like this....
    1. Get user selection of spot elevation blocks (or select all blocks)
    2. With each block...
    a. get the elevation
    b. fill in the attribute of the block with the elevation

    Here's what I came up with...just copy and paste into a *.lsp file, appload it, and start with "ElevToAtt"
    Just modify the block name, attribute tag name and rounding precision. (you can always change the command name to something else :)
    Code:
    (defun c:ElevToAtt ( / 	strBlockName	strAttTag
    intPrecision	acadDoc
    acadMspace	ss
    acadSS		acadBlock
    reaElevation	acadAtt)
    ;; modify the settings below for your situation
    (setq strBlockName "SPOT" ; block name in quotes
    strAttTag "EL" ; elevation attribute tag in quotes
    intPrecision 2 ; number of decimal places to round to
    )
    ;; load activex
    (vl-load-com)
    ;; get document and modelspace objects
    (setq acadDoc (vla-get-activedocument (vlax-get-acad-object))
    acadMspace (vla-get-modelspace acadDoc)
    )
    ;; get selection set, filtering for spot elevation blocks
    (prompt "\nSelect the spot elevations to update...")
    (setq ss (ssget (list (cons 2 strBlockName)))
    acadSS (vla-get-activeselectionset acadDoc))
    ;; iterate through each block
    (vlax-for acadBlock acadSS
    ;; get the elevation of the block
    (setq reaElevation (caddr (vlax-get acadBlock "insertionpoint")))
    ;; cycle through each attribute
    (foreach acadAtt (vlax-invoke acadBlock "GetAttributes")
    ;; if attribute tag matches the one we want
    (if (= (vla-get-tagstring acadAtt) strAttTag)
    ;; edit attribute text
    (vla-put-textstring acadAtt (rtos reaElevation 2 intPrecision))
    )
    )
    )
    (princ "\nDone.")
    ;; ssssh.
    (princ)
    )
    
     
    andywatson, Jul 9, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.