Create table from list

Create table from list

neam
Collaborator Collaborator
1,166 Views
10 Replies
Message 1 of 11

Create table from list

neam
Collaborator
Collaborator

Hi everyone.

With the help of some subroutines that I found on the Internet (Thank Lee Mac and Roland.R71),
I wrote a code that extracts the information of curves.
A list is generated (strx):

(("E18" "minR=0.447" "majR=0.978" "X=27.45" "Y=5.20") ("E17" "minR=0.447" "majR=0.978" "X=23.87" "Y=7.16")........)

Can I create a table from the generated list (Like the table attached in the file)?

0 Likes
Accepted solutions (2)
1,167 Views
10 Replies
Replies (10)
Message 2 of 11

EnM4st3r
Advocate
Advocate

but why a .rar??

0 Likes
Message 3 of 11

neam
Collaborator
Collaborator

it went wrong.
I apologize.

as usual.

0 Likes
Message 4 of 11

komondormrex
Mentor
Mentor
Accepted solution

hey there,

check this. no formatting except for the first column is done. rows' height and columns' length are set directly. the default text style is used for cells' content. 

 

(setq table_list '(("E18" "minR=0.447" "majR=0.978" "X=27.45" "Y=5.20") ("E17" "minR=0.447" "majR=0.978" "X=23.87" "Y=7.16")))
(setq table_object (vla-addtable (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
				 (vlax-3d-point (getvar 'viewctr))
				 (+ 2 (length table_list))
				 (length (car table_list)) 
				 0.36
				 2.5
	     	   )
)
(vla-deleterows table_object 0 2) 
(setq row_index 0)
(foreach row_list table_list
  (setq column_index 0)
  (foreach cell_text row_list
  	(vla-settext table_object row_index column_index cell_text)
  	(if (zerop column_index) (vla-setcellalignment table_object row_index column_index acTopLeft))
    	(setq column_index (1+ column_index))
  )
  (setq row_index (1+ row_index))
)
(setvar 'cmdecho 0)
(command "_cutclip" (vlax-vla-object->ename table_object) "")
(command "_pasteclip")
(setvar 'cmdecho 1)

 

 

 

Message 5 of 11

neam
Collaborator
Collaborator

Dear komondormrex:

As always, you hit the target perfectly.

I am really grateful 🙏🙏

0 Likes
Message 6 of 11

Sea-Haven
Mentor
Mentor

Just a suggestion something I do is that you may want to add more curve details to an existing table so I ask "Select existing table or pick nothing for a new one", using entsel returns the table or a nil ie make a new one and at the point selected. I use Insertrows rather than rows = the length of the list, so can get max row number even after dwg has been saved and reopened if adding to an existing.

 

Not sure if you would still want the title and heading.

 

(vla-deleterows table_object 0 2) 
(setq row_index 0)

;(vla-deleterows table_object 0 2) 
(setq row_index 2)
(vla-settext table_object 0 0 "Curve details")
(vla-settext table_object 1 0 "Curve Number")
(vla-settext table_object 1 1 "Min Radius")
(vla-settext table_object 1 2 "Max Radius")
(vla-settext table_object 1 3 "X Cen. Pt")
(vla-settext table_object 1 4 "Y Cen. Pt")

 

SeaHaven_0-1715396367016.png

Why the copy clip at end ?

 

Message 7 of 11

neam
Collaborator
Collaborator

Thank you for your attention.
Be sure to add the point you mentioned in the code.

At the end of the code. The copy is also disabled.

0 Likes
Message 8 of 11

neam
Collaborator
Collaborator

HI dear Sea-Haven:

How can I replace the character "X=" and "Y=" of text string to each item in a list to this ""


My list:
(("E4" "X=612021.95" "Y=4283098.74" "minR=0.277" "majR=1.211") ("E3" "X=612105.72" "Y=4283341.37" "minR=1.700" "majR=3.652") ("E2" "X=612304.66" "Y=4283234.50" "minR=3.069" "majR=5.449"))


Result:
(("E4" "612021.95" "4283098.74" "minR=0.277" "majR=1.211") ("E3" "612105.72" "4283341.37" "minR=1.700" "majR=3.652") ("E2" "612304.66" "4283234.50" "minR=3.069" "majR=5.449"))

 

I tried to do this with the following function, but my list is not updated.

(setq nx 0)
(foreach i list
(vl-string-subst "" "X=" (cadr (nth nx list)))
(setq nx (+ nx 1))
)

0 Likes
Message 9 of 11

pkenewell6347
Advocate
Advocate
Accepted solution

This approach I think will work:

(setq lst
   (mapcar
      '(lambda (y)
         (mapcar
            '(lambda (x)(if (wcmatch (substr x 1 2) "X=,Y=")(substr x 3) x))
            y
         )
      )
      lst
   )
)

Message 10 of 11

neam
Collaborator
Collaborator
Thanx dear pkenewell6347 for reply and guidance.
Message 11 of 11

Sea-Haven
Mentor
Mentor

I would go back a step, look at your Data on Curves 5.lsp

 

(setq data (append (list (strcat "A" (rtos arcn 2 0) "  R=" (rtos rad 2 2) "  L=" (rtos arc_len 2 2) "  X=" (rtos (car cen) 2 2) "  Y=" (rtos (cadr cen) 2 2))) 

 

Just remove " x=" & " Y="