List manipulation

List manipulation

avinash00002002
Collaborator Collaborator
3,365 Views
52 Replies
Message 1 of 53

List manipulation

avinash00002002
Collaborator
Collaborator

Hi!

I have a list which has nos. of vary members. 

(0.816176 6.48044 10.7246 10.3981 1.90985 8.48824 1.69765 3.39529 24.2404 1.63235 22.3306 1.50176 14.7075 17.4335 13.3526 13.3526 14.5769 5.8275 1.25691 11.8019 9.30441 7.72103 8.03118 4.35838 2.17103 3.65647)

I need help that
1. Which member have less than 4 than set to 4, and it will deduct from greater than 4.

Thanks,

Avinash

0 Likes
Accepted solutions (4)
3,366 Views
52 Replies
Replies (52)
Message 41 of 53

avinash00002002
Collaborator
Collaborator

Thanks for reply,

 

Select objects:
Command: GET_X_DISTANCES
Rectangle bottom left point >
Rectangle bottom rigth point >
Select all holes >
>
Select objects: Specify opposite corner: 6 found

Select objects: ; error: bad function: #<SUBR @000001a9eb9f87a0 -lambda->

 

I got above error.

0 Likes
Message 42 of 53

hak_vz
Advisor
Advisor

 

(defun c:get_x_distances ( / p1 p2 p3 p4  ang1 ang2 ss i intpts distlist)
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
(setq p1 (take 2(getpoint "\nRectangle bottom left point >")))
(setq p2 (take 2(getpoint "\nRectangle bottom rigth point >")))
(setq ang1 (angle p1 p2))
(setq ang2 (+ ang1 (* 0.5 PI)))
(princ "\nSelect all holes >")
(princ "\n>")
(setq ss (ssget '((0 . "INSERT"))))
(setq i -1)
(while (< (setq i (1+ i))(sslength ss))
(setq p3 (take 2(cdr (assoc 10 (entget(ssname ss i))))))
(setq p4 (take 2(polar p3 ang2 10)))
(setq intpts (cons (inters p1 p2 p3 p4 nil) intpts))
)
(setq intpts (vl-sort intpts '(lambda (x y) (< (distance p1 x)(distance p1 y)))))
(setq i -1)
(while (< (setq i (1+ i)) (1-(length intpts)))
	(setq distlist (cons (rtos (distance (nth i intpts) p1) 2 2) distlist))
)
(mapcar 'atof(reverse distlist))
)

 

Give more information if you need code changes. How to deal with situation where you have two holes at equal distance?

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 43 of 53

avinash00002002
Collaborator
Collaborator

Great Work, Thanks

 

I have attached sample1 drawing Last two dimensions is not getting, why? any update reqd.

Can we get y-distance for all holes as well as per drawing dimension given in red color.

 

Give more information if you need code changes. How to deal with situation where you have two holes at equal distance? --> Reply:  If two holes equal distance and Y-distance is different then we have to kept both holes, but if overlapping  holes we have to one ignore(it may happens while preparing drawing)

 

 

 

0 Likes
Message 44 of 53

hak_vz
Advisor
Advisor

@avinash00002002 

Try this. For rectangle base you use either top or bottom edge. X direction is calculated in direction from first to second selected point on desired rectangle edge so it works from left or from right.

(defun c:get_x_y_distances ( / take  p1 p2  ang1 ang2 ss tp i m n ipt dx dy distlist)
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(setq p1 (take 2(getpoint "\nRectangle base left point >")))
	(setq p2 (take 2(getpoint "\nRectangle base rigth point >")))
	(setq ang1 (angle p1 p2))
	(setq ang2 (+ ang1 (* 0.5 PI)))
	(princ "\n>")
	(princ "\nSelect all holes >")	
	(setq ss (ssget '((0 . "INSERT"))))
	(princ "\n")
	(initget "x y")
	(setq tp (getkword "\n Extract x or y distances <x y>"))
	(setq i -1)
	(while (< (setq i (1+ i))(sslength ss))
		(setq m (take 2(cdr (assoc 10 (entget(ssname ss i))))))
		(setq n (take 2(polar m ang2 10)))
		(setq ipt (inters p1 p2 m n nil))
		(setq dx (distance p1 ipt))
		(setq dy (distance m ipt))
		(setq distlist (cons (list dx dy) distlist))
	)
	(setq distlist (vl-sort distlist '(lambda (a b) (< (car a)(car b)))))
	(cond 
		(( = tp "x")
			(setq distlist (mapcar 'car distlist))
		)
		(( = tp "y")
			(setq distlist (mapcar 'cadr distlist))
		)
	)

(mapcar '(lambda (x) (atof(rtos x 2 2))) distlist)
)

 

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 45 of 53

avinash00002002
Collaborator
Collaborator

Thanks for your reply,

 

While using X-direction last distance (Hole to end) is not coming.

 

Avinash

0 Likes
Message 46 of 53

hak_vz
Advisor
Advisor

@avinash00002002 wrote:

While using X-direction last distance (Hole to end) is not coming.

Avinash


Sorry, but you must be wrong. I've tested it on all your sample drawings and my own using various blocks and there was no error. Check that all your hole entities are blocks and that you select them all. I've changed the code and there is no chance to fail if all condition are fulfilled. Check your side.

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 47 of 53

avinash00002002
Collaborator
Collaborator

Hi!

 

Its working properly, many many thanks.

 

Avinash

0 Likes
Message 48 of 53

hak_vz
Advisor
Advisor
Accepted solution

@avinash00002002 wrote:

Hi!

 

Its working properly, many many thanks.


OK If it works, select is as a solution. I think this also answers your other post about UCS so point it to this direction using post permalink.

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 49 of 53

avinash00002002
Collaborator
Collaborator

Hi!

in this function is it possible to get the block name after sorting.

 

Thanks,

 

Avinash

0 Likes
Message 50 of 53

avinash00002002
Collaborator
Collaborator
Hi!

in this function is it possible to get the block name after sorting.



Thanks,



Avinash
0 Likes
Message 51 of 53

hak_vz
Advisor
Advisor
Accepted solution

@avinash00002002 wrote:
Hi
in this function is it possible to get the block name after sorting.
Thanks,
Avinash
(defun c:get_x_y_distances ( / take  p1 p2  ang1 ang2 ss tp i m n ipt dx dy distlist)
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(setq p1 (take 2(getpoint "\nRectangle base left point >")))
	(setq p2 (take 2(getpoint "\nRectangle base rigth point >")))
	(setq ang1 (angle p1 p2))
	(setq ang2 (+ ang1 (* 0.5 PI)))
	(princ "\n>")
	(princ "\nSelect all holes >")	
	(setq ss (ssget '((0 . "INSERT"))))
	(princ "\n")
	(initget "x y")
	(setq tp (getkword "\n Extract x or y distances [x y] > "))
	(setq i -1)
	(while (< (setq i (1+ i))(sslength ss))
		(setq m (take 2(cdr (assoc 10 (entget(ssname ss i))))))
		(setq n (take 2(polar m ang2 10)))
		(setq name (cdr (assoc 2 (entget(ssname ss i)))))
		(setq ipt (inters p1 p2 m n nil))
		(setq dx (distance p1 ipt))
		(setq dy (distance m ipt))
		(setq distlist (cons (list dx dy name) distlist))
	)
	(setq distlist (vl-sort distlist '(lambda (a b) (< (car a)(car b)))))
	(cond 
		(( = tp "x")
			(setq distlist (mapcar '(lambda (x)(list (car x)(last x))) distlist))
		)
		(( = tp "y")
			(setq distlist (mapcar '(lambda (x)(list (cadr x)(last x))) distlist))
		)
	)
distlist
)
 Extract x or y distances [x y] > x
((30.0 "h2") (85.5 "h1") (140.5 "h3") (185.5 "H6") (215.5 "h16") (295.5 "H18") (395.5 "h2") (458.5 "h2") (548.0 "h2") (648.0 "h1") (683.0 "h1") (713.0 "h1") (968.0 "h1") (1198.0 "H18") (1198.0 "H18") (1358.0 "H18") (1518.0 "H18") (1626.0 "H18") (1671.0 "H18") (1763.0 "H18") (1832.0 "h16") (1862.0 "H6") (1892.0 "h3") (1939.0 "h1"))
 Extract x or y distances [x y] > y
((45.0 "h2") (55.0 "h1") (65.0 "h3") (75.0 "H6") (85.0 "h16") (95.0 "H18") (105.0 "h2") (115.0 "h2") (125.0 "h2") (135.0 "h1") (145.0 "h1") (165.0 "h1") (165.0 "h1") (165.0 "H18") (45.0 "H18") (165.0 "H18") (75.0 "H18") (135.0 "H18") (75.0 "H18") (65.0 "H18") (85.0 "h16") (75.0 "H6") (65.0 "h3") (55.0 "h1"))

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 52 of 53

hak_vz
Advisor
Advisor

@avinash00002002Have you tested this?

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 53 of 53

avinash00002002
Collaborator
Collaborator

Yes,  I have tested today and got result what I want exatly

0 Likes