Polyline with attributes

Polyline with attributes

Marco.studio.venica
Participant Participant
1,346 Views
12 Replies
Message 1 of 13

Polyline with attributes

Marco.studio.venica
Participant
Participant

Hello everyone, for years I have abandoned the development of utility in lisp, and now I am definitely rusty, I hope for your help

I would like to obtain a polyline to be built at will that is connected to one or more attributes to be applied on it and also its total length, all in order to later extract the data and bring them to a spreadsheet.

For example the following data to extract

Polyline name (to be assigned during drawing)

1st alphanumeric value (data to be assigned during the design phase)

2nd alphanumeric value 1 (data to be assigned during the design phase)

3rd alphanumeric value 1 (data to be assigned during the design phase)

n ° Alphanumeric value 1 (data to be assigned during the design phase)

1st numeric value (Total length of the polyline)

 If anyone has already done something similar or if you could give me a tip I would be grateful.

0 Likes
1,347 Views
12 Replies
Replies (12)
Message 2 of 13

CADaSchtroumpf
Advisor
Advisor

Hi,

For exemple, you can use ldata for store value

(defun c:pl_data ( / pt sel obj vla_obj)
	(setq pt (getpoint "\nFirst point of polyline or enter for select one: "))
	(if pt
		(command "_.pline" pt
			(while (not (zerop (getvar "cmdactive")))
				(command pause)
			)
		)
		(while (not (setq sel (ssget "_+.:E:S" '((0 . "*POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 112) (-4 . "NOT>"))))))
	)
	(cond
		(js (setq obj (ssname ss 0)))
		(T (setq obj (entlast)))
	)
	(vlax-ldata-put (setq vla_obj (vlax-ename->vla-object obj)) "DATA_NAME" (getstring T "\nName of polyline : "))
	(vlax-ldata-put vla_obj "DATA_ALPHA1" (getstring T "\nData alphanumeric : "))
;...Repeat for other data alphanumeric
	(vlax-ldata-put vla_obj "DATA_LENGTH" (vlax-get-property vla_obj "Length"))
	(princ "\nPolyline have this data:")
	(print (vlax-ldata-list vla_obj))
	(prin1)
)
0 Likes
Message 3 of 13

john.uhden
Mentor
Mentor

It's funny how you caught me off guard with your variable naming.  Having learned things here from wizards long ago (and from decrypting DCA code), I got into the habit of naming an entity with E, and entity data with ENT.  When VLisp came along I decided to name vla-objects as OBJ so that I would never try to (entget OBJ).

For you lurkers, there is nothing wrong with what @CADaSchtroumpf  wrote because he knows what he is doing.  I'm just very old school with very old habits.  I have to have my orange juice before my coffee, and cheese must go on top of the ham or turkey.  The tomato or pickle goes on last.

John F. Uhden

Message 4 of 13

cadffm
Consultant
Consultant

Agree

"and cheese must go on top of the ham "

Sebastian

0 Likes
Message 5 of 13

Marco.studio.venica
Participant
Participant

Thank you for your attention, I tried the command and it is OK it remains for me to understand how I can extract the data with the DATAEXTRACTION command.
Can you help me?

0 Likes
Message 6 of 13

Marco.studio.venica
Participant
Participant

Ami la moto, se si abbiamo una passione in comune.

0 Likes
Message 7 of 13

Marco.studio.venica
Participant
Participant
0 Likes
Message 8 of 13

dlanorh
Advisor
Advisor

You could go (bread -> topping -> cheese -> ham ->bread) and then turn the sandwich upside down.😛

I am not one of the robots you're looking for

0 Likes
Message 9 of 13

Marco.studio.venica
Participant
Participant

Hi, I'm not aligned with your thoughts and I don't understand the message you are sending me, I am aware that it is my limit but I can only accept it !!

 

0 Likes
Message 10 of 13

CADaSchtroumpf
Advisor
Advisor

You can't use DATAEXTRACTION with extended data, aren't attribut of block!

You can make a table in drawing with my first exemple

(defun c:tab_ldata ( / js js_sel n obj vla_obj oldim oldlay AcDoc Space nw_style ins_pt_cell h_t w_c ename_cell n_row n_column)
	(setq js (ssget '((0 . "*POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 112) (-4 . "NOT>"))))
	(setq js_sel (ssadd))
	(repeat (setq n (sslength js))
		(setq obj (ssname js (setq n (1- n))))
		(if (vlax-ldata-get (setq vla_obj (vlax-ename->vla-object obj)) "DATA_NAME")
			(ssadd obj js_sel)
		)
	)
	(cond
		(js_sel
			(setq
				oldim (getvar "dimzin")
				oldlay (getvar "clayer")
			)
			(setq
				AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
				Space
				(if (= 1 (getvar "CVPORT"))
					(vla-get-PaperSpace AcDoc)
					(vla-get-ModelSpace AcDoc)
				)
			)
			(cond
				((null (tblsearch "LAYER" "Sheet_data"))
					(vla-add (vla-get-layers AcDoc) "Sheet_data")
				)
			)
			(cond
				((null (tblsearch "STYLE" "TEXT_SHEET"))
					(setq nw_style (vla-add (vla-get-textstyles AcDoc) "TEXT_SHEET"))
					(vlax-put nw_style 'fontfile (strcat (getenv "windir") "\\fonts\\arial.ttf"))
					(vlax-put nw_style 'height 0.0)
					(vlax-put nw_style 'obliqueangle (/ (* 15.0 pi) 180))
					(vlax-put nw_style 'width 1.0)
					(vlax-put nw_style 'textgenerationflag 0.0)
				)
			)
			(setvar "dimzin" 0) (setvar "clayer" "Sheet_data")
			(initget 9)
			(setq ins_pt_cell (getpoint "\nUp-Left insertion point for table: "))
			(initget 6)
			(setq h_t (getdist ins_pt_cell (strcat "\nHeight of text <" (rtos (getvar "textsize")) ">: ")))
			(if (null h_t) (setq h_t (getvar "textsize")) (setvar "textsize" h_t))
			(initget 7)
			(setq w_c (getdist ins_pt_cell "\nWidth of cell: "))
			(setq ename_cell (vla-addTable Space (vlax-3d-point (trans ins_pt_cell 1 0)) (+ 3 (sslength js_sel)) 3 (+ h_t (* h_t 0.25)) w_c))
			(setq n_row 2 n_column -1)
			(vla-SetText ename_cell 0 0 "LENGTH")
			(vla-SetCellTextStyle ename_cell 0 0 "TEXT_SHEET")
			(vla-SetCellTextHeight ename_cell 0 0 (vlax-make-variant h_t 5))
			(vla-SetCellAlignment ename_cell 0 0 5)
			(foreach string '("DATA_NAME" "DATA_ALPHA1" "DATA_LENGTH")
				(vla-SetText ename_cell 1 (setq n_column (1+ n_column)) string)
				(vla-SetCellTextStyle ename_cell 1 n_column "TEXT_SHEET")
				(vla-SetCellTextHeight ename_cell 1 n_column (vlax-make-variant h_t 5))
				(vla-SetCellAlignment ename_cell 1 n_column 5)
			)
			(setq n_column -1)
			(repeat (setq n (sslength js_sel))
				(setq ename (vlax-ename->vla-object (ssname js_sel (setq n (1- n)))))
				(if (vlax-property-available-p ename 'Length)
					(foreach el '("DATA_NAME" "DATA_ALPHA1" "DATA_LENGTH")
						(vla-SetText ename_cell n_row (setq n_column (1+ n_column)) (vlax-ldata-get ename el))
						(vla-SetCellTextStyle ename_cell n_row n_column "TEXT_SHEET")
						(vla-SetCellTextHeight ename_cell n_row n_column (vlax-make-variant h_t 5))
						(vla-SetCellAlignment ename_cell n_row n_column 6)
					)
				)
				(setq n_row (1+ n_row) n_column -1)
			)
			(setq n_column 2)
			(vla-SetText ename_cell n_row n_column
				(strcat "Sum= " "%<\\AcExpr (Sum(C3:C" (itoa n_row) ")) \\f \">%")
			)
			(vla-SetCellTextStyle ename_cell n_row (1- (length lst_idcolumn)) "TEXT_SHEET")
			(vla-SetCellTextHeight ename_cell n_row (1- (length lst_idcolumn)) (vlax-make-variant h_t 5))
			(vla-SetCellAlignment ename_cell n_row (1- (length lst_idcolumn)) 6)
			(vlax-release-object ename_cell)
			(vlax-release-object Space)
			(setvar "dimzin" oldim) (setvar "clayer" oldlay)
		)
		(T
			(princ "\nEmpty!")
		)
	)
	(prin1)
)
0 Likes
Message 11 of 13

Sea-Haven
Mentor
Mentor

There is an add on TV here in AUS where the child says the sandwich is not correct, dad flips it and brings it back all is ok now.

0 Likes
Message 12 of 13

Marco.studio.venica
Participant
Participant

I confirm my gratitude for the attention you reserve me and I thank you for this fact.
Aware that data is extracted only from blocks, I initially thought of a solution in which:
With a new command I build a polyline, then I generate a block whose name I define
The block that contains:
1 - the generated polyline
2 - a series of attributes (with the classic setting possibilities).
3 - the length of the polyline entered as an attribute
(I found the DimPoly.lsp file which can be used for this purpose) which I am attaching.
By doing so I could manage the information in an excel file that I extract with DATAEXTRACTION.
Everything would become easier.
What do you think about it?

I attach the DimPoly.lsp file

0 Likes
Message 13 of 13

CADaSchtroumpf
Advisor
Advisor

I am not convinced by the use of blocks.
If it is to be able to extract data, I will give you 2 examples.
the 1st for data creation (similar to pl_data)
the 2 nd for the extraction to excel

 

It's possible for you to adapt at your need?

 

 

0 Likes