Reference point for custom coordinates

Reference point for custom coordinates

Dan-Rod
Advocate Advocate
850 Views
12 Replies
Message 1 of 13

Reference point for custom coordinates

Dan-Rod
Advocate
Advocate

Hello group.

I would like to see if it is possible, through a Lisp routine, to be able to extract in an Excel the coordinate where the block called "circle" is located. The standard of use for the measurement is the size of the "10x10" box, there are smaller sizes for What the coordinate could be in decimals (or at least it is the proposal I have) I don't know if this is a restriction for the code, I hope you can support me, I attach the example files for this case.

 

The frame size could be longer and wider so those coordinates are not a limit.

0 Likes
Accepted solutions (1)
851 Views
12 Replies
Replies (12)
Message 2 of 13

hak_vz
Advisor
Advisor

@Dan-Rod 

It is tricky request, but it is solvable. I have more than half a the requested code already written. Just have to play with different box setups  and fine-tune it for boxes with width (height) equal 150. Also have to add output to Excel. Would you mind export to .csv or you really need write directly to Excel?

It getting late so I'll try to finish it tomorrow. 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 13

hak_vz
Advisor
Advisor
Accepted solution

@Dan-Rod

 Try this on different box combinations and see if it works correctly. I have no time to conduct thorough testing.

;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/reference-point-for-custom-coordinates/td-p/12593789
;hak_vz 03-03-2024
(defun c:clist ()
	(defun LM:selectDynamicBlockByName (ss name / e i out)
		(setq i -1 ssout (ssadd))
		(while (setq e (ssname ss (setq i (1+ i))))
			(if (= :vlax-true (vla-get-IsDynamicBlock (vlax-ename->vla-object e)))
				(if (= (strcase (vla-get-Effectivename (vlax-ename->vla-object e))) (strcase name))
				(ssadd e ssout)
				)
			)
		)
		ssout
	)
	(defun LM:getattributevalue ( blk tag )
		(setq tag (strcase tag))
		(vl-some '(lambda ( att ) 
			(if (= tag (strcase (vla-get-tagstring att))) 
			(vla-get-textstring att)))
			(vlax-invoke blk 'getattributes)
		)
	)
	(defun LM:getdynpropvalue ( blk prp )
		(setq prp (strcase prp))
		(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
			(vlax-invoke blk 'getdynamicblockproperties)
		)
	)
	(defun LM:getvisibilitystate ( blk / vis )
		(if (setq vis (LM:getvisibilityparametername blk))
			(LM:getdynpropvalue blk vis)
		)
	)
	(defun LM:getvisibilityparametername ( blk / vis )  
		(if
			(and
				(vlax-property-available-p blk 'effectivename)
				(setq blk
					(vla-item
						(vla-get-blocks (vla-get-document blk))
						(vla-get-effectivename blk)
					)
				)
				(= :vlax-true (vla-get-isdynamicblock blk))
				(= :vlax-true (vla-get-hasextensiondictionary blk))
				(setq vis
					(vl-some
					   '(lambda ( pair )
							(if
								(and
									(= 360 (car pair))
									(= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
								)
								(cdr pair)
							)
						)
						(dictsearch
							(vlax-vla-object->ename (vla-getextensiondictionary blk))
							"ACAD_ENHANCEDBLOCK"
						)
					)
				)
			)
			(cdr (assoc 301 (entget vis)))
		)
	)
	 
	(defun LM:writecsv ( lst csv / des sep )
		(if (setq des (open csv "w"))
			(progn
				(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
				(foreach row lst (write-line (LM:lst->csv row sep) des))
				(close des)
				t
			)
		)
	)
	(defun LM:lst->csv ( lst sep )
		(if (cdr lst)
			(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
			(LM:csv-addquotes (car lst) sep)
		)
	)
	(defun LM:csv-addquotes ( str sep / pos )
		(cond
			(   (wcmatch str (strcat "*[`" sep "\"]*"))
				(setq pos 0)    
				(while (setq pos (vl-string-position 34 str pos))
					(setq str (vl-string-subst "\"\"" "\"" str pos)
						  pos (+ pos 2)
					)
				)
				(strcat "\"" str "\"")
			)
			(   str   )
		)
	)
	(defun string_to_list ( str del / pos )
		(if (setq pos (vl-string-search del str))
			(cons (substr str 1 pos) (string_to_list (substr str (+ pos 1 (strlen del))) del))
			(list str)
		)
	)
	(setq hor_cord 
		'(	
			("1" 25 125)
			("2" 125 225)
			("3" 225 325)
			("4" 325 425)
			("5" 425 525)
			("6" 525 625)
			("7" 625 725)
			("8" 725 825)
			("9" 825 925)
			("10" 925 1025)
			("11" 1025 1125)
			("12" 1125 1225)
			("13" 1225 1325)
			("14" 1325 1425)
			("15" 1425 1525)	
		)
	)
	(setq ver_cord 
			'(	
				("A" 25 125)
				("B" 125 225)
				("C" 225 325)
				("D" 325 425)
				("E" 425 525)
				("F" 525 625)
			)
	)
	(setq ss (LM:selectDynamicBlockByName (ssget "_C" '(0 0) '(1550 650) '((0 . "INSERT"))) "SQARE") i -1 boxes nil)
	(while (<(setq i (1+ i)) (sslength ss))
		(setq eo (vlax-ename->vla-object (ssname ss i)))
		(setq minpt (vlax-get eo 'InsertionPoint))
		(setq visibility (string_to_list (LM:getvisibilitystate eo) "x"))
		(setq bx (atof(car visibility)))
		(setq by (atof(cadr visibility)))
		;(princ (strcat "\n" (rtos bx 2 0)"x" (rtos by 2 0)))
		(setq boxes (cons (list minpt (mapcar '+ minpt (list bx by))) boxes))
	)
	(setq ss (ssget  "_C" '(0 0) '(1550 650) '((0 . "INSERT")(2 . "circle"))) i -1 loclist nil)
	(while (<(setq i (1+ i)) (sslength ss))
		(setq co (vlax-ename->vla-object (ssname ss i)))
		(setq id (LM:getattributevalue co "ID"))
		(setq ip (vlax-get co 'InsertionPoint))
		(setq xip (car ip) yip (cadr ip))
		(foreach box boxes
			(setq p1 (car box) p2 (cadr box))
			(setq xmin (car p1) ymin (cadr p1))
			(setq xmax (car p2) ymax (cadr p2))
			(if (and (> xip xmin)(< xip xmax)(> yip ymin)(< yip ymax))
				(setq 
					refpoint (mapcar '+ '(6 6) p1)
					boxsize (list (- xmax xmin)(- ymax ymin))
				)
			)
		)
		(foreach loc hor_cord
			(if (and (>= xip (cadr loc))(<= xip (caddr loc)))
				(setq xloc (list (car loc) xip))
			)
		)
		(foreach loc ver_cord
			(if (and (>= yip (cadr loc))(<= yip (caddr loc)))
				(setq yloc (list (car loc) yip))
			)
		)

		(setq loclist (cons (list id xloc yloc boxsize refpoint) loclist))
	)
	(setq ret nil)
	(foreach loc loclist
		(setq id (car loc)
			 xloc (assoc(car(cadr loc)) hor_cord)
			 xrange (cdr xloc)
			 xloc (car xloc)
			 xip (cadr(cadr loc))
			 yloc (assoc(car(caddr loc))ver_cord)
			 yrange (cdr yloc)
			 yloc (car yloc)
			 yip (cadr(caddr loc))
			 xmid (* 0.5 (apply '+ xrange))
			 ymid (* 0.5 (apply '+ yrange))
			 refpoint (last loc)
			 boxsize (nth 3 loc)
			 boxwidth (car boxsize)
			 boxheight (cadr boxsize)
			 rpx (car refpoint)
			 rpy (cadr refpoint)
		)
		
		(cond 
			((and (< rpx xmid) (< rpy ymid)) (setq rp "1"))
			((and (>= rpx xmid) (< rpy ymid)) (setq rp "2"))
			((and (< rpx xmid) (> rpy ymid)) (setq rp "3"))
			((and (>= rpx xmid) (> rpy ymid)) (setq rp "4"))
		)
		(if (and (>= boxwidth 100)(>= boxheight 100))(setq rp ""))
		(if (>(strlen rp) 0) (setq xloc (strcat xloc "." rp)))
		(setq ret (cons (list id (strcat yloc xloc)) ret))
		
	)
	(setq ret (append '((" ")) (vl-sort ret '(lambda (x y)(< (atoi (car x))(atoi (car y)))))))
	 (if
		(and
			(setq fn (getfiled "Create Output File" "" "csv" 1))
		)
		(progn
			(if (LM:WriteCSV ret fn)
				(startapp "explorer" fn)
			)
		)
	)
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 13

Dan-Rod
Advocate
Advocate

perfect, it works very very well, so far I have had no problems with the one I sent, I would just like to see if there is a way I can confirm the coordinate data, I tried adding a larger frame and the additional coordinates are no longer detected, and if I change any number or letter it is still considered the original, I appreciate you taking the time to support me, annex the modified

Message 5 of 13

hak_vz
Advisor
Advisor

Program will work if following conditions are true:

1) Origin of the grid is at point 0,0 and grid is not selected

2) Modify variables hor_cord and ver_cord i.e add additional ranges according to your need since I didn't play with scales of blocks. Keep it in this sizes.

 

	(setq hor_cord 
		'(	
			("1" 25 125)
			("2" 125 225)
			("3" 225 325)
			("4" 325 425)
			("5" 425 525)
			("6" 525 625)
			("7" 625 725)
			("8" 725 825)
			("9" 825 925)
			("10" 925 1025)
			("11" 1025 1125)
			("12" 1125 1225)
			("13" 1225 1325)
			("14" 1325 1425)
			("15" 1425 1525)	
		)
	)

3)If you need to add more box type retain block names as current

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 13

hak_vz
Advisor
Advisor

I'll modify code so that you can enter grid size and that this variables are auto created. First play with this grid but with different box sizes and orientations.

I have assumed that large boxes that take more then one grid unit (100X100 150X150)are placed origin i.e. in field 1 and small boxes are added around them. When you do some testings and in next iterations we can add other options and improvements.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 13

Sea-Haven
Mentor
Mentor

Hak_VZ your welcome to use the defuns inside Alan Excel to write to Excel.

 

I like the way you did the grid look up, rather than hard code "1" "2" etc would it be easier to read the size of the block to work out 1-14 A-Z etc you can dynamically make variables, only problem is when you have more than 26 Alpha ie "Z". 

 

So if you have a X with a increment range, use (chr 65) = "A", an example

(set (read (strcat "pt" (rtos x 2 0))) '(100 200) )
(100 200)
: !pt1
(100 200)

Could even chuck in a Scale check.

 

 

 

0 Likes
Message 8 of 13

Dan-Rod
Advocate
Advocate

How does lsp work?

I don't know if it is also directed to what we are looking for, at the beginning of the code it seems to call an Excel file.

0 Likes
Message 9 of 13

hak_vz
Advisor
Advisor

@Dan-Rod 

IMO you can create largest grid that you plan to use. Update hor and ver variable to have all ranges and it will work with all smaller one.  Also change

(ssget "_C" '(0 0) '(1550 650)

where 1550, 650 is inside coordinate of right top corner of the grid. Code after it finishes and create return list calls Excel to write result in csv file.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 13

Dan-Rod
Advocate
Advocate

I understand, we use that size because it is the standard, there is a tool in each frame and it generally covers this size, special cases mean that smaller or larger size covers are used, I will add the coordinates for the maximum size, once again I thank you for your support and your time

Message 11 of 13

hak_vz
Advisor
Advisor

@Dan-Rod

I actually liked working on this task. This looks to me as a good method to organize boxes with rarely used stuff stored in my cellar.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 12 of 13

Dan-Rod
Advocate
Advocate

It's good that it was also useful to you, I think that working with coordinates is something that adapts to many types of activities, I hope that more people in the group will also find it useful

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

I did a staff seating plan, for a 5 Storey building, as a "where are they", it had a grid like yours and I manually added the location "E5" to each member in an Excel, so this would have been fantastic for that, each staff member was shown with an image so you even knew what they looked like. 

 

A side comment, throw it all away as the new office 8 storeys has hot desks so who knows where some one is located.