Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Extract attrib value of a block to change the elev. of multiple different blocks

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jimperson66
491 Views, 5 Replies

Extract attrib value of a block to change the elev. of multiple different blocks

We have a need to convert 2D blocks to 3D to build a new surface. Our old spot elevations were comprised of two blocks, one called spotp which was the actual point on the drawing where the desired elevation was and one called spotel that has the attribute for the elevation enclosed in an ellipse, a line joins the two. I would like the program to prompt you to select the spotel block with the attribute, extract the elevation string, then prompt you to pick one or more spotp blocks and change the elevation of those to the value of the attribute extracted from the selected spotel block.

I already have a program that takes blocks with z elevation and creates points with the assigned elevation so once we elevate the spotp blocks we can use it to create point data to build the new surface.

 

Thanks

5 REPLIES 5
Message 2 of 6
Shneuph
in reply to: jimperson66


@jimperson66 wrote:

I would like the program to prompt you to select the spotel block with the attribute, extract the elevation string, then prompt you to pick one or more spotp blocks and change the elevation of those to the value of the attribute extracted from the selected spotel block.

Thanks



Does SPOTEL have more than one attribute?  If so what is the attribute tag of the elevation attribute?

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 3 of 6
Shneuph
in reply to: jimperson66

This works pretty well.. It has NO error checking so you have to make sure you select the correct elements (the blocks).  It assumes that the SPOTL block has only 1 attribute, a string value that translates to a real number.

 

(Defun C:SLBELtoSPB ( / SpotL SpotP SPPosition Elevation)
  (vl-load-com)
  (setq SpotL (vlax-ename->vla-object (car (entsel "\nSelect SpotL Block: ")))
        SpotP (vlax-ename->vla-object (car (entsel "\nSelect SpotP Block: ")))
        SPPosition (vlax-variant-value (vla-get-insertionpoint spotp))
        Elevation (atof (vla-get-textstring (car (vlax-safearray->list (vlax-variant-value (vla-getattributes spotl))))))
        );setq
  

  (vlax-safearray-put-element SPPosition 2 Elevation)
  (vla-put-insertionpoint SpotP (vlax-make-variant SPPosition))
  (princ (strcat "\nElevation: " elevation " put to block SpotP"))
  
  (princ)
  );defun

 

EDIT:

" then prompt you to pick one or more spotp blocks"

My bad... I'll have to change this around a bit..

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 6
Shneuph
in reply to: jimperson66

Try this...

 

(Defun TempError (message /)
  
  (if (not (or
             (= message "Function cancelled")
             (wcmatch message "bad argument type:*")
             );or
           );not
    (princ (strcat "\nError: " message));print message
    );if
  (setq *error* backuperror)
  (princ)
  );defun

(Defun C:SLBELtoSPB ( / SpotL SpotP SPPosition Elevation)
  (vl-load-com)
  (setq backuperror *error*)
  (setq *error* TempError)
  (setq SpotL (vlax-ename->vla-object (car (entsel "\nSelect SpotL Block: ")))
        Elevation (atof (vla-get-textstring (car (vlax-safearray->list (vlax-variant-value (vla-getattributes spotl))))))
        );setq
  
  (while (setq SpotP (vlax-ename->vla-object (car (entsel "\nSelect SpotP Block: "))))
    (setq SPPosition (vlax-variant-value (vla-get-insertionpoint spotp)))
    (vlax-safearray-put-element SPPosition 2 Elevation)
    (vla-put-insertionpoint SpotP (vlax-make-variant SPPosition))
    (princ (strcat "\nElevation: " (rtos elevation) " put to block SpotP"))
    );while
  (setq *error* backuperror)
  (princ)
  );defun

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 5 of 6
Lee_Mac
in reply to: jimperson66

Hi jimperson,

 

Give the following a try:

 

(defun c:test ( / ss1 ss2 elv ent ins i )
  (if
    (and
      (setq ss1 (ssget "_+.:S:E" '((0 . "INSERT") (2 . "spotel") (66 . 1))))
      (setq elv (distof (cdr (assoc 1 (entget (entnext (ssname ss1 0)))))))
      (setq ss2 (ssget "_:L" '((0 . "INSERT") (2 . "spotp"))))
    )
    (repeat (setq i (sslength ss2))
      (setq ent (entget (ssname ss2 (setq i (1- i))))
            ins (cdr (assoc 10 ent))
      )
      (entmod (subst (list 10 (car ins) (cadr ins) elv) (assoc 10 ent) ent))
    )
  )
  (princ)
)

 It will prompt for selection of the 'spotel' block, then multiple 'spotp' blocks, moving such blocks to the elevation specified by the attribute in the 'spotel' block.

 

Since you haven't given the tag name of the elevation attribute, I assume that it is the first attribute in the spotel block.

 

Hope this helps,

 

Lee

Message 6 of 6
jimperson66
in reply to: Shneuph

Thanks Shneuph, works fine

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost