Adjust 3D polyline Z values by text

yu85.info
Collaborator

Adjust 3D polyline Z values by text

yu85.info
Collaborator
Collaborator

Hi, I have a 3D polyline (DWG attached) with text. I need to adjust the Z values of the vertexes. I need to subtract from the current value the value that appears in the text in the same location of the vertex. For example the Z value of the first vertex is 513.76. The text contains "0.52m". I need the result - 513.76-0.52 =  so the Z value will be - 513.24

Thank you very much in advance

 

0 Likes
Reply
Accepted solutions (1)
606 Views
9 Replies
Replies (9)

john.uhden
Mentor
Mentor

@yu85.info ,

A few questions...

1.   Are the textual objects TEXT or MTEXT?

2.  If MTEXT might they have formatting codes?

3.  Are all the applicable text objects on a unique layer?

4.  Are all the applicable polylines on a unique layer?

5.  Are vertices close together so there might be confusion as to which text is meant for which vertex?

John F. Uhden

Kent1Cooper
Consultant
Consultant

[Open the drawing, and all questions will be answered.]

 

My question is:  There are Points at all the vertices, as well as the Text objects [which are "at" the vertices in the XY direction, but not Z].  Should the Points be moved along with the vertices?

Kent Cooper, AIA

yu85.info
Collaborator
Collaborator

Thank you sir,

1. It is Text

3. Yes

4. In the drawing I attached there only one polyline but I am looking for a solution also for many polylines

5. The location of the text is unique to each vertex it is exactly in the same location of the vertex

0 Likes

yu85.info
Collaborator
Collaborator

Thank you very much friend,

The points can be ignored.

0 Likes

john.uhden
Mentor
Mentor

@yu85.info ,

Luckily I have my work laptop at home running 2020, so I was able to open the drawing.

I have the detection and adjustments working, but it leaves me with more questions...

6.  After the vertices have been adjusted, do you want to do something to preclude someone running it again and adjusting the vertices by more?

   a)  Like maybe deleting all the text?  OR

   b)  Locking the polyline's layer?  OR

   c)  Some other extruded action?

7.  Do you want to process multiple polylines in one shot?

8.  Might you have a situation where the Z values are to be raised?

John F. Uhden

yu85.info
Collaborator
Collaborator

Sorry sir, I should have save it in an earlier version. Thanks for the effort.

6. No need for any of that.

7. Yes

8. No

Thanks again sir 

0 Likes

john.uhden
Mentor
Mentor
Accepted solution

@yu85.info ,

Here ya go.  I just didn't add typical *error* and Undo controls.

(defun c:adj3dZ ( / gettxt ss i n e ent p adj okay)
  ;; v1.0 (3-28-2024) by John Uhden for @yu85.info
  ;; program adjusts (negatively) the vertex elevations of
  ;;   selected 3DPolylines based on the value of adjacent text.
  (defun gettxt (p / p1 p2 ss adj)
    (and
      (setq p1 (mapcar '+ p '(-1 -1)))
      (setq p2 (mapcar '+ p '(1 1)))
      (setq ss (ssget "_C" p1 p2 '((0 . "TEXT")(1 . "*#m"))))
      (setq adj (atof (cdr (assoc 1 (entget (ssname ss 0))))))
    )
    adj
  )
  (and
    (princ "\nSelect 3DPolylines: ")
    (setq ss (ssget '((0 . "POLYLINE")(-4 . "&")(70 . 8))))
    (setq n 0)
    (repeat (setq i (sslength ss))
      (setq e (ssname ss (setq i (1- i))) okay nil)
      (while (and (setq e (entnext e))(= (cdr (assoc 0 (setq ent (entget e)))) "VERTEX"))
        (and
          (setq p (cdr (assoc 10 ent)))
          (setq adj (gettxt p))
          (setq p (mapcar '- p (list 0 0 adj)))
          (entmod (subst (cons 10 p)(assoc 10 ent) ent))
          (setq okay 1)
        )
      )
      (if okay (setq n (1+ n)) T)
    )
    (princ (strcat "\nProcessed " (itoa n) " 3DPolylines."))
  )
  (princ)
)

John F. Uhden

yu85.info
Collaborator
Collaborator

Perfect! Thanks friend for your help. Works great!

0 Likes

komondormrex
Mentor
Mentor

hey there,

yet another one

;***************************************************************************************************************************************

(defun make_assoc_xy_points (coordinates_raw_list / point_list)
  	(if coordinates_raw_list
		(setq point_list (cons (list (list (car coordinates_raw_list) (cadr coordinates_raw_list)) (caddr coordinates_raw_list))
				       (make_assoc_xy_points (cdddr coordinates_raw_list))
				 )
		)
	)
  	point_list
)

;***************************************************************************************************************************************

(defun c:change_z (/ 3d_pline assoc_xy_point_list text_list found_text)
  (setq 3d_pline (vlax-ename->vla-object (car (entsel "\nPick target 3D pline: ")))
	assoc_xy_point_list (make_assoc_xy_points (vlax-get 3d_pline 'coordinates))
	text_list (mapcar 'vlax-ename->vla-object
			  (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_f" (mapcar '(lambda (vertex) (mapcar '+ '(-0.5 -0.5) vertex))
											   (mapcar 'car assoc_xy_point_list)
										  ) '((0 . "text"))
								      )
							     )
					       )
			  )
	 	  )
  )
  (foreach vertex assoc_xy_point_list
    (if (vl-some '(lambda (text) (equal (vlax-get (setq found_text text) 'textalignmentpoint) (append (car vertex) '(0))))
		  text_list
	)
      	(vla-put-coordinate 3d_pline (vl-position vertex assoc_xy_point_list)
	  			     (vlax-make-variant (vlax-3d-point (append (car vertex)
									       (list (- (cadr vertex) (atof (vla-get-textstring found_text))))
								       )
							)
				     )
	)
    )
  )
  (princ)
)

;***************************************************************************************************************************************
0 Likes