ISO - Routine to extract data from table and create MTEXT lines inserting data into them.

ISO - Routine to extract data from table and create MTEXT lines inserting data into them.

zac_bullock
Enthusiast Enthusiast
418 Views
3 Replies
Message 1 of 4

ISO - Routine to extract data from table and create MTEXT lines inserting data into them.

zac_bullock
Enthusiast
Enthusiast

Hi, I have tried and tried again to get this to work, but I need to learn to walk before I learn to run with things like this. I have a table that has a header row, and a title row that I don't care about. It also has one column on the far left side "The Line # column" that I don't care about. What I am after is the Bearing (B) column and Distance (D) column. I would like to extract L1-B, and put its text in the first THENCE line in place of "XXX", and then extract L1-D, and put its text (MINUS THE FOOT SYMBOL " ' " in place of "YYY". I would like to do this for all rows no matter how long the table is (it is not always 5 lines).

zac_bullock_0-1694548646774.png

The final product should look like this:

zac_bullock_1-1694548975288.png

My approaches did not work, and I wasn't able to even really extract the data much less convert it into MTEXT format.

If anyone could help me out it would be greatly appreciated! Thanks!

 

0 Likes
Accepted solutions (1)
419 Views
3 Replies
Replies (3)
Message 2 of 4

Sea-Haven
Mentor
Mentor

Ok to have a go you need to GET a cell text.

 

(setq obj (vlax-ename->vla-object (car  (entsel "Pick table "))))

(setq cellvalue (vlax-variant-value (vla-GETCELLVALUE OBJ row col)))

 

Then use repeat to loop through the values start at row 1 as 0 is top row.

 

(setq cols (vlax-get-property obj 'columns))
(setq rows (vlax-get-property obj 'rows))
0 Likes
Message 3 of 4

komondormrex
Mentor
Mentor
Accepted solution

hey,

you'd better start learning to fly)

 

 

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

(defun make_rows (cell_raw_list / row_list)
  	(if cell_raw_list
		(setq row_list (cons
							   (list (car cell_raw_list) (cadr cell_raw_list) (caddr cell_raw_list) )
							   (make_rows (cdddr cell_raw_list))
					   )
		)     
	)
  	row_list
)

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

(defun c:rip_table (/ table_ename columns_number skip_row row_list mtext_content)
	(setq table_ename (car (entsel "\nPick a table to rip: "))
		  columns_number (vla-get-columns (vlax-ename->vla-object table_ename))
		  skip_row 2
		  row_list (make_rows (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 302 (car group))) (entget table_ename))))
		  row_list (repeat skip_row (setq row_list (cdr row_list)))
		  mtext_content ""
	)
	(vla-addmtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
				  (vlax-3d-point (trans (getpoint "\Pick upper left corner of mtext of ripped cells: ") 1 0))
				  0
				  (foreach row row_list
					(setq mtext_content (strcat mtext_content "THENCE " 
												(cadr row) 
												" SAID CENTERLINE, A DISTANCE OF " 
												(substr (last row) 1 (1- (strlen (last row))))
												" FEET TO A POINT;\\P"
										)
					) 
				  )
	)
)
;**************************************************************************************************************************

 

 

0 Likes
Message 4 of 4

zac_bullock
Enthusiast
Enthusiast

Works like a charm. Thank so much! Exactly what I needed 😁

I'm trying to learn slow and steady because just trying to throw myself out of a plane without a parachute has confused me greatly! I'm reading Essential Autolisp now, taken a short course, and continuing to learn from the code that you and others help me with to form a deeper understanding of Autolisp. So thank you again!!!

0 Likes